Remove TempFiles's dependency on global and environment variables
This commit is contained in:
Родитель
90b9f2199f
Коммит
c83c53bfe5
|
@ -32,7 +32,7 @@ def path_from_root(*pathelems):
|
|||
"""
|
||||
return os.path.join(__rootpath__, *pathelems)
|
||||
|
||||
temp_files = shared.TempFiles()
|
||||
temp_files = shared.ConfigureTempFiles()
|
||||
|
||||
compiler_engine = None
|
||||
jcache = False
|
||||
|
@ -574,7 +574,7 @@ def main(args):
|
|||
|
||||
emscript(args.infile, settings, args.outfile, libraries)
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
parser = optparse.OptionParser(
|
||||
usage='usage: %prog [-h] [-H HEADERS] [-o OUTFILE] [-c COMPILER_ENGINE] [-s FOO=BAR]* infile',
|
||||
description=('You should normally never use this! Use emcc instead. '
|
||||
|
@ -618,3 +618,5 @@ if __name__ == '__main__':
|
|||
|
||||
temp_files.run_and_clean(lambda: main(keywords))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import os, sys, subprocess, multiprocessing, re
|
||||
import shared
|
||||
|
||||
temp_files = shared.TempFiles()
|
||||
temp_files = shared.ConfigureTempFiles()
|
||||
|
||||
__rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
def path_from_root(*pathelems):
|
||||
|
|
|
@ -425,7 +425,10 @@ def try_delete(filename):
|
|||
pass
|
||||
|
||||
class TempFiles:
|
||||
def __init__(self):
|
||||
def __init__(self, tmp, saveDebugFiles=False):
|
||||
self.tmp = tmp
|
||||
self.saveDebugFiles = saveDebugFiles
|
||||
|
||||
self.to_clean = []
|
||||
|
||||
def note(self, filename):
|
||||
|
@ -433,13 +436,13 @@ class TempFiles:
|
|||
|
||||
def get(self, suffix):
|
||||
"""Returns a named temp file with the given prefix."""
|
||||
named_file = tempfile.NamedTemporaryFile(dir=TEMP_DIR if not DEBUG else EMSCRIPTEN_TEMP_DIR, suffix=suffix, delete=False)
|
||||
named_file = tempfile.NamedTemporaryFile(dir=self.tmp, suffix=suffix, delete=False)
|
||||
self.note(named_file.name)
|
||||
return named_file
|
||||
|
||||
def clean(self):
|
||||
if os.environ.get('EMCC_DEBUG_SAVE'):
|
||||
print >> sys.stderr, 'not cleaning up temp files since in debug-save mode, see them in %s' % EMSCRIPTEN_TEMP_DIR
|
||||
if self.saveDebugFiles:
|
||||
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)
|
||||
|
@ -451,6 +454,11 @@ class TempFiles:
|
|||
finally:
|
||||
self.clean()
|
||||
|
||||
def ConfigureTempFiles():
|
||||
return TempFiles(
|
||||
tmp=TEMP_DIR if not DEBUG else EMSCRIPTEN_TEMP_DIR,
|
||||
saveDebugFiles=os.environ.get('EMCC_DEBUG_SAVE'))
|
||||
|
||||
# Utilities
|
||||
|
||||
def check_engine(engine):
|
||||
|
|
Загрузка…
Ссылка в новой задаче