diff options
Diffstat (limited to 'tools/shared.py')
-rw-r--r-- | tools/shared.py | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/tools/shared.py b/tools/shared.py index db8f7a56..c9efe6ef 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1,6 +1,7 @@ import shutil, time, os, sys, json, tempfile, copy, shlex, atexit, subprocess, hashlib, cPickle, re 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 logging, platform @@ -204,25 +205,12 @@ else: config_file = '\n'.join(config_file) # autodetect some default paths config_file = config_file.replace('{{{ EMSCRIPTEN_ROOT }}}', __rootpath__) - llvm_root = '/usr/bin' - try: - llvm_root = os.path.dirname(Popen(['which', 'llvm-dis'], stdout=PIPE).communicate()[0].replace('\n', '')) - except: - pass + llvm_root = find_executable('llvm-dis') or '/usr/bin' config_file = config_file.replace('{{{ LLVM_ROOT }}}', llvm_root) - node = 'node' - try: - node = Popen(['which', 'node'], stdout=PIPE).communicate()[0].replace('\n', '') or \ - Popen(['which', 'nodejs'], stdout=PIPE).communicate()[0].replace('\n', '') or node - except: - pass + node = find_executable('node') or find_executable('nodejs') or 'node' config_file = config_file.replace('{{{ NODE }}}', node) - python = sys.executable or 'python' - try: - python = Popen(['which', 'python2'], stdout=PIPE).communicate()[0].replace('\n', '') or \ - Popen(['which', 'python'], stdout=PIPE).communicate()[0].replace('\n', '') or python - except: - pass + python = find_executable('python2') or find_executable('python') or \ + sys.executable or 'python' config_file = config_file.replace('{{{ PYTHON }}}', python) # write @@ -295,7 +283,7 @@ def check_node_version(): # 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.5.1' +EMSCRIPTEN_VERSION = '1.5.3' def generate_sanity(): return EMSCRIPTEN_VERSION + '|' + get_llvm_target() @@ -324,6 +312,7 @@ def check_sanity(force=False): if reason: logging.warning('(Emscripten: %s, clearing cache)' % reason) Cache.erase() + force = False # the check actually failed, so definitely write out the sanity file, to avoid others later seeing failures too # some warning, not fatal checks - do them even if EM_IGNORE_SANITY is on check_llvm_version() @@ -420,7 +409,7 @@ FILE_PACKAGER = path_from_root('tools', 'file_packager.py') # Temp dir. Create a random one, unless EMCC_DEBUG is set, in which case use TEMP_DIR/emscripten_temp class Configuration: - def __init__(self, environ): + def __init__(self, environ=os.environ): self.DEBUG = environ.get('EMCC_DEBUG') if self.DEBUG == "0": self.DEBUG = None @@ -448,11 +437,14 @@ class Configuration: tmp=self.TEMP_DIR if not self.DEBUG else self.EMSCRIPTEN_TEMP_DIR, save_debug_files=os.environ.get('EMCC_DEBUG_SAVE')) -configuration = Configuration(environ=os.environ) -DEBUG = configuration.DEBUG -EMSCRIPTEN_TEMP_DIR = configuration.EMSCRIPTEN_TEMP_DIR -DEBUG_CACHE = configuration.DEBUG_CACHE -CANONICAL_TEMP_DIR = configuration.CANONICAL_TEMP_DIR +def apply_configuration(): + global configuration, DEBUG, EMSCRIPTEN_TEMP_DIR, DEBUG_CACHE, CANONICAL_TEMP_DIR + configuration = Configuration() + DEBUG = configuration.DEBUG + EMSCRIPTEN_TEMP_DIR = configuration.EMSCRIPTEN_TEMP_DIR + DEBUG_CACHE = configuration.DEBUG_CACHE + CANONICAL_TEMP_DIR = configuration.CANONICAL_TEMP_DIR +apply_configuration() logging.basicConfig(format='%(levelname)-8s %(name)s: %(message)s') def set_logging(): @@ -462,9 +454,11 @@ set_logging() if not EMSCRIPTEN_TEMP_DIR: EMSCRIPTEN_TEMP_DIR = tempfile.mkdtemp(prefix='emscripten_temp_', dir=configuration.TEMP_DIR) - def clean_temp(): - try_delete(EMSCRIPTEN_TEMP_DIR) - atexit.register(clean_temp) + def prepare_to_clean_temp(d): + def clean_temp(): + try_delete(d) + atexit.register(clean_temp) + prepare_to_clean_temp(EMSCRIPTEN_TEMP_DIR) # this global var might change later # EM_CONFIG stuff @@ -939,7 +933,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e # Finish link actual_files = unique_ordered(actual_files) # tolerate people trying to link a.so a.so etc. - logging.debug('emcc: llvm-linking: %s', actual_files) + logging.debug('emcc: llvm-linking: %s to %s', actual_files, target) # check for too-long command line link_cmd = [LLVM_LINK] + actual_files + ['-o', target] @@ -1213,8 +1207,8 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e return opts @staticmethod - def js_optimizer(filename, passes, jcache): - return js_optimizer.run(filename, passes, listify(NODE_JS), jcache) + def js_optimizer(filename, passes, jcache, debug): + return js_optimizer.run(filename, passes, listify(NODE_JS), jcache, debug) @staticmethod def closure_compiler(filename, pretty=True): @@ -1288,9 +1282,6 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e emcc_debug = os.environ.get('EMCC_DEBUG') if emcc_debug: del os.environ['EMCC_DEBUG'] - emcc_optimize_normally = os.environ.get('EMCC_OPTIMIZE_NORMALLY') - if emcc_optimize_normally: del os.environ['EMCC_OPTIMIZE_NORMALLY'] - def make(opt_level): raw = relooper + '.raw.js' Building.emcc(os.path.join('relooper', 'Relooper.cpp'), ['-I' + os.path.join('relooper'), '--post-js', @@ -1321,7 +1312,6 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e finally: os.chdir(curr) if emcc_debug: os.environ['EMCC_DEBUG'] = emcc_debug - if emcc_optimize_normally: os.environ['EMCC_OPTIMIZE_NORMALLY'] = emcc_optimize_normally if not ok: logging.error('bootstrapping relooper failed. You may need to manually create relooper.js by compiling it, see src/relooper/emscripten') 1/0 |