This change allows sourcing emsdk_env.sh from bash, zsh and
ksh.
The script works out the true location of the emsdk directory,
even if it is a symlink or the script itself is a symlink.
Added a test in scripts/test_source_env.sh to try sourcing via
all the shells and with various paths.
Co-authored-by: Bob Tolbert <bob@tolbert.org>
This is a because its not possible to determine the location
of as script that is currently being sources under a POSIX shell
such as dash (the default ubuntu shell). Only bash has this
special BASH_SCRIPT variable.
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 allows `emsdk_env.sh` to work under bash for windows even in the
absence of the `MSYSTEM` environment variable (which seems to be
the setup on circle CI.
The code for construct_env expects the output file to be at `argv[2]`,
but it is actually invoked in emsdk_env.{sh,fish} with $@ there
instead. Usually this is not a problem because the emdsk_env.{sh,fish}
is `sourced` directly from the user's shell and $@ is empty, but this
can break in scripted environments.
The $@ was added two years ago in 3b6c6b86 for no discernible reason,
but it was entirely ignored in the code until last month when #307
added a meaningful argument to construct_env but incorrectly kept the
$@.
It seems that some variables were mistakenly left unquoted, leading to paths containing spaces being treated incorrectly.
For example, the directory `/home/person/foo bar/test/` would cause `CURDIR=$(pwd)` to be expanded to `CURDIR=/home/person/foo bar/test/`. This means that the shell would attempt to run the command `bar/test/` with the environment variable `CURDIR` set to `/home/person/foo`. This is due to [word splitting](https://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html). (TL;DR the result of shell expansions should probably be quoted 99% of the time)
Move into the emsdk directory before running ./emsdk. Make it possible to add `test -x $EMSCRIPTEN/emsdk_env.sh && source $EMSCRIPTEN/emsdk_env.sh` to my shell initialization script.