Skip to content

Commit

Permalink
run_scons: call scons from a bash script, for signals
Browse files Browse the repository at this point in the history
and so, to call scons, we have a bash wrapper, run_scons.sh, which
creates two wrappers, valeNsconsM.bat and valeNsconsM.sh, and calls
the .bat, which then calls the .sh with bash, which then calls scons
with python.

The .bat layer is needed because we need to set up the Visual Studio
environment through vcvarsall.bat, which only works from within a .bat
file. Then, the .sh layer is needed so that UNIX signals (e.g. CTRL+C)
can be caught while running scons (which would be impossible if run
directly from the .bat)

Enjoy!
  • Loading branch information
tahina-pro committed Sep 12, 2018
1 parent 7d731e0 commit 3fefeea
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions run_scons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ windows_scons_python_dir () {
echo "ERROR: Python $SCONS_PYTHON_MAJOR_MINOR was not installed properly" >&2
exit 1
fi
PYDIR=$(cygpath -u "$PYDIR")
echo "$PYDIR"
}

Expand Down Expand Up @@ -72,33 +73,46 @@ is_windows () {
if is_windows ; then
VS_ENV_CMD=$(windows_setup_environment)
pydir=$(windows_scons_python_dir)
pydir_w=$(cygpath -d "$pydir")

# Instead of invoking cmd.exe /c, which would force us to
# rely on its flaky semantics for double quotes,
# we go through a batch file.

# The problem is that, if we run scons directly from within the
# .bat file (or, even worse, call scons.bat), then it will not
# capture UNIX signals (CTRL+C, etc.) So we need to go "back to
# Cygwin": create a .sh file, and have the .bat file call bash
# with the .sh file, and have the .sh file call python with scons.py
# instead of calling scons.bat.

# This detour through a .bat file is necessary because of
# vcvarsall.bat, which is called to change the caller's
# environment, which only works from a .bat file, and not from a
# bash script or python script.

THIS_PID=$$
# Find an unambiguous file name for our .bat file
SCONS_EXECS=0
while
SCONS_INVOKE_FILE="vale$THIS_PID""scons$SCONS_EXECS"".bat" &&
[[ -e "$SCONS_INVOKE_FILE" ]]
SCONS_INVOKE_FILE_BASENAME="vale$THIS_PID""scons$SCONS_EXECS" && {
[[ -e "$SCONS_INVOKE_FILE_BASENAME.bat" ]] ||
[[ -e "$SCONS_INVOKE_FILE_BASENAME.sh" ]]
}
do
SCONS_EXECS=$(($SCONS_EXECS + 1))
done
# Then create, run and remove the .bat file
cat > "$SCONS_INVOKE_FILE" <<EOF
cat > "$SCONS_INVOKE_FILE_BASENAME.bat" <<EOF
call $VS_ENV_CMD
C:\cygwin64\bin\bash.exe $SCONS_INVOKE_FILE_BASENAME.sh
EOF
if command -v scons.bat > /dev/null 2>&1 ; then
echo "call scons.bat $cmd $parallel_opt" >> "$SCONS_INVOKE_FILE"
else
PYDIR=$(cygpath -d $(windows_scons_python_dir))
echo "$PYDIR/python.exe $PYDIR/Scripts/scons.py $*" >> "$SCONS_INVOKE_FILE"
fi
chmod +x "$SCONS_INVOKE_FILE"
"./$SCONS_INVOKE_FILE"
# TODO: convert arguments to scons to windows paths.
echo "$pydir/python.exe '$pydir_w\\Scripts\\scons.py' $*" > "$SCONS_INVOKE_FILE_BASENAME.sh"
chmod +x "$SCONS_INVOKE_FILE_BASENAME.bat"
"./$SCONS_INVOKE_FILE_BASENAME.bat"
SCONS_RETCODE=$?
rm -f "$SCONS_INVOKE_FILE"
rm -f "$SCONS_INVOKE_FILE_BASENAME.bat" "$SCONS_INVOKE_FILE_BASENAME.sh"
exit $SCONS_RETCODE
else
python$SCONS_PYTHON_MAJOR_MINOR $(which scons) "$@"
Expand Down

0 comments on commit 3fefeea

Please sign in to comment.