Skip to content

Commit 88586b1

Browse files
committed
Update default emscripten cache directory
Now that emscripten uses an in-tree cache directory there is no need to copy the pre-built libraries around. See: WebAssembly/waterfall#644 Also for the sake of older versions of emscripten explictly set EM_CACHE environment variable to point to the in-tree cache directory.
1 parent d75a9a8 commit 88586b1

File tree

1 file changed

+21
-53
lines changed

1 file changed

+21
-53
lines changed

emsdk.py

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,17 +1455,13 @@ def generate_dot_emscripten(active_tools):
14551455
if embedded:
14561456
cfg += 'import os\n'
14571457
cfg += "emsdk_path = os.path.dirname(os.environ.get('EM_CONFIG')).replace('\\\\', '/')\n"
1458-
cfg += "CACHE = '%s'\n" % sdk_path('.emscripten_cache')
14591458

14601459
# Different tools may provide the same activated configs; the latest to be
14611460
# activated is the relevant one.
14621461
activated_config = OrderedDict()
14631462
for tool in active_tools:
1464-
tool_cfg = tool.activated_config()
1465-
if tool_cfg:
1466-
for specific_cfg in tool_cfg.split(';'):
1467-
name, value = specific_cfg.split('=')
1468-
activated_config[name] = value
1463+
for name, value in tool.activated_config().items():
1464+
activated_config[name] = value
14691465

14701466
if 'NODE_JS' not in activated_config:
14711467
node_fallback = which('nodejs')
@@ -1474,7 +1470,7 @@ def generate_dot_emscripten(active_tools):
14741470
activated_config['NODE_JS'] = "'%s'" % node_fallback
14751471

14761472
for name, value in activated_config.items():
1477-
cfg += name + ' = ' + value + '\n'
1473+
cfg += name + " = '" + value + "'\n"
14781474

