aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/response_file.py31
-rw-r--r--tools/shared.py12
2 files changed, 41 insertions, 2 deletions
diff --git a/tools/response_file.py b/tools/response_file.py
new file mode 100644
index 00000000..f6226783
--- /dev/null
+++ b/tools/response_file.py
@@ -0,0 +1,31 @@
+import tempfile, os, sys, shlex
+from tempfiles import try_delete
+
+# Routes the given cmdline param list in args into a new .rsp file and returns the filename to it.
+# The returned filename has '@' prepended to it already for convenience.
+def create_response_file(args, directory):
+ (response_fd, response_filename) = tempfile.mkstemp(prefix='emscripten_', suffix='.rsp', dir=directory, text=True)
+ response_fd = os.fdopen(response_fd, "w")
+ #print >> sys.stderr, "Creating response file '%s'" % response_filename
+ args = map(lambda p: p.replace(' ', '').replace('\\', '\\\\').replace('"', '\\"'), args)
+ response_fd.write(' '.join(args))
+ response_fd.close
+ return '@' + response_filename
+
+# Reads and deletes a .rsp file, and returns the list of cmdline params found in the file.
+def read_and_delete_response_file(response_filename):
+ # Ensure safety so that this function can never accidentally delete any non-.rsp files if things go wrong!
+ if not (response_filename.startswith('@') and response_filename.endswith('.rsp')):
+ raise Exception("'%s' is not a valid response file name! Response file names must start with '@' and end in '.rsp'!" % response_filename)
+ response_filename = response_filename[1:]
+
+ #print >> sys.stderr, "Using response file '%s'" % response_filename
+ if not os.path.exists(response_filename):
+ raise Exception("Response file '%s' not found!" % response_filename)
+
+ response_fd = open(response_filename, 'r')
+ args = response_fd.read()
+ response_fd.close()
+ try_delete(response_filename)
+ args = shlex.split(args)
+ return args
diff --git a/tools/shared.py b/tools/shared.py
index 72f4868e..7692b4f8 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -2,6 +2,7 @@ import shutil, time, os, sys, json, tempfile, copy, shlex, atexit, subprocess, h
from subprocess import Popen, PIPE, STDOUT
from tempfile import mkstemp
import jsrun, cache, tempfiles
+from response_file import create_response_file
def listify(x):
if type(x) is not list: return [x]
@@ -34,13 +35,20 @@ class WindowsPopen:
self.stdout_ = PIPE
if self.stderr_ == None:
self.stderr_ = PIPE
-
- # Call the process with fixed streams.
+
+ # emscripten.py supports reading args from a response file instead of cmdline.
+ # Use .rsp to avoid cmdline length limitations on Windows.
+ if len(args) >= 2 and args[1].endswith("emscripten.py"):
+ response_filename = create_response_file(args[2:], TEMP_DIR)
+ args = args[0:2] + [response_filename]
+
try:
+ # Call the process with fixed streams.
self.process = subprocess.Popen(args, bufsize, executable, self.stdin_, self.stdout_, self.stderr_, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
except Exception, e:
print >> sys.stderr, '\nsubprocess.Popen(args=%s) failed! Exception %s\n' % (' '.join(args), str(e))
raise e
+ raise
def communicate(self, input=None):
output = self.process.communicate(input)