Small bug in emsdk_env.sh when sourced from another script

29 views
Skip to first unread message

Benjamin Golinvaux

unread,
Jan 27, 2020, 8:02:52 AM1/27/20
to emscripten-discuss
Hello

I have build script that I call like that:

./build.sh RelWithDebInfo

Inside this script, I source the emsdk_env.sh file like that:

cd $somewhere
source ./emsdk_env.sh

then, below, I am using

emconfigure cmake ..... 

I noticed that it stopped working a few releases ago (emconfigure not found).

And, indeed, my PATH variable (I am using Ubuntu 16 in WSL) was not updated inside my script.

I inserted debug logs and I traced the problem to this (in emsdk_env.sh):

./emsdk construct_env "$@" $tmpfile

and this (around line 2645 in 1.38.41 in emsdk):

  elif cmd == 'construct_env':
    if len(sys.argv) == 2:
      outfile = EMSDK_SET_ENV
      silentremove(EMSDK_SET_ENV) # Clean up old temp file up front, in case of failure later before we get to write out the new one.
    else:
      outfile = sys.argv[2]

The thing is, when I source emsdk_env.sh without arguments, "$@" is not empty, but contains the list of arguments from my build.sh script!

So, the following line

./emsdk construct_env "$@" $tmpfile 

becomes equivalent to 

./emsdk construct_env "RelWithDebInfo" $tmpfile

and, since the Python code does special processing when len(sys.argv) != 2, the outfile where the EXPORT statements are written is not the correct one (which is $tmpFile)

This causes the environment setup script to be written to a file called RelWithDebInfo that is not called at all.

The workaround is to use 

source ./emsdk_env.sh "" 

when sourcing the EMSDK env file.

I am not sure there is a solution, but maybe having a separate emsdk_env_src.sh file meant to be sourced and that uses no arguments would be a good idea (just my $0.02)

In case someone wastes time on this as I did, I thought it'd be interesting to share...

Thanks for your attention :)






Sam Clegg

unread,
Jan 27, 2020, 6:10:04 PM1/27/20
to emscripte...@googlegroups.com
Looks like an emsdk bug.  Would you mind filing an issue here: https://github.com/emscripten-core/emsdk/issues

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/85eac63b-f49d-4ea6-bb25-d26d04e7c032%40googlegroups.com.

Benjamin Golinvaux

unread,
Jan 29, 2020, 9:47:16 AM1/29/20
to emscripten-discuss
Hello

I created a detailed issue (that has been noticed).


Thanks.
Reply all
Reply to author
Forward
0 new messages