14791475
cfg += '''\
14801476
TEMP_DIR = '%s'
@@ -1493,11 +1489,9 @@ def generate_dot_emscripten(active_tools):
14931489
with open(dot_emscripten_path(), "w") as text_file:
14941490
text_file.write(cfg)
14951491

1496-
# Clear old cached emscripten content.
1492+
# Clear old emscripten content.
14971493
try:
1498-
remove_tree(os.path.join(emscripten_config_directory, ".emscripten_cache"))
14991494
os.remove(os.path.join(emscripten_config_directory, ".emscripten_sanity"))
1500-
os.remove(os.path.join(emscripten_config_directory, ".emscripten_cache__last_clear"))
15011495
except:
15021496
pass
15031497

@@ -1620,10 +1614,14 @@ def installation_dir(self):
16201614
# Returns the configuration item that needs to be added to .emscripten to make
16211615
# this Tool active for the current user.
16221616
def activated_config(self):
1623-
if hasattr(self, 'activated_cfg'):
1624-
return to_unix_path(self.expand_vars(self.activated_cfg))
1625-
else:
1626-
return ''
1617+
if not hasattr(self, 'activated_cfg'):
1618+
return {}
1619+
config = OrderedDict()
1620+
expanded = to_unix_path(self.expand_vars(self.activated_cfg))
1621+
for specific_cfg in expanded.split(';'):
1622+
name, value = specific_cfg.split('=')
1623+
config[name] = value.strip("'")
1624+
return config
16271625

16281626
def activated_environment(self):
16291627
if hasattr(self, 'activated_env'):
@@ -1727,20 +1725,18 @@ def is_active(self):
17271725
return False
17281726

17291727
activated_cfg = self.activated_config()
1730-
if activated_cfg == '':
1728+
if not activated_cfg:
17311729
return len(deps) > 0
17321730

1733-
activated_cfg = activated_cfg.split(';')
1734-
for cfg in activated_cfg:
1735-
cfg = cfg.strip()
1736-
key, value = parse_key_value(cfg)
1731+
for key, value in activated_cfg.items():
17371732
if key not in dot_emscripten:
17381733
debug_print(str(self) + ' is not active, because key="' + key + '" does not exist in .emscripten')
17391734
return False
17401735

17411736
# If running in embedded mode, all paths are stored dynamically relative
17421737
# to the emsdk root, so normalize those first.
17431738
dot_emscripten_key = dot_emscripten[key].replace("emsdk_path + '", "'" + emsdk_path())
1739+
dot_emscripten_key = dot_emscripten_key.strip("'")
17441740
if dot_emscripten_key != value:
17451741
debug_print(str(self) + ' is not active, because key="' + key + '" has value "' + dot_emscripten_key + '" but should have value "' + value + '"')
17461742
return False
@@ -2448,31 +2444,6 @@ def run_emcc(tools_to_activate):
24482444
return
24492445

24502446

2451-
def emscripten_cache_directory():
2452-
return os.path.join(emscripten_config_directory, ".emscripten_cache")
2453-
2454-
2455-
# Copy over any emscripten cache contents that were pregenerated. This avoids
2456-
# the user needing to immediately build libc etc. on first run.
2457-
def copy_pregenerated_cache(tools_to_activate):
2458-
for tool in tools_to_activate:
2459-
pregenerated_cache = getattr(tool, 'pregenerated_cache', None)
2460-
if not pregenerated_cache:
2461-
continue
2462-
for cache_dir in pregenerated_cache:
2463-
# Finish the install of an emscripten-releases build.
2464-
install_path = to_native_path(sdk_path(tool.expand_vars(tool.install_path)))
2465-
in_cache = os.path.join(install_path, 'lib', cache_dir)
2466-
if not os.path.exists(in_cache):
2467-
continue
2468-
out_cache = os.path.join(emscripten_cache_directory(), cache_dir)
2469-
os.makedirs(out_cache)
2470-
for filename in os.listdir(in_cache):
2471-
debug_print('Copying %s to cache: %s' % (filename, out_cache))
2472-
shutil.copy2(os.path.join(in_cache, filename),
2473-
os.path.join(out_cache, filename))
2474-
2475-
24762447
# Reconfigure .emscripten to choose the currently activated toolset, set PATH
24772448
# and other environment variables.
24782449
# Returns the full list of deduced tools that are now active.
@@ -2489,8 +2460,6 @@ def set_active_tools(tools_to_activate, permanently_activate):
24892460
# copy the cache contents.
24902461
run_emcc(tools_to_activate)
24912462

2492-
copy_pregenerated_cache(tools_to_activate)
2493-
24942463
# Construct a .bat script that will be invoked to set env. vars and PATH
24952464
if WINDOWS:
24962465
env_string = construct_env(tools_to_activate, False)
@@ -2628,15 +2597,14 @@ def construct_env(tools_to_activate, permanent):
26282597
em_config_path = os.path.normpath(dot_emscripten_path())
26292598
if to_unix_path(os.environ.get('EM_CONFIG', '')) != to_unix_path(em_config_path):
26302599
env_vars_to_add += [('EM_CONFIG', em_config_path)]
2631-
if emscripten_config_directory == emsdk_path():
2632-
# Remove this once emscripten support CACHE in the config file:
2633-
# https://github.com/emscripten-core/emscripten/pull/11091
2634-
em_cache_dir = sdk_path('.emscripten_cache')
2635-
if to_unix_path(os.environ.get('EM_CACHE', '')) != to_unix_path(em_cache_dir):
2636-
env_vars_to_add += [('EM_CACHE', em_cache_dir)]
2637-
mkdir_p(em_cache_dir)
26382600

26392601
for tool in tools_to_activate:
2602+
config = tool.activated_config()
2603+
if 'EMSCRIPTEN_ROOT' in config:
2604+
# For older emscripten versions that don't use this default we export
2605+
# EM_CACHE.
2606+
em_cache_dir = os.path.join(config['EMSCRIPTEN_ROOT'], 'cache')
2607+
env_vars_to_add += [('EM_CACHE', em_cache_dir)]
26402608
envs = tool.activated_environment()
26412609
for env in envs:
26422610
key, value = parse_key_value(env)

0 commit comments

Comments
 (0)