diff --git a/ChangeLog.md b/ChangeLog.md index 5684036c63a37..b445747ac0b38 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -36,6 +36,10 @@ See docs/process.md for more on how version tagging works. `__syscall22`) to name-based (e.g. `__syscall_open`). This should not be a visible change except for folks trying to intercept/implement syscalls in native code (#15202). +- Fixed launcher batch script issues on Windows, and added two env. vars + EM_WORKAROUND_PYTHON_BUG_34780 and EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG that + can be enabled to work around a Windows Python issue + https://bugs.python.org/issue34780 , and a Windows 7 exit code issue (#15146) 2.0.31 - 10/01/2021 ------------------- diff --git a/em++.bat b/em++.bat index 800fad8ac3f78..9de276dadece8 100644 --- a/em++.bat +++ b/em++.bat @@ -5,18 +5,65 @@ :: To make modifications to this file, edit `tools/run_python_compiler.bat` and :: then run `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. +@setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: If _EMCC_CCACHE is not set, do a regular invocation of the python compiler driver. +:: Otherwise remove the ccache env. var, and then reinvoke this script with ccache enabled. @if "%_EMCC_CCACHE%"=="" ( - :: Do regular invocation of the python compiler driver set CMD="%EM_PY%" "%~dp0\%~n0.py" ) else ( - :: Remove the ccache env. var, invoke ccache and re-enter this script to take the above branch. set _EMCC_CCACHE= set CMD=ccache "%~dp0\%~n0.bat" ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@%CMD% %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@%CMD% %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@%CMD% %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @%CMD% %* diff --git a/em-config.bat b/em-config.bat index f9ce949e613f0..2d981b1168899 100644 --- a/em-config.bat +++ b/em-config.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/emar.bat b/emar.bat index f9ce949e613f0..2d981b1168899 100644 --- a/emar.bat +++ b/emar.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/embuilder.bat b/embuilder.bat index f9ce949e613f0..2d981b1168899 100644 --- a/embuilder.bat +++ b/embuilder.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/emcc.bat b/emcc.bat index 800fad8ac3f78..9de276dadece8 100644 --- a/emcc.bat +++ b/emcc.bat @@ -5,18 +5,65 @@ :: To make modifications to this file, edit `tools/run_python_compiler.bat` and :: then run `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. +@setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: If _EMCC_CCACHE is not set, do a regular invocation of the python compiler driver. +:: Otherwise remove the ccache env. var, and then reinvoke this script with ccache enabled. @if "%_EMCC_CCACHE%"=="" ( - :: Do regular invocation of the python compiler driver set CMD="%EM_PY%" "%~dp0\%~n0.py" ) else ( - :: Remove the ccache env. var, invoke ccache and re-enter this script to take the above branch. set _EMCC_CCACHE= set CMD=ccache "%~dp0\%~n0.bat" ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@%CMD% %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@%CMD% %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@%CMD% %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @%CMD% %* diff --git a/emcmake.bat b/emcmake.bat index f9ce949e613f0..2d981b1168899 100644 --- a/emcmake.bat +++ b/emcmake.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/emconfigure.bat b/emconfigure.bat index f9ce949e613f0..2d981b1168899 100644 --- a/emconfigure.bat +++ b/emconfigure.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/emdump.bat b/emdump.bat index 769cd236d7fa8..ed920be000483 100644 --- a/emdump.bat +++ b/emdump.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\tools\emdump.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\tools\emdump.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\tools\emdump.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\tools\emdump.py" %* diff --git a/emdwp.bat b/emdwp.bat index b16d072111f81..29d98d66cce7f 100644 --- a/emdwp.bat +++ b/emdwp.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\tools\emdwp.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\tools\emdwp.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\tools\emdwp.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\tools\emdwp.py" %* diff --git a/emmake.bat b/emmake.bat index f9ce949e613f0..2d981b1168899 100644 --- a/emmake.bat +++ b/emmake.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/emnm.bat b/emnm.bat index 2f350f34a8f24..9415f162435ee 100644 --- a/emnm.bat +++ b/emnm.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\tools\emnm.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\tools\emnm.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\tools\emnm.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\tools\emnm.py" %* diff --git a/emprofile.bat b/emprofile.bat index 74dbf0c99e3aa..c9e327a82637a 100644 --- a/emprofile.bat +++ b/emprofile.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\tools\emprofile.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\tools\emprofile.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\tools\emprofile.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\tools\emprofile.py" %* diff --git a/emranlib.bat b/emranlib.bat index f9ce949e613f0..2d981b1168899 100644 --- a/emranlib.bat +++ b/emranlib.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/emrun.bat b/emrun.bat index f9ce949e613f0..2d981b1168899 100644 --- a/emrun.bat +++ b/emrun.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/emscons.bat b/emscons.bat index f9ce949e613f0..2d981b1168899 100644 --- a/emscons.bat +++ b/emscons.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/emsize.bat b/emsize.bat index f9ce949e613f0..2d981b1168899 100644 --- a/emsize.bat +++ b/emsize.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/tests/runner.bat b/tests/runner.bat index f9ce949e613f0..2d981b1168899 100644 --- a/tests/runner.bat +++ b/tests/runner.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/tests/test_other.py b/tests/test_other.py index 724bf7f4b3797..30fc182e437fb 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -11076,3 +11076,12 @@ def test_emscripten_set_timeout(self): @node_pthreads def test_emscripten_set_timeout_loop(self): self.do_runf(test_file('emscripten_set_timeout_loop.c'), args=['-s', 'USE_PTHREADS', '-s', 'PROXY_TO_PTHREAD']) + + # Verify that we are able to successfully compile a script when the Windows 7 + # and Python workaround env. vars are enabled. + # See https://bugs.python.org/issue34780 + @with_env_modify({'EM_WORKAROUND_PYTHON_BUG_34780': '1', + 'EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG': '1'}) + def test_windows_batch_script_workaround(self): + self.run_process([EMCC, test_file('hello_world.c')]) + self.assertExists('a.out.js') diff --git a/tools/file_packager.bat b/tools/file_packager.bat index f9ce949e613f0..2d981b1168899 100644 --- a/tools/file_packager.bat +++ b/tools/file_packager.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/tools/run_python.bat b/tools/run_python.bat index f9ce949e613f0..2d981b1168899 100644 --- a/tools/run_python.bat +++ b/tools/run_python.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %* diff --git a/tools/run_python_compiler.bat b/tools/run_python_compiler.bat index 800fad8ac3f78..9de276dadece8 100644 --- a/tools/run_python_compiler.bat +++ b/tools/run_python_compiler.bat @@ -5,18 +5,65 @@ :: To make modifications to this file, edit `tools/run_python_compiler.bat` and :: then run `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. +@setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: If _EMCC_CCACHE is not set, do a regular invocation of the python compiler driver. +:: Otherwise remove the ccache env. var, and then reinvoke this script with ccache enabled. @if "%_EMCC_CCACHE%"=="" ( - :: Do regular invocation of the python compiler driver set CMD="%EM_PY%" "%~dp0\%~n0.py" ) else ( - :: Remove the ccache env. var, invoke ccache and re-enter this script to take the above branch. set _EMCC_CCACHE= set CMD=ccache "%~dp0\%~n0.bat" ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@%CMD% %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@%CMD% %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@%CMD% %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @%CMD% %* diff --git a/tools/webidl_binder.bat b/tools/webidl_binder.bat index f9ce949e613f0..2d981b1168899 100644 --- a/tools/webidl_binder.bat +++ b/tools/webidl_binder.bat @@ -5,10 +5,56 @@ :: To make modifications to this file, edit `tools/run_python.bat` and then run :: `tools/create_entry_points.py` +:: All env. vars specified in this file are to be local only to this script. @setlocal + @set EM_PY=%EMSDK_PYTHON% @if "%EM_PY%"=="" ( set EM_PY=python ) +:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a +:: shared stdin handle from the parent process, and that parent process stdin handle is in +:: a certain state, running python.exe might hang here. To work around this, if +:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid +:: sharing the parent's stdin handle to it, avoiding the hang. + +:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, +:: even when the python executable above did succeed and quit with errorlevel 0 above. +:: On Windows 8 and newer, this issue has not been observed. It is possible that this +:: issue is related to the above python bug, but this has not been conclusively confirmed, +:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known +:: workaround this issue, which is to explicitly quit the calling process with the previous +:: errorlevel from the above command. + +:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from +:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that +:: would throw off the parsing of the cmdline arg. +@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto NORMAL + ) else ( + goto NORMAL_EXIT + ) +) else ( + @if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( + goto MUTE_STDIN + ) else ( + goto MUTE_STDIN_EXIT + ) +) + +:NORMAL_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* +@exit %ERRORLEVEL% + +:MUTE_STDIN +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit /b %ERRORLEVEL% + +:MUTE_STDIN_EXIT +@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL +@exit %ERRORLEVEL% + +:NORMAL @"%EM_PY%" "%~dp0\%~n0.py" %*