aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-04-11 10:39:31 +0300
committerJukka Jylänki <jujjyl@gmail.com>2013-04-11 10:42:18 +0300
commit69c67542e76bcbc37563399eb3ab8716c6a37774 (patch)
tree39c5891a02caacb4b7bcd0a4a5b0ba099d1b86ba
parent5351b86b0768813c4c18bb61494c43b07bc00372 (diff)
Remove the unwanted abstraction that callee is allowed to autodelete a response file after consuming it. Instead, manually track and delete response files by the caller and clean them up.
-rwxr-xr-xemcc4
-rwxr-xr-xemscripten.py4
-rw-r--r--tools/response_file.py16
-rw-r--r--tools/shared.py11
4 files changed, 18 insertions, 17 deletions
diff --git a/emcc b/emcc
index bcd703fd..17b8e6e8 100755
--- a/emcc
+++ b/emcc
@@ -79,7 +79,7 @@ import os, sys, shutil, tempfile, subprocess, shlex, time, re
from subprocess import PIPE, STDOUT
from tools import shared
from tools.shared import Compression, execute, suffix, unsuffixed, unsuffixed_basename
-from tools.response_file import read_and_delete_response_file
+from tools.response_file import read_response_file
# Mapping of emcc opt levels to llvm opt levels. We use llvm opt level 3 in emcc opt
# levels 2 and 3 (emcc 3 is unsafe opts, so unsuitable for the only level to get
@@ -131,7 +131,7 @@ while response_file:
if sys.argv[index][0] == '@':
# found one, loop again next time
response_file = True
- extra_args = read_and_delete_response_file(sys.argv[index])
+ extra_args = read_response_file(sys.argv[index])
# slice in extra_args in place of the response file arg
sys.argv[index:index+1] = extra_args
break
diff --git a/emscripten.py b/emscripten.py
index 02e28623..bd6994fa 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -12,7 +12,7 @@ headers, for the libc implementation in JS).
import os, sys, json, optparse, subprocess, re, time, multiprocessing, functools
from tools import jsrun, cache as cache_module, tempfiles
-from tools.response_file import read_and_delete_response_file
+from tools.response_file import read_response_file
__rootpath__ = os.path.abspath(os.path.dirname(__file__))
def path_from_root(*pathelems):
@@ -637,7 +637,7 @@ def _main(environ):
if sys.argv[index][0] == '@':
# found one, loop again next time
response_file = True
- response_file_args = read_and_delete_response_file(sys.argv[index])
+ response_file_args = read_response_file(sys.argv[index])
# slice in extra_args in place of the response file arg
sys.argv[index:index+1] = response_file_args
break
diff --git a/tools/response_file.py b/tools/response_file.py
index 29756833..312cda73 100644
--- a/tools/response_file.py
+++ b/tools/response_file.py
@@ -1,21 +1,19 @@
import tempfile, os, sys, shlex
-from tempfiles import try_delete
# Routes the given cmdline param list in args into a new response file and returns the filename to it.
-# The response file has a suffix '.tmp' to signal that the process receiving the response file is free to delete it after it has consumed it.
-# The returned filename has '@' prepended to it already for convenience.
+# The returned filename has a suffix '.rsp'.
def create_response_file(args, directory):
- (response_fd, response_filename) = tempfile.mkstemp(prefix='emscripten_', suffix='.tmp', dir=directory, text=True)
+ (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
+ return response_filename
# Reads a response file, and returns the list of cmdline params found in the file.
-# If the response file ends with .tmp, it is automatically deleted after reading it.
-def read_and_delete_response_file(response_filename):
+# The parameter response_filename may start with '@'.
+def read_response_file(response_filename):
if response_filename.startswith('@'):
response_filename = response_filename[1:]
@@ -26,9 +24,5 @@ def read_and_delete_response_file(response_filename):
response_fd = open(response_filename, 'r')
args = response_fd.read()
response_fd.close()
- # For conveniency, the receiver is allowed to immediately clean up response files ending with '.tmp' so that the
- # caller doesn't have to do it.
- if response_filename.endswith(".tmp"):
- try_delete(response_filename)
args = shlex.split(args)
return args
diff --git a/tools/shared.py b/tools/shared.py
index 7692b4f8..dce27a18 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -39,8 +39,8 @@ class WindowsPopen:
# 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]
+ self.response_filename = create_response_file(args[2:], TEMP_DIR)
+ args = args[0:2] + ['@' + self.response_filename]
try:
# Call the process with fixed streams.
@@ -75,6 +75,13 @@ class WindowsPopen:
def kill(self):
return self.process.kill()
+
+ def __del__(self):
+ try:
+ # Clean up the temporary response file that was used to spawn this process, so that we don't leave temp files around.
+ tempfiles.try_delete(self.response_filename)
+ except:
+ pass # Mute all exceptions in dtor, particularly if we didn't use a response file, self.response_filename doesn't exist.
# Install our replacement Popen handler if we are running on Windows to avoid python spawn process function.
if os.name == 'nt':