[m-rev.] diff: avoid command line overflows when creating an archive under windows

Peter Ross pro at missioncriticalit.com
Fri Jun 15 03:19:52 AEST 2007


Hi,


===================================================================


Estimated hours taken: 3
Branches: main

When compiling using a Mercury compiler built on top of MSVC,
we use the windows command shell to invoke commands.
The windows command shell limits the length of command lines,
this change works around that limit when building the command line
to build an archive.

compiler/compile_target_code.m:
	When linking using the windows lib tool, place the list of
	files into a temp file and use that temp file as the method
	to pass the set of files to link to lib.


Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.110
diff -u -r1.110 compile_target_code.m
--- compiler/compile_target_code.m	12 Jun 2007 06:39:14 -0000	1.110
+++ compiler/compile_target_code.m	14 Jun 2007 00:13:10 -0000
@@ -2037,11 +2037,45 @@
         % Quoting would prevent that.
         join_string_list(ObjectList, "", "", " ", Objects)
     ),
-    MakeLibCmd = string.append_list([
-        ArCmd, " ", ArFlags, " ", ArOutputFlag, " ",
-        LibFileName, " ", Objects]),
-    invoke_system_command(ErrorStream, cmd_verbose_commands,
-        MakeLibCmd, MakeLibCmdSucceeded, !IO),
+    ( ArCmd = "lib" ->
+            
+        %
+        % If we are using lib, we are on windows and windows doesn't
+        % handle long command lines, so place the list of object
+        % files in a file and pass that file as an argument to lib.
+        %
+        io.make_temp(TmpFile, !IO),
+        io.open_output(TmpFile, OpenResult, !IO),
+        (
+            OpenResult = ok(TmpStream),
+            io.write_string(TmpStream, Objects, !IO),
+            io.close_output(TmpStream, !IO),
+
+            MakeLibCmd = string.append_list([
+                ArCmd, " ", ArFlags, " ", ArOutputFlag,
+                LibFileName, " @", TmpFile]),
+            invoke_system_command(ErrorStream, cmd_verbose_commands,
+                MakeLibCmd, MakeLibCmdSucceeded0, !IO),
+
+            io.remove_file(TmpFile, RemoveResult, !IO),
+            (
+                RemoveResult = ok,
+                MakeLibCmdSucceeded = MakeLibCmdSucceeded0
+            ;
+                RemoveResult = error(_),
+                MakeLibCmdSucceeded = no
+            )
+        ;
+            OpenResult = error(_),
+            MakeLibCmdSucceeded = no
+        )
+    ;
+        MakeLibCmd = string.append_list([
+            ArCmd, " ", ArFlags, " ", ArOutputFlag, " ",
+            LibFileName, " ", Objects]),
+        invoke_system_command(ErrorStream, cmd_verbose_commands,
+            MakeLibCmd, MakeLibCmdSucceeded, !IO)
+    ),
     (
         ( RanLib = ""
         ; MakeLibCmdSucceeded = no

--------------------------------------------------------------------------
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