[m-rev.] for review: extend the use of library grade install checks

Julien Fischer jfischer at opturion.com
Sat Sep 14 02:12:53 AEST 2019


For review by anyone.

----------------------

Extend the use of library grade install checks.

Perform library grade install checks when the compiler is invoked on a single
source file linked target; previously we only performed this checks when using
mmc --make.

compiler/mercury_compile_main.m:
     As above.

compiler/check_libgrades.m:
     Check whether --libgrade-install-check is enabled here, rather than
     in our callers.

compiler/handle_options.m:
     Do not disable the library grade install checks when the compiler
     is invoked to build a single source file linked target.

compiler/make.program_target.m:
     Conform to the above changes.

Julien.

diff --git a/compiler/check_libgrades.m b/compiler/check_libgrades.m
index 801f6c5..f2743f9 100644
--- a/compiler/check_libgrades.m
+++ b/compiler/check_libgrades.m
@@ -23,10 +23,11 @@

  %---------------------------------------------------------------------------%

-    % Check that all Mercury libraries required by the target are installed
-    % in the selected grade.
+    % If --libgrade-install-check is enabled, then check that all Mercury
+    % libraries required by the target are installed in the selected grade.
+    % Always succeeds if --libgrade-install-check is *not* enabled.
      %
-:- pred check_libraries_are_installed(globals::in, bool::out,
+:- pred maybe_check_libraries_are_installed(globals::in, bool::out,
      io::di, io::uo) is det.

  %---------------------------------------------------------------------------%
@@ -45,12 +46,20 @@

  %---------------------------------------------------------------------------%

-check_libraries_are_installed(Globals, Succeeded, !IO) :-
-    globals.lookup_accumulating_option(Globals, mercury_libraries, Libs),
-    grade_directory_component(Globals, Grade),
-    check_stdlib_is_installed(Globals, Grade, Succeeded0, !IO),
-    list.foldl2(check_library_is_installed(Globals, Grade), Libs,
-        Succeeded0, Succeeded, !IO).
+maybe_check_libraries_are_installed(Globals, Succeeded, !IO) :-
+    globals.lookup_bool_option(Globals, libgrade_install_check,
+        LibgradeCheck),
+    (
+        LibgradeCheck = yes,
+        globals.lookup_accumulating_option(Globals, mercury_libraries, Libs),
+        grade_directory_component(Globals, Grade),
+        check_stdlib_is_installed(Globals, Grade, Succeeded0, !IO),
+        list.foldl2(check_library_is_installed(Globals, Grade), Libs,
+            Succeeded0, Succeeded, !IO)
+    ;
+        LibgradeCheck = no,
+        Succeeded = yes
+    ).

  :- pred check_stdlib_is_installed(globals::in, string::in, bool::out,
      io::di, io::uo) is det.
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index a908bdd..9cafaf6 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -1002,8 +1002,19 @@ convert_options_to_globals(OptionTable0, OpMode, Target,
      option_implies(invoked_by_mmc_make,
          generate_mmc_make_module_dependencies, bool(no), !Globals),

-    % --libgrade-install-check only works with --make.
-    ( if OpMode = opm_top_make then
+    % We only perform the library grade install check if we are
+    % building a linked target using mmc --make or if we are building
+    % a single source file linked target.  (The library grade install
+    % check is *not* compatible with the use of mmake.)
+    ( if
+        (
+            OpMode = opm_top_make
+        ;
+            OpMode = opm_top_args(OpModeArgs),
+            OpModeArgs = opma_augment(opmau_generate_code(
+                opmcg_target_object_and_executable))
+        )
+    then
          true
      else
          globals.set_option(libgrade_install_check, bool(no), !Globals)
diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index 1ec8278..1c1eb5f 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -91,15 +91,8 @@ make_linked_target(Globals, LinkedTargetFile, LinkedTargetSucceeded,
      then
          LinkedTargetSucceeded = yes
      else
-        globals.lookup_bool_option(Globals, libgrade_install_check,
-            LibgradeCheck),
-        (
-            LibgradeCheck = yes,
-            check_libraries_are_installed(Globals, LibgradeCheckSucceeded, !IO)
-        ;
-            LibgradeCheck = no,
-            LibgradeCheckSucceeded = yes
-        ),
+        maybe_check_libraries_are_installed(Globals, LibgradeCheckSucceeded,
+            !IO),
          (
              LibgradeCheckSucceeded = yes,
              maybe_with_analysis_cache_dir(Globals,
diff --git a/compiler/mercury_compile_main.m b/compiler/mercury_compile_main.m
index 5655cac..2e41909 100644
--- a/compiler/mercury_compile_main.m
+++ b/compiler/mercury_compile_main.m
@@ -54,6 +54,7 @@
  :- import_module hlds.hlds_module.
  :- import_module hlds.make_hlds.
  :- import_module hlds.passes_aux.
+:- import_module libs.check_libgrades.
  :- import_module libs.compiler_util.
  :- import_module libs.compute_grade.
  :- import_module libs.file_util.
@@ -962,9 +963,18 @@ process_compiler_arg(Globals, OpModeArgs, DetectedGradeFlags, OptionVariables,

  process_compiler_arg_build(OpModeArgs, FileOrModule, OptionArgs, Globals, _,
          Succeeded, _DummyInput, {Modules, ExtraObjFiles}, !IO) :-
-    do_process_compiler_arg(Globals, OpModeArgs, OptionArgs, FileOrModule,
-        Modules, ExtraObjFiles, !IO),
-    Succeeded = yes.
+    maybe_check_libraries_are_installed(Globals, LibgradeCheckSucceeded, !IO),
+    (
+        LibgradeCheckSucceeded = yes,
+        do_process_compiler_arg(Globals, OpModeArgs, OptionArgs, FileOrModule,
+            Modules, ExtraObjFiles, !IO),
+        Succeeded = yes
+    ;
+        LibgradeCheckSucceeded = no,
+        Modules = [],
+        ExtraObjFiles = [],
+        Succeeded = no
+    ).

  :- func version_numbers_return_timestamp(bool) = maybe_return_timestamp.



More information about the reviews mailing list