Skip to content

Commit

Permalink
Correctly fix windows parentheses mix-up (emscripten-core#13723)
Browse files Browse the repository at this point in the history
This issue was attempted to fix in emscripten-core#13698 by escaping `)` but it turned
out to be an incomplete fix, because it fixed the breaking tests then
but broke other ones instead depending on their syntax. This PR tries to
fix it correctly by using `enabledelayedexpansion` feature of batch
files. We can enable delayed expansion of variables within a batch file
by
```
@SETLOCAL enabledelayedexpansion
```
And if you use variables not by the usual syntax `%VAR%` but `!VAR!`, it
is expanded in a delayed manner, after all parentheses for `if`s and
`else`s are expanded.
  • Loading branch information
aheejin authored Mar 22, 2021
1 parent 7cecaba commit 533d712
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions em++.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:: To modify this file, edit `tools/run_python_compiler.bat` and then run
:: `tools/create_entry_points.py`

@setlocal
@setlocal enabledelayedexpansion
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand All @@ -11,9 +11,9 @@
@set ARGS=%*
@if "%_EMCC_CCACHE%"=="" (
:: Do regular invocation of em++.py compiler
"%EM_PY%" "%~dp0\%~n0.py" %ARGS:)=^)%
"%EM_PY%" "%~dp0\%~n0.py" !ARGS!
) else (
:: Remove the ccache env. var, invoke ccache and re-enter this script to take the above branch.
set _EMCC_CCACHE=
ccache "%~dp0\%~n0.bat" %ARGS:)=^)%
ccache "%~dp0\%~n0.bat" !ARGS!
)
6 changes: 3 additions & 3 deletions emcc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:: To modify this file, edit `tools/run_python_compiler.bat` and then run
:: `tools/create_entry_points.py`

@setlocal
@setlocal enabledelayedexpansion
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand All @@ -11,9 +11,9 @@
@set ARGS=%*
@if "%_EMCC_CCACHE%"=="" (
:: Do regular invocation of em++.py compiler
"%EM_PY%" "%~dp0\%~n0.py" %ARGS:)=^)%
"%EM_PY%" "%~dp0\%~n0.py" !ARGS!
) else (
:: Remove the ccache env. var, invoke ccache and re-enter this script to take the above branch.
set _EMCC_CCACHE=
ccache "%~dp0\%~n0.bat" %ARGS:)=^)%
ccache "%~dp0\%~n0.bat" !ARGS!
)
6 changes: 3 additions & 3 deletions tools/run_python_compiler.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:: To modify this file, edit `tools/run_python_compiler.bat` and then run
:: `tools/create_entry_points.py`

@setlocal
@setlocal enabledelayedexpansion
@set EM_PY=%EMSDK_PYTHON%
@if "%EM_PY%"=="" (
set EM_PY=python
Expand All @@ -11,9 +11,9 @@
@set ARGS=%*
@if "%_EMCC_CCACHE%"=="" (
:: Do regular invocation of em++.py compiler
"%EM_PY%" "%~dp0\%~n0.py" %ARGS:)=^)%
"%EM_PY%" "%~dp0\%~n0.py" !ARGS!
) else (
:: Remove the ccache env. var, invoke ccache and re-enter this script to take the above branch.
set _EMCC_CCACHE=
ccache "%~dp0\%~n0.bat" %ARGS:)=^)%
ccache "%~dp0\%~n0.bat" !ARGS!
)

0 comments on commit 533d712

Please sign in to comment.