diff options
-rwxr-xr-x | emscripten.py | 7 | ||||
-rw-r--r-- | tools/jsrun.py | 27 | ||||
-rw-r--r-- | tools/shared.py | 31 |
3 files changed, 37 insertions, 28 deletions
diff --git a/emscripten.py b/emscripten.py index a117a216..3487d320 100755 --- a/emscripten.py +++ b/emscripten.py @@ -12,6 +12,7 @@ headers, for the libc implementation in JS). import os, sys, json, optparse, subprocess, re, time, multiprocessing, functools from tools import shared +from tools import jsrun __rootpath__ = os.path.abspath(os.path.dirname(__file__)) def path_from_root(*pathelems): @@ -40,7 +41,7 @@ def process_funcs((i, funcs, meta, settings_file, compiler, forwarded_file, libr ll = ''.join(funcs) + '\n' + meta funcs_file = temp_files.get('.func_%d.ll' % i).name open(funcs_file, 'w').write(ll) - out = shared.run_js( + out = jsrun.run_js( compiler, engine=compiler_engine, args=[settings_file, funcs_file, 'funcs', forwarded_file] + libraries, @@ -160,7 +161,7 @@ def emscript(configuration, infile, settings, outfile, libraries=[], if out and DEBUG: print >> sys.stderr, ' loading pre from jcache' if not out: open(pre_file, 'w').write(pre_input) - out = shared.run_js(compiler, compiler_engine, [settings_file, pre_file, 'pre'] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) + out = jsrun.run_js(compiler, compiler_engine, [settings_file, pre_file, 'pre'] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) if jcache: if DEBUG: print >> sys.stderr, ' saving pre to jcache' jcache.set(shortkey, keys, out) @@ -312,7 +313,7 @@ def emscript(configuration, infile, settings, outfile, libraries=[], if DEBUG: t = time.time() post_file = temp_files.get('.post.ll').name open(post_file, 'w').write('\n') # no input, just processing of forwarded data - out = shared.run_js(compiler, compiler_engine, [settings_file, post_file, 'post', forwarded_file] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) + out = jsrun.run_js(compiler, compiler_engine, [settings_file, post_file, 'post', forwarded_file] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src')) post, last_forwarded_data = out.split('//FORWARDED_DATA:') # if this fails, perhaps the process failed prior to printing forwarded data? last_forwarded_json = json.loads(last_forwarded_data) diff --git a/tools/jsrun.py b/tools/jsrun.py new file mode 100644 index 00000000..27c55350 --- /dev/null +++ b/tools/jsrun.py @@ -0,0 +1,27 @@ +import time +from subprocess import Popen, PIPE, STDOUT + +def timeout_run(proc, timeout, note='unnamed process', full_output=False): + start = time.time() + if timeout is not None: + while time.time() - start < timeout and proc.poll() is None: + time.sleep(0.1) + if proc.poll() is None: + proc.kill() # XXX bug: killing emscripten.py does not kill it's child process! + raise Exception("Timed out: " + note) + out = proc.communicate() + return '\n'.join(out) if full_output else out[0] + +def run_js(filename, engine=None, args=[], check_timeout=False, stdout=PIPE, stderr=None, cwd=None, full_output=False): + if type(engine) is not list: + engine = [engine] + 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) diff --git a/tools/shared.py b/tools/shared.py index a7ca6391..afb80abf 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, zlib, re from subprocess import Popen, PIPE, STDOUT from tempfile import mkstemp +from . import jsrun def listify(x): if type(x) is not list: return [x] @@ -481,30 +482,10 @@ def check_engine(engine): print 'Checking JS engine %s failed. Check %s. Details: %s' % (str(engine), EM_CONFIG, str(e)) return False -def timeout_run(proc, timeout, note='unnamed process', full_output=False): - start = time.time() - if timeout is not None: - while time.time() - start < timeout and proc.poll() is None: - time.sleep(0.1) - if proc.poll() is None: - proc.kill() # XXX bug: killing emscripten.py does not kill it's child process! - raise Exception("Timed out: " + note) - out = proc.communicate() - return '\n'.join(out) if full_output else out[0] - -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] - engine = listify(engine) - 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) +def run_js(filename, engine=None, *args, **kw): + if engine is None: + engine = JS_ENGINES[0] + return jsrun.run_js(filename, engine, *args, **kw) def to_cc(cxx): # By default, LLVM_GCC and CLANG are really the C++ versions. This gets an explicit C version @@ -995,7 +976,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e # Run Emscripten Settings.RELOOPER = Cache.get_path('relooper.js') settings = Settings.serialize() - compiler_output = timeout_run(Popen([PYTHON, EMSCRIPTEN, filename + ('.o.ll' if append_ext else ''), '-o', filename + '.o.js'] + settings + extra_args, stdout=PIPE), None, 'Compiling') + 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') #print compiler_output # Detect compilation crashes and errors |