diff options
Diffstat (limited to 'tools/shared.py')
-rw-r--r-- | tools/shared.py | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/tools/shared.py b/tools/shared.py index 108a48a4..0783dc75 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -3,7 +3,7 @@ from subprocess import Popen, PIPE, STDOUT from tempfile import mkstemp from distutils.spawn import find_executable import jsrun, cache, tempfiles -from response_file import create_response_file +import response_file import logging, platform def listify(x): @@ -41,8 +41,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"): - self.response_filename = create_response_file(args[2:], TEMP_DIR) - args = args[0:2] + ['@' + self.response_filename] + response_filename = response_file.create_response_file(args[2:], TEMP_DIR) + args = args[0:2] + ['@' + response_filename] try: # Call the process with fixed streams. @@ -78,13 +78,6 @@ 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. - __rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) def path_from_root(*pathelems): return os.path.join(__rootpath__, *pathelems) @@ -284,7 +277,7 @@ def check_node_version(): try: node = listify(NODE_JS) actual = Popen(node + ['--version'], stdout=PIPE).communicate()[0].strip() - version = tuple(map(int, actual.replace('v', '').split('.'))) + version = tuple(map(int, actual.replace('v', '').replace('-pre', '').split('.'))) if version >= EXPECTED_NODE_VERSION: return True logging.warning('node version appears too old (seeing "%s", expected "%s")' % (actual, 'v' + ('.'.join(map(str, EXPECTED_NODE_VERSION))))) @@ -314,7 +307,7 @@ def find_temp_directory(): # we re-check sanity when the settings are changed) # We also re-check sanity and clear the cache when the version changes -EMSCRIPTEN_VERSION = '1.7.1' +EMSCRIPTEN_VERSION = '1.7.8' def generate_sanity(): return EMSCRIPTEN_VERSION + '|' + get_llvm_target() + '|' + LLVM_ROOT @@ -1036,7 +1029,7 @@ class Building: dirname = os.path.dirname(content) if dirname and not os.path.exists(dirname): os.makedirs(dirname) - Popen([LLVM_AR, 'x', f], stdout=PIPE).communicate() # if absolute paths, files will appear there. otherwise, in this directory + Popen([LLVM_AR, 'xo', f], stdout=PIPE).communicate() # if absolute paths, files will appear there. otherwise, in this directory contents = map(lambda content: os.path.join(temp_dir, content), contents) contents = filter(os.path.exists, map(os.path.abspath, contents)) added_contents = set() @@ -1117,14 +1110,16 @@ class Building: # @param opt Either an integer, in which case it is the optimization level (-O1, -O2, etc.), or a list of raw # optimization passes passed to llvm opt @staticmethod - def llvm_opt(filename, opts): + def llvm_opt(filename, opts, out=None): if type(opts) is int: opts = Building.pick_llvm_opts(opts) #opts += ['-debug-pass=Arguments'] logging.debug('emcc: LLVM opts: ' + str(opts)) - output = Popen([LLVM_OPT, filename] + opts + ['-o', filename + '.opt.bc'], stdout=PIPE).communicate()[0] - assert os.path.exists(filename + '.opt.bc'), 'Failed to run llvm optimizations: ' + output - shutil.move(filename + '.opt.bc', filename) + target = out or (filename + '.opt.bc') + output = Popen([LLVM_OPT, filename] + opts + ['-o', target], stdout=PIPE).communicate()[0] + assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output + if not out: + shutil.move(filename + '.opt.bc', filename) @staticmethod def llvm_opts(filename): # deprecated version, only for test runner. TODO: remove @@ -1214,7 +1209,13 @@ class Building: # Run Emscripten Settings.RELOOPER = Cache.get_path('relooper.js') settings = Settings.serialize() - compiler_output = jsrun.timeout_run(Popen([PYTHON, EMSCRIPTEN, filename + ('.o.ll' if append_ext else ''), '-o', filename + '.o.js'] + settings + extra_args, stdout=PIPE), None, 'Compiling') + args = settings + extra_args + if WINDOWS: + args = ['@' + response_file.create_response_file(args, TEMP_DIR)] + cmdline = [PYTHON, EMSCRIPTEN, filename + ('.o.ll' if append_ext else ''), '-o', filename + '.o.js'] + args + if jsrun.TRACK_PROCESS_SPAWNS: + logging.info('Executing emscripten.py compiler with cmdline "' + ' '.join(cmdline) + '"') + compiler_output = jsrun.timeout_run(Popen(cmdline, stdout=PIPE), None, 'Compiling') #print compiler_output # Detect compilation crashes and errors @@ -1511,6 +1512,28 @@ class JS: return ident.replace('%', '$').replace('@', '_') @staticmethod + def make_initializer(sig, settings=None): + settings = settings or Settings + if sig == 'i': + return '0' + elif sig == 'f' and settings.get('PRECISE_F32'): + return 'Math_fround(0)' + else: + return '+0' + + @staticmethod + def make_coercion(value, sig, settings=None): + settings = settings or Settings + if sig == 'i': + return value + '|0' + elif sig == 'f' and settings.get('PRECISE_F32'): + return 'Math_fround(' + value + ')' + elif sig == 'd' or sig == 'f': + return '+' + value + else: + return value + + @staticmethod def make_extcall(sig, named=True): args = ','.join(['a' + str(i) for i in range(1, len(sig))]) args = 'index' + (',' if args else '') + args |