Avoid writing to file in emsdk_env.csh / emsdk_env.sh (#544)
This is an alternative fix for https://github.com/emscripten-core/emscripten/issues/9090 which recently came up again after #539. Tested with bash, tcsh and fish.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -9,9 +9,8 @@ __pycache__
|
||||
/.emscripten_sanity
|
||||
/.emscripten_sanity_wasm
|
||||
|
||||
# Auto-generated by `active`
|
||||
# Auto-generated by emsdk.py under windows by `construct_env` or `activate`
|
||||
/emsdk_set_env.bat
|
||||
/emsdk_set_env.sh
|
||||
|
||||
# Tags files that get generated at runtime
|
||||
/emscripten-releases-tot.txt
|
||||
|
||||
58
emsdk.py
58
emsdk.py
@@ -96,7 +96,6 @@ if WINDOWS:
|
||||
else:
|
||||
ENVPATH_SEPARATOR = ':'
|
||||
|
||||
|
||||
ARCH = 'unknown'
|
||||
# platform.machine() may return AMD64 on windows, so standardize the case.
|
||||
machine = platform.machine().lower()
|
||||
@@ -170,18 +169,7 @@ emscripten_config_directory = os.path.expanduser("~/")
|
||||
if os.path.exists(os.path.join(emsdk_path(), '.emscripten')):
|
||||
emscripten_config_directory = emsdk_path()
|
||||
|
||||
|
||||
def get_set_env_script_name():
|
||||
if POWERSHELL:
|
||||
return 'emsdk_set_env.ps1'
|
||||
if WINDOWS and not MSYS:
|
||||
return 'emsdk_set_env.bat'
|
||||
if CSH:
|
||||
return 'emsdk_set_env.csh'
|
||||
return 'emsdk_set_env.sh'
|
||||
|
||||
|
||||
EMSDK_SET_ENV = os.path.join(emsdk_path(), get_set_env_script_name())
|
||||
EMSDK_SET_ENV = os.path.join(emsdk_path(), 'emsdk_set_env.bat')
|
||||
|
||||
ARCHIVE_SUFFIXES = ('zip', '.tar', '.gz', '.xz', '.tbz2', '.bz2')
|
||||
|
||||
@@ -2479,6 +2467,11 @@ def copy_pregenerated_cache(tools_to_activate):
|
||||
os.path.join(out_cache, filename))
|
||||
|
||||
|
||||
def write_set_env_bat(env_string):
|
||||
assert(WINDOWS)
|
||||
open(EMSDK_SET_ENV, 'w').write(env_string)
|
||||
|
||||
|
||||
# Reconfigure .emscripten to choose the currently activated toolset, set PATH
|
||||
# and other environment variables.
|
||||
# Returns the full list of deduced tools that are now active.
|
||||
@@ -2503,7 +2496,7 @@ def set_active_tools(tools_to_activate, permanently_activate):
|
||||
# required.
|
||||
if WINDOWS:
|
||||
env_string = construct_env(tools_to_activate)
|
||||
open(EMSDK_SET_ENV, 'w').write(env_string)
|
||||
write_set_env_bat(env_string)
|
||||
|
||||
# Apply environment variables to global all users section.
|
||||
if WINDOWS and permanently_activate:
|
||||
@@ -2599,6 +2592,10 @@ def adjusted_path(tools_to_activate, log_additions=False, system_path_only=False
|
||||
return (separator.join(whole_path), new_emsdk_tools)
|
||||
|
||||
|
||||
def log_stderr(msg):
|
||||
sys.stderr.write(str(msg) + '\n')
|
||||
|
||||
|
||||
def construct_env(tools_to_activate):
|
||||
env_string = ''
|
||||
newpath, added_path = adjusted_path(tools_to_activate)
|
||||
@@ -2610,17 +2607,17 @@ def construct_env(tools_to_activate):
|
||||
elif CMD:
|
||||
env_string += 'SET PATH=' + newpath + '\n'
|
||||
elif CSH:
|
||||
env_string += 'setenv PATH "' + newpath + '"\n'
|
||||
env_string += 'setenv PATH "' + newpath + '";\n'
|
||||
elif BASH:
|
||||
env_string += 'export PATH="' + newpath + '"\n'
|
||||
env_string += 'export PATH="' + newpath + '";\n'
|
||||
else:
|
||||
assert False
|
||||
|
||||
if added_path:
|
||||
print('Adding directories to PATH:')
|
||||
log_stderr('Adding directories to PATH:')
|
||||
for item in added_path:
|
||||
print('PATH += ' + item)
|
||||
print('')
|
||||
log_stderr('PATH += ' + item)
|
||||
log_stderr('')
|
||||
|
||||
# A core variable EMSDK points to the root of Emscripten SDK directory.
|
||||
env_vars = [('EMSDK', to_unix_path(emsdk_path()))]
|
||||
@@ -2649,19 +2646,19 @@ def construct_env(tools_to_activate):
|
||||
env_vars_to_add.append((key, value))
|
||||
|
||||
if env_vars_to_add:
|
||||
print('Setting environment variables:')
|
||||
log_stderr('Setting environment variables:')
|
||||
for key, value in env_vars_to_add:
|
||||
if POWERSHELL:
|
||||
env_string += '$env:' + key + '="' + value + '"\n'
|
||||
elif CMD:
|
||||
env_string += 'SET ' + key + '=' + value + '\n'
|
||||
elif CSH:
|
||||
env_string += 'setenv ' + key + ' "' + value + '"\n'
|
||||
env_string += 'setenv ' + key + ' "' + value + '";\n'
|
||||
elif BASH:
|
||||
env_string += 'export ' + key + '="' + value + '"\n'
|
||||
env_string += 'export ' + key + '="' + value + '";\n'
|
||||
else:
|
||||
assert False
|
||||
print(key + ' = ' + value)
|
||||
log_stderr(key + ' = ' + value)
|
||||
return env_string
|
||||
|
||||
|
||||
@@ -3023,19 +3020,20 @@ def main():
|
||||
elif cmd == 'construct_env':
|
||||
# Clean up old temp file up front, in case of failure later before we get
|
||||
# to write out the new one.
|
||||
silentremove(EMSDK_SET_ENV)
|
||||
tools_to_activate = currently_active_tools()
|
||||
tools_to_activate = process_tool_list(tools_to_activate, log_errors=True)
|
||||
env_string = construct_env(tools_to_activate)
|
||||
open(EMSDK_SET_ENV, 'w').write(env_string)
|
||||
if UNIX:
|
||||
os.chmod(EMSDK_SET_ENV, 0o755)
|
||||
if WINDOWS and not BASH:
|
||||
write_set_env_bat(env_string)
|
||||
else:
|
||||
sys.stdout.write(env_string)
|
||||
return 0
|
||||
elif cmd == 'update':
|
||||
update_emsdk()
|
||||
# Clean up litter after old emsdk update which may have left this temp file
|
||||
# around.
|
||||
silentremove(sdk_path(EMSDK_SET_ENV))
|
||||
if WINDOWS:
|
||||
# Clean up litter after old emsdk update which may have left this temp
|
||||
# file around.
|
||||
silentremove(sdk_path(EMSDK_SET_ENV))
|
||||
return 0
|
||||
elif cmd == 'update-tags':
|
||||
fetch_emscripten_tags()
|
||||
|
||||
11
emsdk_env.csh
Executable file → Normal file
11
emsdk_env.csh
Executable file → Normal file
@@ -5,8 +5,6 @@
|
||||
# because it won't have any effect then.
|
||||
# That is, always run this script with
|
||||
#
|
||||
# . ./emsdk_env.csh
|
||||
# or
|
||||
# source ./emsdk_env.csh
|
||||
#
|
||||
# instead of just plainly running with
|
||||
@@ -18,16 +16,15 @@ set SRC=($_)
|
||||
if ("$SRC" == "") then
|
||||
set SRC="$0"
|
||||
else
|
||||
set SRC="$SRC[2]"
|
||||
set SRC="$SRC[1]"
|
||||
endif
|
||||
set CURDIR=`pwd`
|
||||
set DIR=`dirname "$SRC"`
|
||||
setenv DIR `dirname "$SRC"`
|
||||
unset SRC
|
||||
|
||||
setenv EMSDK_CSH 1
|
||||
|
||||
$DIR/emsdk construct_env
|
||||
source $DIR/emsdk_set_env.csh
|
||||
unset DIR
|
||||
eval `$DIR/emsdk construct_env`
|
||||
unsetenv DIR
|
||||
|
||||
unsetenv EMSDK_CSH
|
||||
|
||||
3
emsdk_env.fish
Executable file → Normal file
3
emsdk_env.fish
Executable file → Normal file
@@ -6,8 +6,7 @@
|
||||
set -l script (status -f)
|
||||
set -l dir (dirname $script)
|
||||
|
||||
$dir/emsdk construct_env
|
||||
. $dir/emsdk_set_env.sh
|
||||
eval ($dir/emsdk construct_env)
|
||||
|
||||
set -e -l script
|
||||
set -e -l dir
|
||||
|
||||
3
emsdk_env.sh
Executable file → Normal file
3
emsdk_env.sh
Executable file → Normal file
@@ -22,6 +22,5 @@ fi
|
||||
DIR="$(dirname "$DIR")"
|
||||
|
||||
# Force emsdk to use bash syntax so that this works in windows + bash too
|
||||
EMSDK_BASH=1 $DIR/emsdk construct_env
|
||||
. $DIR/emsdk_set_env.sh
|
||||
eval `EMSDK_BASH=1 $DIR/emsdk construct_env`
|
||||
unset DIR
|
||||
|
||||
Reference in New Issue
Block a user