Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------
Expand Down
51 changes: 49 additions & 2 deletions em++.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the /b does this not exit the entire cmd.exe shell?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, though unfortunately with the /b flag that will not fix the Windows 7 issue. The /b flag is used in the other part to avoid a goto, which would reset the %errorlevel% variable to zero.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So users of EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG are opting into not being able to use these tools in a command shell, is that the idea? Maybe it would never make sense there?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry I should have read all of your above comments.. I see it mentions this there).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is the case - when one enables EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG, that will cause the shell to quit. For command line uses that would be quite undesirable, hence placing it under a separate workaround env. var.


:MUTE_STDIN
@%CMD% %* < NUL
@exit /b %ERRORLEVEL%

:MUTE_STDIN_EXIT
@%CMD% %* < NUL
@exit %ERRORLEVEL%

:NORMAL
@%CMD% %*
46 changes: 46 additions & 0 deletions em-config.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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" %*
46 changes: 46 additions & 0 deletions emar.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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" %*
46 changes: 46 additions & 0 deletions embuilder.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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" %*
51 changes: 49 additions & 2 deletions emcc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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% %*
46 changes: 46 additions & 0 deletions emcmake.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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" %*
Loading