Avoid setting EM_CACHE unless we really need to (#797)

This avoid polluting the global environment which makes
side-by-side installational of different emscripten version
harder.

See https://github.com/emscripten-core/emscripten/pull/13954
This commit is contained in:
Sam Clegg
2021-04-26 06:29:01 -07:00
committed by GitHub
parent cee96f8054
commit 4282d5d44b
4 changed files with 28 additions and 20 deletions

View File

@@ -2171,6 +2171,14 @@ def find_tot_sdk():
return 'sdk-releases-upstream-%s-64bit' % (extra_release_tag)
def parse_emscripten_version(emscripten_root):
version_file = os.path.join(emscripten_root, 'emscripten-version.txt')
with open(version_file) as f:
version = f.read().strip()
version = version.strip('"').split('.')
return [int(v) for v in version]
# Given a git hash in emscripten-releases, find the emscripten
# version for it. There may not be one if this is not the hash of
# a release, in which case we return None.
@@ -2643,10 +2651,26 @@ def get_env_vars_to_add(tools_to_activate, system, user):
for tool in tools_to_activate:
config = tool.activated_config()
if 'EMSCRIPTEN_ROOT' in config:
# For older emscripten versions that don't use this default we export
# EM_CACHE.
em_cache_dir = os.path.join(config['EMSCRIPTEN_ROOT'], 'cache')
env_vars_to_add += [('EM_CACHE', em_cache_dir)]
# For older emscripten versions that don't use an embedded cache by
# default we need to export EM_CACHE.
#
# Sadly, we can't put this in the config file since those older versions
# also didn't read the `CACHE` key from the config file:
#
# History:
# - 'CACHE' config started being honored in 1.39.16
# https://github.com/emscripten-core/emscripten/pull/11091
# - Default to embedded cache also started in 1.39.16
# https://github.com/emscripten-core/emscripten/pull/11126
#
# Since setting EM_CACHE in the environment effects the entire machine
# we want to avoid this except when installing these older emscripten
# versions that really need it.
version = parse_emscripten_version(config['EMSCRIPTEN_ROOT'])
if version < [1, 39, 16]:
em_cache_dir = os.path.join(config['EMSCRIPTEN_ROOT'], 'cache')
env_vars_to_add += [('EM_CACHE', em_cache_dir)]
envs = tool.activated_environment()
for env in envs:
key, value = parse_key_value(env)

View File

@@ -12,12 +12,6 @@ MACOS = sys.platform == 'darwin'
assert 'EM_CONFIG' in os.environ, "emsdk should be activated before running this script"
# Remove the EM_CACHE environment variable. It interferes with testing since
# it would otherwise be fixed for the duration of the script and we expect
# "emsdk activate" to be able switch between SDKs during the running of this
# script.
del os.environ['EM_CACHE']
emconfig = os.environ['EM_CONFIG']
upstream_emcc = os.path.join('upstream', 'emscripten', 'emcc')
fastcomp_emcc = os.path.join('fastcomp', 'emscripten', 'emcc')

View File

@@ -32,7 +32,6 @@ try {
$EMSDK_NODE = [System.Environment]::GetEnvironmentVariable("EMSDK_NODE", $env_type)
$EMSDK_PYTHON = [System.Environment]::GetEnvironmentVariable("EMSDK_PYTHON", $env_type)
$JAVA_HOME = [System.Environment]::GetEnvironmentVariable("JAVA_HOME", $env_type)
$EM_CACHE = [System.Environment]::GetEnvironmentVariable("EM_CACHE", $env_type)
$PATH = [System.Environment]::GetEnvironmentVariable("PATH", $env_type)
if (!$EMSDK) {
@@ -50,9 +49,6 @@ try {
if (!$EMSDK_PYTHON) {
throw "EMSDK_PYTHON is not set for the user"
}
if (!$EM_CACHE) {
throw "EM_CACHE is not set for the user"
}
$path_split = $PATH.Split(';')
@@ -91,7 +87,6 @@ finally {
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "User")
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "User")
try {
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
@@ -99,7 +94,6 @@ finally {
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Machine")
} catch {}
@@ -108,7 +102,6 @@ finally {
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Process")
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Process")
refreshenv
}

View File

@@ -127,7 +127,6 @@ finally {
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "User")
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "User")
try {
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
@@ -135,7 +134,6 @@ finally {
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Machine")
} catch {}
@@ -144,7 +142,6 @@ finally {
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Process")
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Process")
refreshenv