|
| 1 | +:: Entry point for running python scripts on windows systems. |
| 2 | +:: |
| 3 | +:: Automatically generated by `create_entry_points.py`; DO NOT EDIT. |
| 4 | +:: |
| 5 | +:: To make modifications to this file, edit `tools/run_python.bat` and then run |
| 6 | +:: `tools/create_entry_points.py` |
| 7 | + |
| 8 | +:: All env. vars specified in this file are to be local only to this script. |
| 9 | +@setlocal |
| 10 | + |
| 11 | +@set EM_PY=%EMSDK_PYTHON% |
| 12 | +@if "%EM_PY%"=="" ( |
| 13 | + set EM_PY=python |
| 14 | +) |
| 15 | + |
| 16 | +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a |
| 17 | +:: shared stdin handle from the parent process, and that parent process stdin handle is in |
| 18 | +:: a certain state, running python.exe might hang here. To work around this, if |
| 19 | +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid |
| 20 | +:: sharing the parent's stdin handle to it, avoiding the hang. |
| 21 | + |
| 22 | +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, |
| 23 | +:: even when the python executable above did succeed and quit with errorlevel 0 above. |
| 24 | +:: On Windows 8 and newer, this issue has not been observed. It is possible that this |
| 25 | +:: issue is related to the above python bug, but this has not been conclusively confirmed, |
| 26 | +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known |
| 27 | +:: workaround this issue, which is to explicitly quit the calling process with the previous |
| 28 | +:: errorlevel from the above command. |
| 29 | + |
| 30 | +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from |
| 31 | +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that |
| 32 | +:: would throw off the parsing of the cmdline arg. |
| 33 | +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( |
| 34 | + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( |
| 35 | + goto NORMAL |
| 36 | + ) else ( |
| 37 | + goto NORMAL_EXIT |
| 38 | + ) |
| 39 | +) else ( |
| 40 | + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( |
| 41 | + goto MUTE_STDIN |
| 42 | + ) else ( |
| 43 | + goto MUTE_STDIN_EXIT |
| 44 | + ) |
| 45 | +) |
| 46 | + |
| 47 | +:NORMAL_EXIT |
| 48 | +@"%EM_PY%" "%~dp0\%~n0.py" %* |
| 49 | +@exit %ERRORLEVEL% |
| 50 | + |
| 51 | +:MUTE_STDIN |
| 52 | +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL |
| 53 | +@exit /b %ERRORLEVEL% |
| 54 | + |
| 55 | +:MUTE_STDIN_EXIT |
| 56 | +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL |
| 57 | +@exit %ERRORLEVEL% |
| 58 | + |
| 59 | +:NORMAL |
| 60 | +@"%EM_PY%" "%~dp0\%~n0.py" %* |
0 commit comments