-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove python_selector.py in favor of run_python.sh #10729
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm, while we assume most windows users use the bat files, they should still be able to do python
on the python files?
@@ -2464,12 +2464,12 @@ def test_mmap_file(self): | |||
def test_emrun_info(self): | |||
if not has_browser(): | |||
self.skipTest('need a browser') | |||
result = run_process([PYTHON, path_from_root('emrun'), '--system_info', '--browser_info'], stdout=PIPE).stdout | |||
result = run_process([PYTHON, path_from_root('emrun.py'), '--system_info', '--browser_info'], stdout=PIPE).stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change necessary? if it is that seems like a breaking change. if it isn't then why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this change is a slightly breaking change. You can no longer run python emcc
(because emcc is now itself a shell script that runs python). You can still run ./emcc.py
directly or python emcc.py
if you like.
I think this is the best approach. The python_selector method where python re-invokes itself is kind of nasty. If I run python2 emcc
I kind of expect it to run under python2 not invoke a python3 subprocess to run itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm. is there some way we can show a clear error on python emcc / emranlib / etc.
, like keeping the files around but only containing a print of an error? or if that's not possible, maybe a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not deleting those files. They are now symbolic links to run_python.sh
. So they exist by they are shell scripts.
I'm not sure we can have python <some_shell_script>
do anything useful... but let me see...
@@ -1,19 +1,17 @@ | |||
#!/usr/bin/env python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is em++.py special among the tools? seems like it's getting different treatment in this PR than the others and it's not obvious why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because em++ was using the python_selector in a slightly different way. It was using it to redirect to emcc.py as well as to choose the python version.
With this change, once python is running we assume its the correct version, we never try to re-invoke python. So this change means that em++ now runs emcc directly, without re-invoking python.
Yes. One can always run python on the |
The essential problem here is that there is no |
@@ -2464,12 +2464,12 @@ def test_mmap_file(self): | |||
def test_emrun_info(self): | |||
if not has_browser(): | |||
self.skipTest('need a browser') | |||
result = run_process([PYTHON, path_from_root('emrun'), '--system_info', '--browser_info'], stdout=PIPE).stdout | |||
result = run_process([PYTHON, path_from_root('emrun.py'), '--system_info', '--browser_info'], stdout=PIPE).stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm. is there some way we can show a clear error on python emcc / emranlib / etc.
, like keeping the files around but only containing a print of an error? or if that's not possible, maybe a comment?
Ubuntu 20.04 dropped the /usr/bin/python symlink so it is no longer possible use `/usr/bin/env python` in launcher scripts and then rely on python_selector.py to select a different python version. Instead we go back to age-old method of using shell wrapper script. Here I create a single wrapper script called run_python.sh which runs a commmand under the best version of python it can find. Each unsiffixed command is then a symbol link to this shell script. Since windows users use the .bat files it shouldn't matter whether or not these symlinks work on windows. Fixes #10726
The non-py version of these scripts were converted to shell scripts in #10729. The .bat files run python explicitly so can directly reference .py versions of these scripts. Also, move em-config to em-config.py to match all the others.
The non-py version of these scripts were converted to shell scripts in #10729. The .bat files run python explicitly so can directly reference .py versions of these scripts. Also, move em-config to em-config.py to match all the others.
Have just upgraded to 1.39.12 and found this PR broke running the compiler on my Windows/MinGW environment :-( $ emcc --version
/c/emsdk/upstream/emscripten/emcc: line 1: tools/run_python.sh: No such file or directory |
Just realized emcc etc should be symbolic links now.. so is there some post-process that is failing here? :-/ Anyway, i made this script to workaround it... #!/bin/sh
base_dir=$(dirname "$0")
find $base_dir -type f -name "*.orig" -o -name "*.rej" | xargs -l rm
emsdk update
emsdk install latest
for p in `ls $base_dir/*.diff`; do cd $EMSCRIPTEN && patch -p1 < $p; done
files=("em++" "emar" "emcc" "emcmake" "emconfigure" "emmake" "emranlib" "emrun" "emscons")
for f in "${files[@]}"
do
rm -f "$EMSCRIPTEN/$f"
ln -s "$EMSCRIPTEN/tools/run_python.sh" "$EMSCRIPTEN/$f"
done
sed -i -e 's-which-& 2>/dev/null-g' "$EMSCRIPTEN/tools/run_python.sh" Later on, the first time i tried to compile something i got this error: $ ./build.sh
patching file dcraw.tmp.c
emcc: error: 'C:/emsdk/upstream/bin\clang++.exe --version' failed: [Error 5] Acceso denegado On the next attempt though, it did worked fine $ ./build.sh
patching file dcraw.tmp.c
shared:INFO: (Emscripten: system change: 1.39.12|C:/emsdk/upstream/bin|11.0_wasm vs 1.39.11|C:/emsdk/upstream/bin|11.0_wasm, clearing cache)
shared:INFO: (Emscripten: Running sanity checks)
emcc:WARNING: --llvm-lto ignored when using llvm backend
....[snip]
cache:INFO: generating system asset: is_vanilla.txt... (this will be cached in "C:\msys\1.0\home\dc\.emscripten_cache\is_vanilla.txt" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libc.a... (this will be cached in "C:\msys\1.0\home\dc\.emscripten_cache\wasm-lto\libc.a" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libcompiler_rt.a... (this will be cached in "C:\msys\1.0\home\dc\.emscripten_cache\wasm-lto\libcompiler_rt.a" for subsequent builds)
cache:INFO: - ok
...[snip] If you guys want me to do some further troubleshooting, a PR for my env, etc lmk. |
Sadly we don't really have the time or resources to test in MINGW. I think the problem here is that you are installing the windows SDK, but then using the compiler not via the If you want to fix this we might need your help. I can think of possible options:
|
Also just found out that emcc now bails with an error on MSYS. Worked fine prior to this. emcc isn't a symlink for me. It is a small text file that literally contains the string "tools/run_python.sh". This is how Git handles symlinks on Windows by default. https://github.com/git-for-windows/git/wiki/Symbolic-Links In my opinion it is always a mistake use symlinks in distribution. Just don't do it. A small shell script that finds the run_python.sh script from anywhere will work just fine. |
Here's an idea with a hypothetical tools/find_python.sh script: #!/bin/sh
abspath="$(type -p $0)"
emroot=$(dirname "$abspath")
python=$("$emroot"/tools/find_python.sh)
exec $python "$abspath.py" "$@" |
Does simply removing I think it makes sense to include I agree symbol links are bad idea on windows and we should not be using them. But on linux/mac there is nothing wrong with symbolic links (clang is symlink to clang-11, for example). |
No, .bat files do not work in bash. You're making a mistaken assumption that Windows users want to use cmd.exe. I used Linux for a decade. I want to (and can) use bash. MSYS2 and Git Bash bundled with Git for Windows provides a POSIX compatibility layer over the C runtime and filesystem (similar to Emscripten). I can even configure VS Code to run tasks and launch terminals with bash, because Microsoft supports that out of the box. It's mind blowing the first time you try it, but it's a standard thing these days. Just don't use symlinks. |
I'm curious how other software interacts with MSYS. For example windows python. If you type Also, if you can't run I'm also curious how @diegocr fix works, given that is does use symlinks (it seems to replace the fake symlinks with real ones) and also seems to solve the problem. What is the |
I just type
It doesn't. If I come across software like that, which is actually rare, I make a launcher shell script for it. I have no use for .bat files except as reference for the shell script implementation.
|
Ok, sounds like its worth fixing the shell launchers to work under MSYS. Are you mostly concerned about the emsdk use case? Or do you want |
Ths way it's set up is perfect. Symlinks are the only problem, really. |
Would you be OK with the emsdk image containing the fix to goes do you think it needs to go all the way back the git content? |
OK, lets try this: #10921 |
Hi guys, sorry for the late reply - I've just installed 1.39.13 and all is good now, Thanks! |
PYTHON=$(which python3) | ||
fi | ||
|
||
if [ -z $PYTHON ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that it's possible for Python to be installed in a path with spaces, which breaks this line: #11005
Ubuntu 20.04 dropped the /usr/bin/python symlink so it is no longer
possible use
/usr/bin/env python
in launcher scripts and thenrely on python_selector.py to select a different python version.
Instead we go back to age-old method of using shell wrapper script.
Here I create a single wrapper script called run_python.sh which
runs a commmand under the best version of python it can find. Each
unsiffixed command is then a symbol link to this shell script. Since
windows users use the .bat files it shouldn't matter whether or not
these symlinks work on windows.
Fixes #10726