Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49905 - trunk/tools/jam/src
From: grafikrobot_at_[hidden]
Date: 2008-11-23 21:03:53


Author: grafik
Date: 2008-11-23 21:03:53 EST (Sun, 23 Nov 2008)
New Revision: 49905
URL: http://svn.boost.org/trac/boost/changeset/49905

Log:
Rework how arguments are parsed and tested to fix handling of quoted arguments, options arguments, and arguments with "=". (fixes #2113)
Text files modified:
   trunk/tools/jam/src/build.bat | 196 ++++++++++++++++++++++++---------------
   1 files changed, 118 insertions(+), 78 deletions(-)

Modified: trunk/tools/jam/src/build.bat
==============================================================================
--- trunk/tools/jam/src/build.bat (original)
+++ trunk/tools/jam/src/build.bat 2008-11-23 21:03:53 EST (Sun, 23 Nov 2008)
@@ -7,8 +7,15 @@
 setlocal
 goto Start
 
-REM NOTE: The "setlocal & endlocal & ver>NUL" construct is used to reset the errorlevel to 0.
-REM NOTE: The "move >NUL 2>&1" construct is used to set the errorlevel to 1
+
+:Set_Error
+color 00
+goto :eof
+
+
+:Clear_Error
+ver >nul
+goto :eof
 
 
 :Error_Print
@@ -23,7 +30,7 @@
 ECHO ### Toolsets supported by this script are: borland, como, gcc, gcc-nocygwin,
 ECHO ### intel-win32, metrowerks, mingw, msvc, vc7, vc8, vc9
 ECHO ###
-move >NUL 2>&1
+call :Set_Error
 endlocal
 goto :eof
 
@@ -32,7 +39,7 @@
 REM Tests for the given file(executable) presence in the directories in the PATH
 REM environment variable. Additionaly sets FOUND_PATH to the path of the
 REM found file.
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 setlocal
 set test=%~$PATH:1
 endlocal
@@ -42,14 +49,38 @@
 
 :Test_Option
 REM Tests whether the given string is in the form of an option: "--*"
-setlocal & endlocal & ver>NUL
+call :Clear_Error
+setlocal
+set test=%1
+if not defined test (
+ call :Set_Error
+ goto Test_Option_End
+)
+set test=###%test%###
+set test=%test:"###=%
+set test=%test:###"=%
+set test=%test:###=%
+if not "-" == "%test:~1,1%" call :Set_Error
+:Test_Option_End
+endlocal
+goto :eof
+
+
+:Test_Empty
+REM Tests whether the given string is not empty
+call :Clear_Error
 setlocal
 set test=%1
+if not defined test (
+ call :Clear_Error
+ goto Test_Empty_End
+)
 set test=###%test%###
 set test=%test:"###=%
 set test=%test:###"=%
 set test=%test:###=%
-if not [-] == [%test:~1,1%] move >NUL 2>&1
+if not "" == "%test%" call :Set_Error
+:Test_Empty_End
 endlocal
 goto :eof
 
@@ -65,132 +96,134 @@
 REM May also set BOOST_JAM_TOOLSET_ROOT to the
 REM location of the found toolset.
 
-if "_%ProgramFiles%_" == "__" set ProgramFiles=C:\Program Files
+call :Clear_Error
+call :Test_Empty %ProgramFiles%
+if not errorlevel 1 set ProgramFiles=C:\Program Files
 
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if NOT "_%VS90COMNTOOLS%_" == "__" (
     set "BOOST_JAM_TOOLSET=vc9"
     set "BOOST_JAM_TOOLSET_ROOT=%VS90COMNTOOLS%..\..\VC\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "%ProgramFiles%\Microsoft Visual Studio 9.0\VC\VCVARSALL.BAT" (
     set "BOOST_JAM_TOOLSET=vc9"
     set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio 9.0\VC\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if NOT "_%VS80COMNTOOLS%_" == "__" (
     set "BOOST_JAM_TOOLSET=vc8"
     set "BOOST_JAM_TOOLSET_ROOT=%VS80COMNTOOLS%..\..\VC\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "%ProgramFiles%\Microsoft Visual Studio 8\VC\VCVARSALL.BAT" (
     set "BOOST_JAM_TOOLSET=vc8"
     set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio 8\VC\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if NOT "_%VS71COMNTOOLS%_" == "__" (
     set "BOOST_JAM_TOOLSET=vc7"
     set "BOOST_JAM_TOOLSET_ROOT=%VS71COMNTOOLS%\..\..\VC7\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if NOT "_%VCINSTALLDIR%_" == "__" (
     REM %VCINSTALLDIR% is also set for VC9 (and probably VC8)
     set "BOOST_JAM_TOOLSET=vc7"
     set "BOOST_JAM_TOOLSET_ROOT=%VCINSTALLDIR%\VC7\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "%ProgramFiles%\Microsoft Visual Studio .NET 2003\VC7\bin\VCVARS32.BAT" (
     set "BOOST_JAM_TOOLSET=vc7"
     set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio .NET 2003\VC7\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "%ProgramFiles%\Microsoft Visual Studio .NET\VC7\bin\VCVARS32.BAT" (
     set "BOOST_JAM_TOOLSET=vc7"
     set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio .NET\VC7\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if NOT "_%MSVCDir%_" == "__" (
     set "BOOST_JAM_TOOLSET=msvc"
     set "BOOST_JAM_TOOLSET_ROOT=%MSVCDir%\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "%ProgramFiles%\Microsoft Visual Studio\VC98\bin\VCVARS32.BAT" (
     set "BOOST_JAM_TOOLSET=msvc"
     set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio\VC98\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "%ProgramFiles%\Microsoft Visual C++\VC98\bin\VCVARS32.BAT" (
     set "BOOST_JAM_TOOLSET=msvc"
     set "BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual C++\VC98\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Test_Path cl.exe
 if not errorlevel 1 (
     set "BOOST_JAM_TOOLSET=msvc"
     set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Test_Path vcvars32.bat
 if not errorlevel 1 (
     set "BOOST_JAM_TOOLSET=msvc"
     call "%FOUND_PATH%VCVARS32.BAT"
     set "BOOST_JAM_TOOLSET_ROOT=%MSVCDir%\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "C:\Borland\BCC55\Bin\bcc32.exe" (
     set "BOOST_JAM_TOOLSET=borland"
     set "BOOST_JAM_TOOLSET_ROOT=C:\Borland\BCC55\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Test_Path bcc32.exe
 if not errorlevel 1 (
     set "BOOST_JAM_TOOLSET=borland"
     set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Test_Path icl.exe
 if not errorlevel 1 (
     set "BOOST_JAM_TOOLSET=intel-win32"
     set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "C:\MinGW\bin\gcc.exe" (
     set "BOOST_JAM_TOOLSET=mingw"
     set "BOOST_JAM_TOOLSET_ROOT=C:\MinGW\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if NOT "_%CWFolder%_" == "__" (
     set "BOOST_JAM_TOOLSET=metrowerks"
     set "BOOST_JAM_TOOLSET_ROOT=%CWFolder%\"
     goto :eof )
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Test_Path mwcc.exe
 if not errorlevel 1 (
     set "BOOST_JAM_TOOLSET=metrowerks"
     set "BOOST_JAM_TOOLSET_ROOT=%FOUND_PATH%..\..\"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Error_Print "Could not find a suitable toolset."
 goto :eof
 
 
 :Guess_Yacc
 REM Tries to find bison or yacc in common places so we can build the grammar.
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Test_Path yacc.exe
 if not errorlevel 1 (
     set "YACC=yacc -d"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Test_Path bison.exe
 if not errorlevel 1 (
     set "YACC=bison -d --yacc"
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if EXIST "C:\Program Files\GnuWin32\bin\bison.exe" (
     set "YACC=C:\Program Files\GnuWin32\bin\bison.exe" -d --yacc
     goto :eof)
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 call :Error_Print "Could not find Yacc to build the Jam grammar."
 goto :eof
 
@@ -202,22 +235,24 @@
 REM If no arguments guess the toolset;
 REM or if first argument is an option guess the toolset;
 REM otherwise the argument is the toolset to use.
-if "_%1_" == "__" (
+call :Clear_Error
+call :Test_Empty %1
+if not errorlevel 1 (
     call :Guess_Toolset
- if not errorlevel 1 goto Setup_Toolset
-) else (
- call :Test_Option "%1"
- if not errorlevel 1 (
- call :Guess_Toolset
- if not errorlevel 1 goto Setup_Toolset
- ) else (
- setlocal & endlocal & ver>NUL
- set "BOOST_JAM_TOOLSET=%1"
- shift
- goto Setup_Toolset
- )
+ if not errorlevel 1 ( goto Setup_Toolset ) else ( goto Finish )
+)
+
+call :Clear_Error
+call :Test_Option %1
+if not errorlevel 1 (
+ call :Guess_Toolset
+ if not errorlevel 1 ( goto Setup_Toolset ) else ( goto Finish )
 )
-if errorlevel 1 goto Finish
+
+call :Clear_Error
+set BOOST_JAM_TOOLSET=%1
+shift
+goto Setup_Toolset
 
 
 :Setup_Toolset
@@ -230,15 +265,18 @@
 REM command. A complete "if ... ( commands ) else ( commands )"
 REM is a single command, even though it's in multiple lines here.
 :Setup_Args
-if "_%1_" == "__" goto Config_Toolset
-call :Test_Option "%1"
+call :Clear_Error
+call :Test_Empty %1
+if not errorlevel 1 goto Config_Toolset
+call :Clear_Error
+call :Test_Option %1
 if errorlevel 1 (
     set BOOST_JAM_ARGS=%BOOST_JAM_ARGS% %1
     shift
     goto Setup_Args
 )
 :Config_Toolset
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_metrowerks_" goto :Skip_METROWERKS
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_metrowerks_" goto Skip_METROWERKS
 if NOT "_%CWFolder%_" == "__" (
     set "BOOST_JAM_TOOLSET_ROOT=%CWFolder%\"
     )
@@ -249,7 +287,7 @@
 set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"
 set "_known_=1"
 :Skip_METROWERKS
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_msvc_" goto :Skip_MSVC
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_msvc_" goto Skip_MSVC
 if NOT "_%MSVCDir%_" == "__" (
     set "BOOST_JAM_TOOLSET_ROOT=%MSVCDir%\"
     )
@@ -263,7 +301,7 @@
 set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"
 set "_known_=1"
 :Skip_MSVC
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc7_" goto :Skip_VC7
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc7_" goto Skip_VC7
 if NOT "_%VS71COMNTOOLS%_" == "__" (
     set "BOOST_JAM_TOOLSET_ROOT=%VS71COMNTOOLS%..\..\VC7\"
     )
@@ -278,7 +316,7 @@
 set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"
 set "_known_=1"
 :Skip_VC7
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc8_" goto :Skip_VC8
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc8_" goto Skip_VC8
 if NOT "_%VS80COMNTOOLS%_" == "__" (
     set "BOOST_JAM_TOOLSET_ROOT=%VS80COMNTOOLS%..\..\VC\"
     )
@@ -293,7 +331,7 @@
 set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"
 set "_known_=1"
 :Skip_VC8
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc9_" goto :Skip_VC9
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc9_" goto Skip_VC9
 if NOT "_%VS90COMNTOOLS%_" == "__" (
     set "BOOST_JAM_TOOLSET_ROOT=%VS90COMNTOOLS%..\..\VC\"
     )
@@ -308,7 +346,7 @@
 set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"
 set "_known_=1"
 :Skip_VC9
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_borland_" goto :Skip_BORLAND
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_borland_" goto Skip_BORLAND
 if "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" (
     call :Test_Path bcc32.exe )
 if "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" (
@@ -324,35 +362,35 @@
 set "BOOST_JAM_OPT_YYACC=-eyyacc0"
 set "_known_=1"
 :Skip_BORLAND
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_como_" goto :Skip_COMO
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_como_" goto Skip_COMO
 set "BOOST_JAM_CC=como -DNT"
 set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"
 set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"
 set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"
 set "_known_=1"
 :Skip_COMO
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_gcc_" goto :Skip_GCC
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_gcc_" goto Skip_GCC
 set "BOOST_JAM_CC=gcc -DNT"
 set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"
 set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"
 set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"
 set "_known_=1"
 :Skip_GCC
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_gcc-nocygwin_" goto :Skip_GCC_NOCYGWIN
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_gcc-nocygwin_" goto Skip_GCC_NOCYGWIN
 set "BOOST_JAM_CC=gcc -DNT -mno-cygwin"
 set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"
 set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"
 set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"
 set "_known_=1"
 :Skip_GCC_NOCYGWIN
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_intel-win32_" goto :Skip_INTEL_WIN32
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_intel-win32_" goto Skip_INTEL_WIN32
 set "BOOST_JAM_CC=icl -DNT /nologo kernel32.lib advapi32.lib user32.lib"
 set "BOOST_JAM_OPT_JAM=/Febootstrap\jam0"
 set "BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0"
 set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0"
 set "_known_=1"
 :Skip_INTEL_WIN32
-if NOT "_%BOOST_JAM_TOOLSET%_" == "_mingw_" goto :Skip_MINGW
+if NOT "_%BOOST_JAM_TOOLSET%_" == "_mingw_" goto Skip_MINGW
 if not "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" (
     set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%"
     )
@@ -362,7 +400,7 @@
 set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"
 set "_known_=1"
 :Skip_MINGW
-setlocal & endlocal & ver>NUL
+call :Clear_Error
 if "_%_known_%_" == "__" (
     call :Error_Print "Unknown toolset: %BOOST_JAM_TOOLSET%"
 )
@@ -384,25 +422,27 @@
 set BJAM_SOURCES=%BJAM_SOURCES% modules/property-set.c modules/sequence.c modules/order.c
 
 set BJAM_UPDATE=
-if "_%1" == "_--update" (
- set BJAM_UPDATE=update
-)
-if "_%2" == "_--update" (
- set BJAM_UPDATE=update
-)
-if "_%3" == "_--update" (
- set BJAM_UPDATE=update
-)
-if "_%4" == "_--update" (
- set BJAM_UPDATE=update
-)
+:Check_Update
+call :Test_Empty %1
+if not errorlevel 1 goto Check_Update_End
+call :Clear_Error
+setlocal
+set test=%1
+set test=###%test%###
+set test=%test:"###=%
+set test=%test:###"=%
+set test=%test:###=%
+if "%test%" == "--update" set BJAM_UPDATE=update
+endlocal
+shift
+if not "_%BJAM_UPDATE%_" == "_update_" goto Check_Update
+:Check_Update_End
 if "_%BJAM_UPDATE%_" == "_update_" (
     if not exist ".\bootstrap\jam0.exe" (
         set BJAM_UPDATE=
     )
 )
 
-
 @echo ON
 @if "_%BJAM_UPDATE%_" == "_update_" goto Skip_Bootstrap
 rd /S /Q bootstrap
@@ -444,13 +484,13 @@
 @if "_%BJAM_UPDATE%_" == "_update_" goto Skip_Clean
 .\bootstrap\jam0 -f build.jam --toolset=%BOOST_JAM_TOOLSET% "--toolset-root=%BOOST_JAM_TOOLSET_ROOT% " clean
 :Skip_Clean
-_at_set args=
+@set args=%*
 :Set_Args
-_at_if not "_%1_" == "__" (
- set args=%args% %1
- shift
- goto Set_Args
-)
+@if [-] == [%args:~1,1%] goto Set_Args_End
+@if [^"-] == [%args:~1,2%] goto Set_Args_End
+@set args=%args:~2%
+@goto Set_Args
+:Set_Args_End
 .\bootstrap\jam0 -f build.jam --toolset=%BOOST_JAM_TOOLSET% "--toolset-root=%BOOST_JAM_TOOLSET_ROOT% " %args%
 :Skip_Jam
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk