Skip to content
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

sanitize python env and subprocess i/o #16736

Merged
merged 12 commits into from
Jun 13, 2022
6 changes: 5 additions & 1 deletion em++
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python_compiler.sh` and
# then run `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -29,7 +33,7 @@ if [ -z "$PYTHON" ]; then
fi

if [ -z "$_EMCC_CCACHE" ]; then
exec "$PYTHON" "$0.py" "$@"
exec "$PYTHON" -E "$0.py" "$@"
else
unset _EMCC_CCACHE
exec ccache "$0" "$@"
Expand Down
6 changes: 4 additions & 2 deletions em++.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

:: All env. vars specified in this file are to be local only to this script.
@setlocal

:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
:: of cpython used in cross compilation via setup.py.
@set _PYTHON_SYSCONFIGDATA_NAME=
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand All @@ -16,7 +18,7 @@
:: 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%"=="" (
set CMD="%EM_PY%" "%~dp0\%~n0.py"
set CMD="%EM_PY%" -E "%~dp0\%~n0.py"
) else (
set _EMCC_CCACHE=
set CMD=ccache "%~dp0\%~n0.bat"
Expand Down
6 changes: 5 additions & 1 deletion em-config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python.sh` and then run
# `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -28,4 +32,4 @@ if [ -z "$PYTHON" ]; then
exit 1
fi

exec "$PYTHON" "$0.py" "$@"
exec "$PYTHON" -E "$0.py" "$@"
12 changes: 7 additions & 5 deletions em-config.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

:: All env. vars specified in this file are to be local only to this script.
@setlocal

:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
:: of cpython used in cross compilation via setup.py.
@set _PYTHON_SYSCONFIGDATA_NAME=
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand Down Expand Up @@ -45,16 +47,16 @@
)

:NORMAL_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
@exit %ERRORLEVEL%

:MUTE_STDIN
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit /b %ERRORLEVEL%

:MUTE_STDIN_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit %ERRORLEVEL%

:NORMAL
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
6 changes: 5 additions & 1 deletion emar
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python.sh` and then run
# `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -28,4 +32,4 @@ if [ -z "$PYTHON" ]; then
exit 1
fi

exec "$PYTHON" "$0.py" "$@"
exec "$PYTHON" -E "$0.py" "$@"
12 changes: 7 additions & 5 deletions emar.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

:: All env. vars specified in this file are to be local only to this script.
@setlocal

:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
:: of cpython used in cross compilation via setup.py.
@set _PYTHON_SYSCONFIGDATA_NAME=
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand Down Expand Up @@ -45,16 +47,16 @@
)

:NORMAL_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
@exit %ERRORLEVEL%

:MUTE_STDIN
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit /b %ERRORLEVEL%

:MUTE_STDIN_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit %ERRORLEVEL%

:NORMAL
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
6 changes: 5 additions & 1 deletion embuilder
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python.sh` and then run
# `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -28,4 +32,4 @@ if [ -z "$PYTHON" ]; then
exit 1
fi

exec "$PYTHON" "$0.py" "$@"
exec "$PYTHON" -E "$0.py" "$@"
12 changes: 7 additions & 5 deletions embuilder.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

:: All env. vars specified in this file are to be local only to this script.
@setlocal

:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
:: of cpython used in cross compilation via setup.py.
@set _PYTHON_SYSCONFIGDATA_NAME=
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand Down Expand Up @@ -45,16 +47,16 @@
)

:NORMAL_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
@exit %ERRORLEVEL%

:MUTE_STDIN
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit /b %ERRORLEVEL%

:MUTE_STDIN_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit %ERRORLEVEL%

:NORMAL
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
6 changes: 5 additions & 1 deletion emcc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python_compiler.sh` and
# then run `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -29,7 +33,7 @@ if [ -z "$PYTHON" ]; then
fi

if [ -z "$_EMCC_CCACHE" ]; then
exec "$PYTHON" "$0.py" "$@"
exec "$PYTHON" -E "$0.py" "$@"
else
unset _EMCC_CCACHE
exec ccache "$0" "$@"
Expand Down
6 changes: 4 additions & 2 deletions emcc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

:: All env. vars specified in this file are to be local only to this script.
@setlocal

:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
:: of cpython used in cross compilation via setup.py.
@set _PYTHON_SYSCONFIGDATA_NAME=
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand All @@ -16,7 +18,7 @@
:: 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%"=="" (
set CMD="%EM_PY%" "%~dp0\%~n0.py"
set CMD="%EM_PY%" -E "%~dp0\%~n0.py"
) else (
set _EMCC_CCACHE=
set CMD=ccache "%~dp0\%~n0.bat"
Expand Down
2 changes: 1 addition & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ def run(args):
args = [x for x in args if x != '--cflags']
with misc_temp_files.get_file(suffix='.o') as temp_target:
input_file = 'hello_world.c'
cmd = [shared.PYTHON, sys.argv[0], utils.path_from_root('tests', input_file), '-v', '-c', '-o', temp_target] + args
cmd = [shared.PYTHON, "-E", sys.argv[0], utils.path_from_root('tests', input_file), '-v', '-c', '-o', temp_target] + args
proc = run_process(cmd, stderr=PIPE, check=False)
if proc.returncode != 0:
print(proc.stderr)
Expand Down
6 changes: 5 additions & 1 deletion emcmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python.sh` and then run
# `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -28,4 +32,4 @@ if [ -z "$PYTHON" ]; then
exit 1
fi

exec "$PYTHON" "$0.py" "$@"
exec "$PYTHON" -E "$0.py" "$@"
12 changes: 7 additions & 5 deletions emcmake.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

:: All env. vars specified in this file are to be local only to this script.
@setlocal

:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
:: of cpython used in cross compilation via setup.py.
@set _PYTHON_SYSCONFIGDATA_NAME=
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand Down Expand Up @@ -45,16 +47,16 @@
)

:NORMAL_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
@exit %ERRORLEVEL%

:MUTE_STDIN
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit /b %ERRORLEVEL%

:MUTE_STDIN_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit %ERRORLEVEL%

:NORMAL
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
6 changes: 5 additions & 1 deletion emconfigure
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python.sh` and then run
# `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -28,4 +32,4 @@ if [ -z "$PYTHON" ]; then
exit 1
fi

exec "$PYTHON" "$0.py" "$@"
exec "$PYTHON" -E "$0.py" "$@"
pmp-p marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 7 additions & 5 deletions emconfigure.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

:: All env. vars specified in this file are to be local only to this script.
@setlocal

:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
:: of cpython used in cross compilation via setup.py.
@set _PYTHON_SYSCONFIGDATA_NAME=
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand Down Expand Up @@ -45,16 +47,16 @@
)

:NORMAL_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
@exit %ERRORLEVEL%

:MUTE_STDIN
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit /b %ERRORLEVEL%

:MUTE_STDIN_EXIT
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
@"%EM_PY%" -E "%~dp0\%~n0.py" %* < NUL
@exit %ERRORLEVEL%

:NORMAL
@"%EM_PY%" "%~dp0\%~n0.py" %*
@"%EM_PY%" -E "%~dp0\%~n0.py" %*
6 changes: 5 additions & 1 deletion emdump
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python.sh` and then run
# `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -28,4 +32,4 @@ if [ -z "$PYTHON" ]; then
exit 1
fi

exec "$PYTHON" "$(dirname $0)/tools/emdump.py" "$@"
exec "$PYTHON" -E "$(dirname $0)/tools/emdump.py" "$@"
12 changes: 7 additions & 5 deletions emdump.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

:: All env. vars specified in this file are to be local only to this script.
@setlocal

:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
:: of cpython used in cross compilation via setup.py.
@set _PYTHON_SYSCONFIGDATA_NAME=
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand Down Expand Up @@ -45,16 +47,16 @@
)

:NORMAL_EXIT
@"%EM_PY%" "%~dp0\tools\emdump.py" %*
@"%EM_PY%" -E "%~dp0\tools\emdump.py" %*
@exit %ERRORLEVEL%

:MUTE_STDIN
@"%EM_PY%" "%~dp0\tools\emdump.py" %* < NUL
@"%EM_PY%" -E "%~dp0\tools\emdump.py" %* < NUL
@exit /b %ERRORLEVEL%

:MUTE_STDIN_EXIT
@"%EM_PY%" "%~dp0\tools\emdump.py" %* < NUL
@"%EM_PY%" -E "%~dp0\tools\emdump.py" %* < NUL
@exit %ERRORLEVEL%

:NORMAL
@"%EM_PY%" "%~dp0\tools\emdump.py" %*
@"%EM_PY%" -E "%~dp0\tools\emdump.py" %*
6 changes: 5 additions & 1 deletion emdwp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# To make modifications to this file, edit `tools/run_python.sh` and then run
# `tools/create_entry_points.py`

# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal
# of cpython used in cross compilation via setup.py.
unset _PYTHON_SYSCONFIGDATA_NAME

if [ -z "$PYTHON" ]; then
PYTHON=$EMSDK_PYTHON
fi
Expand All @@ -28,4 +32,4 @@ if [ -z "$PYTHON" ]; then
exit 1
fi

exec "$PYTHON" "$(dirname $0)/tools/emdwp.py" "$@"
exec "$PYTHON" -E "$(dirname $0)/tools/emdwp.py" "$@"
Loading