[m-rev.] for review: Fix error messages related to bad .module_dep files.

Paul Bone paul at bone.id.au
Tue Oct 20 17:44:06 AEDT 2015


For review by either Zoltan or Julien who have been working on other
mmc --make stuff lately.  I don't want to step on their toes.

---

Fix error messages related to bad .module_dep files.

This change makes it a little easier to understand what's going on when the
compiler doesn't understand your .module_dep files, for example when you
bootstrapped with a compiler that's too old.

The error message I got last week was:

    $ mmc --make hello --rebuild
    ** Error: error reading file `pretty_printer.m' to generate dependencies.
    ** Module `pretty_printer' is imported or included by module `list'.
    mercury_compile: cannot find source for module `pretty_printer' in
    directories .

Now the error message is:

    $ mmc --make hello --rebuild
    Making Mercury/int3s/hello.int3
    Error reading file `/tmp/test2/lib/mercury/ints/Mercury/module_deps/pretty_printer.module_dep': failed to parse term
    ...rebuilding
    ** Error: error reading file `pretty_printer.m' to generate dependencies.
    ** Module `pretty_printer' is imported or included by module `array'.
    mercury_compile: cannot find source for module `pretty_printer' in directories
      .

Previously you only saw this information (about the .module_dep) file if you
use --debug-make.

There is no warning (without --debug-make) if the file is missing as that
would lead to spurious warnings.  However an informational message has been
added when --debug-make is used.

compiler/make.module_dep_file.m:
    As above.
---
 compiler/make.module_dep_file.m | 47 +++++++++++++++++++++++------------------
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/compiler/make.module_dep_file.m b/compiler/make.module_dep_file.m
index 49e453d..bf4cc6f 100644
--- a/compiler/make.module_dep_file.m
+++ b/compiler/make.module_dep_file.m
@@ -243,6 +243,10 @@ do_get_module_dependencies(Globals, RebuildModuleDeps, ModuleName,
         )
     ;
         MaybeDepFileTimestamp = error(_),
+        debug_make_msg(Globals, io.format("Module dependencies file '%s' "
+                    ++ "not found in directories %s.\n",
+                [s(DepFileName), s(join_list(", ", SearchDirs))]),
+            !IO),
 
         % Try to make the dependencies. This will succeed when the module name
         % doesn't match the file name and the dependencies for this module
@@ -509,14 +513,19 @@ read_module_dependencies_2(Globals, RebuildModuleDeps, SearchDirs, ModuleName,
             Result = ok
         ;
             Result = error(Msg),
+            read_module_dependencies_remake_msg(RebuildModuleDeps,
+                ModuleDir ++ "/" ++ ModuleDepFile, Msg, !IO),
             read_module_dependencies_remake(Globals, RebuildModuleDeps,
-                ModuleName, Msg, !Info, !IO)
+                ModuleName, !Info, !IO)
         )
     ;
-        SearchResult = error(_),
-        % XXX should use the error message.
-        read_module_dependencies_remake(Globals, RebuildModuleDeps, ModuleName,
-            "couldn't find `.module_dep' file", !Info, !IO)
+        SearchResult = error(Msg),
+        debug_make_msg(Globals,
+            read_module_dependencies_remake_msg(RebuildModuleDeps,
+                ModuleDepFile, Msg),
+            !IO),
+        read_module_dependencies_remake(Globals, RebuildModuleDeps,
+            ModuleName, !Info, !IO)
     ).
 
 :- pred read_module_dependencies_3(globals::in, list(dir_name)::in,
@@ -771,33 +780,31 @@ check_regular_file_exists(FileName, FileExists, !IO) :-
     % Something went wrong reading the dependencies, so just rebuild them.
     %
 :- pred read_module_dependencies_remake(globals::in, rebuild_module_deps::in,
-    module_name::in, string::in, make_info::in, make_info::out,
+    module_name::in, make_info::in, make_info::out,
     io::di, io::uo) is det.
 
-read_module_dependencies_remake(Globals, RebuildModuleDeps, ModuleName, Msg,
+read_module_dependencies_remake(Globals, RebuildModuleDeps, ModuleName,
         !Info, !IO) :-
     (
         RebuildModuleDeps = do_rebuild_module_deps,
-        debug_make_msg(Globals,
-            read_module_dependencies_remake_msg(Globals, ModuleName, Msg),
-            !IO),
         make_module_dependencies(Globals, ModuleName, !Info, !IO)
     ;
         RebuildModuleDeps = do_not_rebuild_module_deps
     ).
 
-:- pred read_module_dependencies_remake_msg(globals::in, module_name::in,
-    string::in, io::di, io::uo) is det.
+:- pred read_module_dependencies_remake_msg(rebuild_module_deps::in,
+    string::in, string::in, io::di, io::uo) is det.
 
-read_module_dependencies_remake_msg(Globals, ModuleName, Msg, !IO) :-
-    module_name_to_file_name(Globals, ModuleName,
-        make_module_dep_file_extension, do_not_create_dirs, ModuleDepsFile,
+read_module_dependencies_remake_msg(RebuildModuleDeps, ModuleDepsFile, Msg,
+        !IO) :-
+    io.format("** Error reading file `%s': %s\n", [s(ModuleDepsFile), s(Msg)],
         !IO),
-    io.write_string("Error reading file `", !IO),
-    io.write_string(ModuleDepsFile, !IO),
-    io.write_string("', rebuilding: ", !IO),
-    io.write_string(Msg, !IO),
-    io.nl(!IO).
+    (
+        RebuildModuleDeps = do_rebuild_module_deps,
+        io.write_string("...rebuilding\n", !IO)
+    ;
+        RebuildModuleDeps = do_not_rebuild_module_deps
+    ).
 
     % The module_name given must be the top level module in the source file.
     % get_module_dependencies ensures this by making the dependencies
-- 
2.6.1




More information about the reviews mailing list