Refactor tools/shared.py to not create a emscripten_temp_xxxxx directory immediately on import, but only when asked. Fixes #706.

This commit is contained in:
Jukka Jylänki 2015-02-20 15:25:08 +02:00
Родитель ae36ccab84
Коммит 5aff002407
4 изменённых файлов: 22 добавлений и 15 удалений

7
emcc
Просмотреть файл

@ -1234,12 +1234,13 @@ try:
log_time('link')
if DEBUG:
logging.debug('saving intermediate processing steps to %s', shared.EMSCRIPTEN_TEMP_DIR)
emscripten_temp_dir = shared.get_emscripten_temp_dir()
logging.debug('saving intermediate processing steps to %s', emscripten_temp_dir)
intermediate_counter = 0
def save_intermediate(name=None, suffix='js'):
global intermediate_counter
shutil.copyfile(final, os.path.join(shared.EMSCRIPTEN_TEMP_DIR, 'emcc-%d%s.%s' % (intermediate_counter, '' if name is None else '-' + name, suffix)))
shutil.copyfile(final, os.path.join(emscripten_temp_dir, 'emcc-%d%s.%s' % (intermediate_counter, '' if name is None else '-' + name, suffix)))
intermediate_counter += 1
if not LEAVE_INPUTS_RAW: save_intermediate('basebc', 'bc')
@ -1374,7 +1375,7 @@ try:
open(memfile, 'wb').write(''.join(map(lambda x: chr(int(x or '0')), s.split(','))))
if DEBUG:
# Copy into temp dir as well, so can be run there too
shared.safe_copy(memfile, os.path.join(shared.EMSCRIPTEN_TEMP_DIR, os.path.basename(memfile)))
shared.safe_copy(memfile, os.path.join(shared.get_emscripten_temp_dir(), os.path.basename(memfile)))
return 'var memoryInitializer = "%s";' % os.path.basename(memfile)
src = re.sub(shared.JS.memory_initializer_pattern, repl, open(final).read(), count=1)
open(final + '.mem.js', 'w').write(src)

Просмотреть файл

@ -391,7 +391,7 @@ process(sys.argv[1])
for name in os.listdir(self.get_dir()):
try_delete(os.path.join(self.get_dir(), name) if not in_curr else name)
emcc_debug = os.environ.get('EMCC_DEBUG')
if emcc_debug and not in_curr:
if emcc_debug and not in_curr and EMSCRIPTEN_TEMP_DIR:
for name in os.listdir(EMSCRIPTEN_TEMP_DIR):
try_delete(os.path.join(EMSCRIPTEN_TEMP_DIR, name))

Просмотреть файл

@ -5,7 +5,8 @@ import shared
print 'Building zlib'
zlib = shared.Building.build_library('zlib', shared.EMSCRIPTEN_TEMP_DIR, shared.EMSCRIPTEN_TEMP_DIR, ['libz.a'], make_args=['libz.a'], copy_project=True, source_dir=shared.path_from_root('tests', 'zlib'))[0]
emscripten_temp_dir = shared.get_emscripten_temp_dir()
zlib = shared.Building.build_library('zlib', emscripten_temp_dir, emscripten_temp_dir, ['libz.a'], make_args=['libz.a'], copy_project=True, source_dir=shared.path_from_root('tests', 'zlib'))[0]
print 'Building minigzip'

Просмотреть файл

@ -617,6 +617,18 @@ def safe_ensure_dirs(dirname):
# handle this atomically in Python 2.x.
# There is an additional option for Python 3.x, though.
# Returns a path to EMSCRIPTEN_TEMP_DIR, creating one if it didn't exist.
def get_emscripten_temp_dir():
global configuration, EMSCRIPTEN_TEMP_DIR
if not EMSCRIPTEN_TEMP_DIR:
EMSCRIPTEN_TEMP_DIR = tempfile.mkdtemp(prefix='emscripten_temp_', dir=configuration.TEMP_DIR)
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
return EMSCRIPTEN_TEMP_DIR
class Configuration:
def __init__(self, environ=os.environ):
self.DEBUG = environ.get('EMCC_DEBUG')
@ -647,7 +659,7 @@ class Configuration:
def get_temp_files(self):
return tempfiles.TempFiles(
tmp=self.TEMP_DIR if not self.DEBUG else self.EMSCRIPTEN_TEMP_DIR,
tmp=self.TEMP_DIR if not self.DEBUG else get_emscripten_temp_dir(),
save_debug_files=os.environ.get('EMCC_DEBUG_SAVE'))
def apply_configuration():
@ -666,14 +678,6 @@ def set_logging():
logger.setLevel(logging.DEBUG if os.environ.get('EMCC_DEBUG') else logging.INFO)
set_logging()
if not EMSCRIPTEN_TEMP_DIR:
EMSCRIPTEN_TEMP_DIR = tempfile.mkdtemp(prefix='emscripten_temp_', dir=configuration.TEMP_DIR)
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
try:
@ -1254,7 +1258,8 @@ class Building:
cwd = os.getcwd()
try:
temp_dir = os.path.join(EMSCRIPTEN_TEMP_DIR, 'ar_output_' + str(os.getpid()) + '_' + str(len(temp_dirs)))
emscripten_temp_dir = get_emscripten_temp_dir()
temp_dir = os.path.join(emscripten_temp_dir, 'ar_output_' + str(os.getpid()) + '_' + str(len(temp_dirs)))
temp_dirs.append(temp_dir)
safe_ensure_dirs(temp_dir)
os.chdir(temp_dir)