changeset 18898:d199e643f23b

mx: replaced MX_SUBPROCESS_COMMAND with MX_SUBPROCESS_COMMAND_FILE
author Doug Simon <doug.simon@oracle.com>
date Wed, 21 Jan 2015 19:00:46 +0100
parents 16ffeae58772
children 8e8b4a6a85f5
files graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java mxtool/mx.py
diffstat 2 files changed, 32 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java	Tue Jan 20 23:18:17 2015 +0100
+++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java	Wed Jan 21 19:00:46 2015 +0100
@@ -23,6 +23,7 @@
 package com.oracle.graal.test;
 
 import java.io.*;
+import java.nio.file.*;
 import java.util.*;
 
 import junit.runner.*;
@@ -167,6 +168,23 @@
     }
 
     /**
+     * Gets the command line for the current process.
+     *
+     * @return the command line arguments for the current process or {@code null} if they are not
+     *         available
+     */
+    public static List<String> getProcessCommandLine() {
+        String processArgsFile = System.getenv().get("MX_SUBPROCESS_COMMAND_FILE");
+        if (processArgsFile != null) {
+            try {
+                return Files.readAllLines(new File(processArgsFile).toPath());
+            } catch (IOException e) {
+            }
+        }
+        return null;
+    }
+
+    /**
      * Expand any arguments starting with @ and return the resulting argument array.
      *
      * @param args
--- a/mxtool/mx.py	Tue Jan 20 23:18:17 2015 +0100
+++ b/mxtool/mx.py	Wed Jan 21 19:00:46 2015 +0100
@@ -1868,9 +1868,19 @@
         assert isinstance(arg, types.StringTypes), 'argument is not a string: ' + str(arg)
 
     if env is None:
-        env = os.environ
-
-    env['MX_SUBPROCESS_COMMAND'] = '|'.join(args)
+        env = os.environ.copy()
+
+    # Ideally the command line could be communicated directly in an environment
+    # variable. However, since environment variables share the same resource
+    # space as the command line itself (on Unix at least), this would cause the
+    # limit to be exceeded too easily.  
+    _, subprocessCommandFile = tempfile.mkstemp(suffix='', prefix='mx_subprocess_command.')
+    with open(subprocessCommandFile, 'w') as fp:
+        for arg in args:
+            # TODO: handle newlines in args once there's a use case
+            assert '\n' not in arg
+            print >> fp, arg
+    env['MX_SUBPROCESS_COMMAND_FILE'] = subprocessCommandFile
 
     if _opts.verbose:
         if _opts.very_verbose:
@@ -1932,6 +1942,7 @@
         abort(1)
     finally:
         _removeSubprocess(sub)
+        os.remove(subprocessCommandFile)
 
     if retcode and nonZeroIsFatal:
         if _opts.verbose: