[m-rev.] diff: disallow directory components in --make targets

Ondrej Bojar bojar at csse.unimelb.edu.au
Fri Feb 23 15:34:20 AEDT 2007


Estimated hours taken: 1

Emit an error message if `mmc --make' is invoked with a target that contains a
directory separator. Targets with a directory component (be it a full pathname
or '../') are not handled correctly by the rest of the code. Previously this
lead to an assertion failure in the compiler.

compiler/make.m:
     Check for targets containing directory separator and emit an error message.

Index: compiler/make.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.43
diff -u -r1.43 make.m
--- compiler/make.m	1 Dec 2006 15:04:04 -0000	1.43
+++ compiler/make.m	23 Feb 2007 04:24:45 -0000
@@ -66,6 +66,8 @@
  :- import_module make.program_target.
  :- import_module make.util.

+:- import_module parse_tree.error_util.
+
  :- import_module backend_libs.compile_target_code.
  :- import_module libs.globals.
  :- import_module libs.options.
@@ -73,6 +75,7 @@
  :- import_module top_level.mercury_compile. % XXX unwanted dependency

  :- import_module bool.
+:- import_module dir.
  :- import_module int.
  :- import_module map.
  :- import_module maybe.
@@ -234,23 +237,43 @@
              MaybeMAIN_TARGET = yes(Targets),
              (
                  Targets = [_ | _],
-                Continue = yes
+                Continue0 = yes
              ;
                  Targets = [],
-                Continue = no,
+                Continue0 = no,
                  io.write_string("** Error: no targets specified " ++
                      "and `MAIN_TARGET' not defined.\n", !IO)
              )
          ;
              MaybeMAIN_TARGET = no,
              Targets = [],
-            Continue = no
+            Continue0 = no
          )
      ;
          Targets0 = [_ | _],
-        Continue = yes,
+        Continue0 = yes,
          Targets = Targets0
      ),
+    %
+    % Ensure none of the targets contains the directory_separator. This is not
+    % supported by the rest of the code.
+    %
+    list.filter(
+        (pred(Target::in) is semidet :-
+            string.contains_char(Target, dir.directory_separator)
+        ), Targets, AbsTargets),
+    (
+        AbsTargets = [],
+        Continue = Continue0
+    ;
+        AbsTargets = [_ | _],
+        Continue = no,
+        list.foldl(
+            (pred(Target::in, !.I::di, !:I::uo) is det :-
+                error_util.write_error_plain_with_progname(Target,
+                  "Make target must not contain any directory component.", !I)
+            ), AbsTargets, !IO)
+    ),
      (
          Continue = no,
          io.set_exit_status(1, !IO)

-- 
Ondrej Bojar (mailto:obo at cuni.cz / bojar at ufal.mff.cuni.cz)
http://www.cuni.cz/~obo
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list