diff options
Diffstat (limited to 'tools/shared.py')
-rw-r--r-- | tools/shared.py | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/tools/shared.py b/tools/shared.py index 6f97737e..aca0677d 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -2,6 +2,10 @@ import shutil, time, os, sys, json, tempfile, copy, shlex, atexit, subprocess, h from subprocess import Popen, PIPE, STDOUT from tempfile import mkstemp +def listify(x): + if type(x) is not list: return [x] + return x + # On Windows python suffers from a particularly nasty bug if python is spawning new processes while python itself is spawned from some other non-console process. # Use a custom replacement for Popen on Windows to avoid the "WindowsError: [Error 6] The handle is invalid" errors when emcc is driven through cmake or mingw32-make. # See http://bugs.python.org/issue3905 @@ -28,7 +32,10 @@ class WindowsPopen: self.stderr_ = PIPE # 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) + try: + 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, 'subprocess.Popen(args=%s) failed! Exception %s' % (' '.join(args), str(e)) def communicate(self, input=None): output = self.process.communicate(input) @@ -155,7 +162,8 @@ EXPECTED_NODE_VERSION = (0,6,8) def check_node_version(): try: - actual = Popen([NODE_JS, '--version'], stdout=PIPE).communicate()[0].strip() + node = listify(NODE_JS) + actual = Popen(node + ['--version'], stdout=PIPE).communicate()[0].strip() version = tuple(map(int, actual.replace('v', '').split('.'))) if version >= EXPECTED_NODE_VERSION: return True @@ -380,6 +388,9 @@ if USE_EMSDK: else: EMSDK_OPTS = [] +#print >> sys.stderr, 'SDK opts', ' '.join(EMSDK_OPTS) +#print >> sys.stderr, 'Compiler opts', ' '.join(COMPILER_OPTS) + # Engine tweaks try: @@ -465,7 +476,8 @@ def timeout_run(proc, timeout, note='unnamed process', full_output=False): def run_js(filename, engine=None, args=[], check_timeout=False, stdout=PIPE, stderr=None, cwd=None, full_output=False): if engine is None: engine = JS_ENGINES[0] - if type(engine) is not list: engine = [engine] + engine = listify(engine) + #if not WINDOWS: 'd8' in engine[0] or 'node' in engine[0]: engine += ['--stack_size=8192'] # needed for some big projects command = engine + [filename] + (['--'] if 'd8' in engine[0] else []) + args return timeout_run(Popen(command, stdout=stdout, stderr=stderr, cwd=cwd), 15*60 if check_timeout else None, 'Execution', full_output=full_output) @@ -571,8 +583,7 @@ class Settings: if opt_level >= 2: Settings.RELOOP = 1 if opt_level >= 3: - # Aside from these, -O3 also runs closure compiler - Settings.INLINING_LIMIT = 0 + # Aside from these, -O3 also runs closure compiler and llvm lto Settings.DOUBLE_MODE = 0 Settings.PRECISE_I64_MATH = 0 if noisy: print >> sys.stderr, 'Warning: Applying some potentially unsafe optimizations! (Use -O2 if this fails.)' @@ -822,14 +833,25 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e # 8k is a bit of an arbitrary limit, but a reasonable one # for max command line size before we use a respose file response_file = None - if len(' '.join(link_cmd)) > 8192: + if WINDOWS and len(' '.join(link_cmd)) > 8192: if DEBUG: print >>sys.stderr, 'using response file for llvm-link' [response_fd, response_file] = mkstemp(suffix='.response', dir=TEMP_DIR) + + link_cmd = [LLVM_LINK, "@" + response_file] + response_fh = os.fdopen(response_fd, 'w') for arg in actual_files: - response_fh.write(arg + "\n") + # we can't put things with spaces in the response file + if " " in arg: + link_cmd.append(arg) + else: + response_fh.write(arg + "\n") response_fh.close() - link_cmd = [LLVM_LINK, "@" + response_file, '-o', target] + link_cmd.append("-o") + link_cmd.append(target) + + if len(' '.join(link_cmd)) > 8192: + print >>sys.stderr, 'emcc: warning: link command line is very long, even with response file -- use paths with no spaces' output = Popen(link_cmd, stdout=PIPE).communicate()[0] @@ -1078,7 +1100,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e @staticmethod def js_optimizer(filename, passes, jcache): - return js_optimizer.run(filename, passes, NODE_JS, jcache) + return js_optimizer.run(filename, passes, listify(NODE_JS), jcache) @staticmethod def closure_compiler(filename): |