Cleanup emsdk_env scripts (#539)
Remove the optional argument to contruct_env. It simple if we always construct the env in the same place. Avoid using temp files, and avoid changing directory.
This commit is contained in:
33
emsdk.py
33
emsdk.py
@@ -2490,6 +2490,9 @@ def set_active_tools(tools_to_activate, permanently_activate):
|
|||||||
copy_pregenerated_cache(tools_to_activate)
|
copy_pregenerated_cache(tools_to_activate)
|
||||||
|
|
||||||
# Construct a .bat script that will be invoked to set env. vars and PATH
|
# Construct a .bat script that will be invoked to set env. vars and PATH
|
||||||
|
# We only do this on windows since emsdk.bat is able to modify the
|
||||||
|
# calling shell environment. On other platform `source emsdk_env.sh` is
|
||||||
|
# required.
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
env_string = construct_env(tools_to_activate)
|
env_string = construct_env(tools_to_activate)
|
||||||
open(EMSDK_SET_ENV, 'w').write(env_string)
|
open(EMSDK_SET_ENV, 'w').write(env_string)
|
||||||
@@ -2612,11 +2615,11 @@ def construct_env(tools_to_activate):
|
|||||||
print('')
|
print('')
|
||||||
|
|
||||||
# A core variable EMSDK points to the root of Emscripten SDK directory.
|
# A core variable EMSDK points to the root of Emscripten SDK directory.
|
||||||
env_vars_to_add = [('EMSDK', to_unix_path(emsdk_path()))]
|
env_vars = [('EMSDK', to_unix_path(emsdk_path()))]
|
||||||
|
|
||||||
em_config_path = os.path.normpath(dot_emscripten_path())
|
em_config_path = os.path.normpath(dot_emscripten_path())
|
||||||
if to_unix_path(os.environ.get('EM_CONFIG', '')) != to_unix_path(em_config_path):
|
if to_unix_path(os.environ.get('EM_CONFIG', '')) != to_unix_path(em_config_path):
|
||||||
env_vars_to_add += [('EM_CONFIG', em_config_path)]
|
env_vars += [('EM_CONFIG', em_config_path)]
|
||||||
|
|
||||||
for tool in tools_to_activate:
|
for tool in tools_to_activate:
|
||||||
config = tool.activated_config()
|
config = tool.activated_config()
|
||||||
@@ -2624,14 +2627,18 @@ def construct_env(tools_to_activate):
|
|||||||
# For older emscripten versions that don't use this default we export
|
# For older emscripten versions that don't use this default we export
|
||||||
# EM_CACHE.
|
# EM_CACHE.
|
||||||
em_cache_dir = os.path.join(config['EMSCRIPTEN_ROOT'], 'cache')
|
em_cache_dir = os.path.join(config['EMSCRIPTEN_ROOT'], 'cache')
|
||||||
env_vars_to_add += [('EM_CACHE', em_cache_dir)]
|
env_vars += [('EM_CACHE', em_cache_dir)]
|
||||||
envs = tool.activated_environment()
|
envs = tool.activated_environment()
|
||||||
for env in envs:
|
for env in envs:
|
||||||
key, value = parse_key_value(env)
|
key, value = parse_key_value(env)
|
||||||
value = to_native_path(tool.expand_vars(value))
|
value = to_native_path(tool.expand_vars(value))
|
||||||
# Don't set env vars which are already set to the correct value.
|
env_vars += [(key, value)]
|
||||||
if key not in os.environ or to_unix_path(os.environ[key]) != to_unix_path(value):
|
|
||||||
env_vars_to_add += [(key, value)]
|
# Don't set env vars which are already set to the correct value.
|
||||||
|
env_vars_to_add = []
|
||||||
|
for key, value in env_vars:
|
||||||
|
if key not in os.environ or to_unix_path(os.environ[key]) != to_unix_path(value):
|
||||||
|
env_vars_to_add.append((key, value))
|
||||||
|
|
||||||
if env_vars_to_add:
|
if env_vars_to_add:
|
||||||
print('Setting environment variables:')
|
print('Setting environment variables:')
|
||||||
@@ -3006,19 +3013,15 @@ def main():
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
elif cmd == 'construct_env':
|
elif cmd == 'construct_env':
|
||||||
if len(sys.argv) == 2:
|
# Clean up old temp file up front, in case of failure later before we get
|
||||||
outfile = EMSDK_SET_ENV
|
# to write out the new one.
|
||||||
# Clean up old temp file up front, in case of failure later before we get
|
silentremove(EMSDK_SET_ENV)
|
||||||
# to write out the new one.
|
|
||||||
silentremove(EMSDK_SET_ENV)
|
|
||||||
else:
|
|
||||||
outfile = sys.argv[2]
|
|
||||||
tools_to_activate = currently_active_tools()
|
tools_to_activate = currently_active_tools()
|
||||||
tools_to_activate = process_tool_list(tools_to_activate, log_errors=True)
|
tools_to_activate = process_tool_list(tools_to_activate, log_errors=True)
|
||||||
env_string = construct_env(tools_to_activate)
|
env_string = construct_env(tools_to_activate)
|
||||||
open(outfile, 'w').write(env_string)
|
open(EMSDK_SET_ENV, 'w').write(env_string)
|
||||||
if UNIX:
|
if UNIX:
|
||||||
os.chmod(outfile, 0o755)
|
os.chmod(EMSDK_SET_ENV, 0o755)
|
||||||
return 0
|
return 0
|
||||||
elif cmd == 'update':
|
elif cmd == 'update':
|
||||||
update_emsdk()
|
update_emsdk()
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
@call "%~dp0emsdk" construct_env %*
|
@call "%~dp0emsdk" construct_env
|
||||||
|
|||||||
@@ -21,16 +21,13 @@ else
|
|||||||
set SRC="$SRC[2]"
|
set SRC="$SRC[2]"
|
||||||
endif
|
endif
|
||||||
set CURDIR=`pwd`
|
set CURDIR=`pwd`
|
||||||
cd `dirname "$SRC"`
|
set DIR=`dirname "$SRC"`
|
||||||
unset SRC
|
unset SRC
|
||||||
|
|
||||||
setenv EMSDK_CSH 1
|
setenv EMSDK_CSH 1
|
||||||
|
|
||||||
set tmpfile=`mktemp` || exit 1
|
$DIR/emsdk construct_env
|
||||||
./emsdk construct_env $tmpfile
|
source $DIR/emsdk_set_env.csh
|
||||||
source $tmpfile
|
unset DIR
|
||||||
rm -f $tmpfile
|
|
||||||
|
|
||||||
unsetenv EMSDK_CSH
|
unsetenv EMSDK_CSH
|
||||||
|
|
||||||
cd "$CURDIR"
|
|
||||||
|
|||||||
@@ -6,12 +6,8 @@
|
|||||||
set -l script (status -f)
|
set -l script (status -f)
|
||||||
set -l dir (dirname $script)
|
set -l dir (dirname $script)
|
||||||
|
|
||||||
pushd $dir > /dev/null
|
$dir/emsdk construct_env
|
||||||
|
. $dir/emsdk_set_env.sh
|
||||||
./emsdk construct_env
|
|
||||||
. ./emsdk_set_env.sh
|
|
||||||
|
|
||||||
set -e -l script
|
set -e -l script
|
||||||
set -e -l dir
|
set -e -l dir
|
||||||
|
|
||||||
popd > /dev/null
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
$ScriptDirectory = Split-Path -parent $PSCommandPath
|
$ScriptDirectory = Split-Path -parent $PSCommandPath
|
||||||
& "$ScriptDirectory/emsdk.ps1" construct_env $args
|
& "$ScriptDirectory/emsdk.ps1" construct_env
|
||||||
|
|||||||
21
emsdk_env.sh
21
emsdk_env.sh
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
# This script is sourced by the user and uses
|
# This script is sourced by the user and uses
|
||||||
# their shell. Try not to use bashisms.
|
# their shell. Try not to use bashisms.
|
||||||
|
|
||||||
@@ -15,18 +15,13 @@
|
|||||||
# ./emsdk_env.sh
|
# ./emsdk_env.sh
|
||||||
#
|
#
|
||||||
# which won't have any effect.
|
# which won't have any effect.
|
||||||
SRC="$BASH_SOURCE"
|
DIR="$BASH_SOURCE"
|
||||||
if [ "$SRC" = "" ]; then
|
if [ "$DIR" = "" ]; then
|
||||||
SRC="$0"
|
DIR="$0"
|
||||||
fi
|
fi
|
||||||
CURDIR="$(pwd)"
|
DIR="$(dirname "$DIR")"
|
||||||
cd "$(dirname "$SRC")"
|
|
||||||
unset SRC
|
|
||||||
|
|
||||||
tmpfile=`mktemp` || exit 1
|
|
||||||
# Force emsdk to use bash syntax so that this works in windows + bash too
|
# Force emsdk to use bash syntax so that this works in windows + bash too
|
||||||
EMSDK_BASH=1 ./emsdk construct_env $tmpfile
|
EMSDK_BASH=1 $DIR/emsdk construct_env
|
||||||
. $tmpfile
|
. $DIR/emsdk_set_env.sh
|
||||||
rm -f $tmpfile
|
unset DIR
|
||||||
|
|
||||||
cd "$CURDIR"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user