diff options
author | Chad Austin <chad@imvu.com> | 2013-02-01 14:54:00 -0800 |
---|---|---|
committer | Chad Austin <chad@imvu.com> | 2013-03-04 19:34:28 -0800 |
commit | 74955d520119ed01509faf4976635a113bfe95bd (patch) | |
tree | 8788d1dbb662721f1b62f5b5f3742c6f1dbd7c82 | |
parent | f507b18f6a21731618ac8042802b05eb23d79543 (diff) |
make it possible to manually specify a temp directory when running emscripten.py
-rwxr-xr-x | emscripten.py | 32 | ||||
-rw-r--r-- | tools/shared.py | 34 | ||||
-rw-r--r-- | tools/tempfiles.py | 31 |
3 files changed, 54 insertions, 43 deletions
diff --git a/emscripten.py b/emscripten.py index f18b69b8..ccfd2ebf 100755 --- a/emscripten.py +++ b/emscripten.py @@ -46,8 +46,8 @@ def process_funcs((i, funcs, meta, settings_file, compiler, forwarded_file, libr tempfiles.try_delete(funcs_file) return out -def emscript(configuration, infile, settings, outfile, libraries=[], compiler_engine=None, - jcache=None, temp_files=None): +def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, + jcache=None, temp_files=None, DEBUG=False): """Runs the emscripten LLVM-to-JS compiler. We parallelize as much as possible Args: @@ -66,7 +66,7 @@ def emscript(configuration, infile, settings, outfile, libraries=[], compiler_en # 2 aka 'funcs': Process functions. We can parallelize this, working on each function independently. # 3 aka 'post' : Process globals, generate postamble and finishing touches. - configuration.debug_log('emscript: ll=>js') + if DEBUG: print >> sys.stderr, 'emscript: ll=>js' if jcache: jcache.ensure() @@ -491,7 +491,7 @@ Runtime.stackRestore = function(top) { asm.stackRestore(top) }; outfile.close() -def main(args, compiler_engine, cache, jcache, relooper, temp_files, configuration): +def main(args, compiler_engine, cache, jcache, relooper, temp_files, DEBUG): # Prepare settings for serialization to JSON. settings = {} for setting in args.settings: @@ -572,10 +572,8 @@ def main(args, compiler_engine, cache, jcache, relooper, temp_files, configurati from tools import shared shared.Building.ensure_relooper(relooper) - emscript(configuration, args.infile, settings, args.outfile, libraries, - compiler_engine=compiler_engine, - jcache=jcache, - temp_files=temp_files) + emscript(args.infile, settings, args.outfile, libraries, compiler_engine=compiler_engine, + jcache=jcache, temp_files=temp_files, DEBUG=DEBUG) def _main(environ): parser = optparse.OptionParser( @@ -599,7 +597,7 @@ def _main(environ): help='Which JS engine to use to run the compiler; defaults to the one in ~/.emscripten.') parser.add_option('--relooper', default=None, - help='Which relooper file to use if RELOOP is enabled') + help='Which relooper file to use if RELOOP is enabled.') parser.add_option('-s', '--setting', dest='settings', default=[], @@ -611,6 +609,9 @@ def _main(environ): action='store_true', default=False, help=('Enable jcache (ccache-like caching of compilation results, for faster incremental builds).')) + parser.add_option('-T', '--temp-dir', + default=None, + help=('Where to create temporary files.')) parser.add_option('--suppressUsageWarning', action='store_true', default=environ.get('EMSCRIPTEN_SUPPRESS_USAGE_WARNING'), @@ -639,12 +640,21 @@ WARNING: You should normally never use this! Use emcc instead. from tools import shared configuration = shared.Configuration(environ=os.environ) - temp_files = configuration.get_temp_files() + + if keywords.temp_dir is None: + temp_files = configuration.get_temp_files() + else: + temp_dir = os.path.abspath(keywords.temp_dir) + if not os.path.exists(temp_dir): + os.makedirs(temp_dir) + temp_files = tempfiles.TempFiles(temp_dir) if keywords.compiler is None: from tools import shared keywords.compiler = shared.COMPILER_ENGINE + DEBUG = configuration.DEBUG + cache = cache_module.Cache() temp_files.run_and_clean(lambda: main( keywords, @@ -653,7 +663,7 @@ WARNING: You should normally never use this! Use emcc instead. jcache=cache_module.JCache(cache) if keywords.jcache else None, relooper=relooper, temp_files=temp_files, - configuration=configuration + DEBUG=DEBUG )) if __name__ == '__main__': diff --git a/tools/shared.py b/tools/shared.py index 052be15b..ff9f9f9b 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1,7 +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, cache +from . import jsrun, cache, tempfiles def listify(x): if type(x) is not list: return [x] @@ -318,7 +318,7 @@ class Configuration: print >> sys.stderr, e, 'Could not create canonical temp dir. Check definition of TEMP_DIR in ~/.emscripten' def get_temp_files(self): - return TempFiles( + return tempfiles.TempFiles( tmp=self.TEMP_DIR if not self.DEBUG else self.EMSCRIPTEN_TEMP_DIR, save_debug_files=os.environ.get('EMCC_DEBUG_SAVE')) @@ -326,36 +326,6 @@ class Configuration: if self.DEBUG: print >> sys.stderr, msg -class TempFiles: - def __init__(self, tmp, save_debug_files=False): - self.tmp = tmp - self.save_debug_files = save_debug_files - - self.to_clean = [] - - def note(self, filename): - self.to_clean.append(filename) - - def get(self, suffix): - """Returns a named temp file with the given prefix.""" - named_file = tempfile.NamedTemporaryFile(dir=self.tmp, suffix=suffix, delete=False) - self.note(named_file.name) - return named_file - - def clean(self): - if self.save_debug_files: - print >> sys.stderr, 'not cleaning up temp files since in debug-save mode, see them in %s' % (self.tmp,) - return - for filename in self.to_clean: - try_delete(filename) - self.to_clean = [] - - def run_and_clean(self, func): - try: - return func() - finally: - self.clean() - configuration = Configuration(environ=os.environ) DEBUG = configuration.DEBUG EMSCRIPTEN_TEMP_DIR = configuration.EMSCRIPTEN_TEMP_DIR diff --git a/tools/tempfiles.py b/tools/tempfiles.py index 1953691e..06c4d1dd 100644 --- a/tools/tempfiles.py +++ b/tools/tempfiles.py @@ -1,8 +1,39 @@ import os import shutil +import tempfile def try_delete(filename): try: os.unlink(filename) except: shutil.rmtree(filename, ignore_errors=True) + +class TempFiles: + def __init__(self, tmp, save_debug_files=False): + self.tmp = tmp + self.save_debug_files = save_debug_files + + self.to_clean = [] + + def note(self, filename): + self.to_clean.append(filename) + + def get(self, suffix): + """Returns a named temp file with the given prefix.""" + named_file = tempfile.NamedTemporaryFile(dir=self.tmp, suffix=suffix, delete=False) + self.note(named_file.name) + return named_file + + def clean(self): + if self.save_debug_files: + print >> sys.stderr, 'not cleaning up temp files since in debug-save mode, see them in %s' % (self.tmp,) + return + for filename in self.to_clean: + try_delete(filename) + self.to_clean = [] + + def run_and_clean(self, func): + try: + return func() + finally: + self.clean() |