Fix exit codes in build/test scripts
authorMatt Mitchell <mmitche@microsoft.com>
Wed, 20 May 2015 22:38:31 +0000 (15:38 -0700)
committerMatt Mitchell <mmitche@microsoft.com>
Wed, 20 May 2015 22:38:31 +0000 (15:38 -0700)
The use of goto :eof in numerous places in the build and test scripts is problematic.  If preceded by an echo or other command, it will overwrite the exit code and the script may return incorrectly.  This was happening for buildtest, masking a recent ycompilation error in one of the tests.

Change all of the goto :eof's to exit /b.

build.cmd
tests/buildtest.cmd
tests/runtest.cmd

index 21ec501..643ecd4 100644 (file)
--- a/build.cmd
+++ b/build.cmd
@@ -96,14 +96,14 @@ goto CheckVS
 if defined VS%__VSProductVersion%COMNTOOLS goto CheckVSExistence
 echo Visual Studio 2013 Community (free) is a pre-requisite to build this repository.
 echo See: https://github.com/dotnet/coreclr/wiki/Developer-Guide#prerequisites
-goto :eof
+exit /b 1
 
 :CheckVSExistence
 :: Does VS 2013 or VS 2015 really exist?
 if exist "!VS%__VSProductVersion%COMNTOOLS!\..\IDE\devenv.exe" goto CheckMSBuild
 echo Visual Studio 2013 Community (free) is a pre-requisite to build this repository.
 echo See: https://github.com/dotnet/coreclr/wiki/Developer-Guide#prerequisites
-goto :eof
+exit /b 1
 
 :CheckMSBuild
 :: Note: We've disabled node reuse because it causes file locking issues.
@@ -142,7 +142,7 @@ of previous version to "%VSINSTALLDIR%" and then resume build.
 echo Visual Studio 2013 Express does not include the DIA SDK. ^
 You need Visual Studio 2013 Community (free).
 echo See: https://github.com/dotnet/coreclr/wiki/Developer-Guide#prerequisites
-goto :eof
+exit /b 1
 
 :GenVSSolution
 :: Regenerate the VS solution
@@ -153,7 +153,7 @@ popd
 :BuildComponents
 if exist "%__IntermediatesDir%\install.vcxproj" goto BuildCoreCLR
 echo Failed to generate native component build project!
-goto :eof
+exit /b 1
 
 REM Build CoreCLR
 :BuildCoreCLR
@@ -161,7 +161,7 @@ set "__CoreCLRBuildLog=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildT
 %_msbuildexe% "%__IntermediatesDir%\install.vcxproj" %__MSBCleanBuildArgs% /nologo /maxcpucount /nodeReuse:false /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% /fileloggerparameters:Verbosity=diag;LogFile="%__CoreCLRBuildLog%"
 IF NOT ERRORLEVEL 1 goto PerformMScorlibBuild
 echo Native component build failed. Refer !__CoreCLRBuildLog! for details.
-goto :eof
+exit /b 1
 
 :PerformMScorlibBuild
 REM endlocal to rid us of environment changes from vcvarsall.bat
@@ -183,12 +183,12 @@ echo.
 set "__MScorlibBuildLog=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
 %_msbuildexe% "%__ProjectFilesDir%\build.proj" %__MSBCleanBuildArgs% /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__MScorlibBuildLog%" /p:OS=%__BuildOS% %__AdditionalMSBuildArgs%
 IF NOT ERRORLEVEL 1 (
-  if defined __MscorlibOnly goto :eof
+  if defined __MscorlibOnly exit /b 0
   goto CrossGenMscorlib
 )
 
 echo MScorlib build failed. Refer !__MScorlibBuildLog! for details.
-goto :eof
+exit /b 1
 
 :CrossGenMscorlib
 echo Generating native image of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType%
@@ -200,7 +200,7 @@ IF NOT ERRORLEVEL 1 (
 )
 
 echo CrossGen mscorlib failed. Refer !__CrossGenMScorlibLog! for details.
-goto :eof
+exit /b 1
 
 :PerformTestBuild
 echo.
@@ -209,7 +209,7 @@ echo.
 call tests\buildtest.cmd
 IF NOT ERRORLEVEL 1 goto SuccessfulBuild
 echo Test binaries build failed. Refer !__MScorlibBuildLog! for details.
-goto :eof
+exit /b 1
 
 :SuccessfulBuild
 ::Build complete
@@ -217,7 +217,7 @@ echo Repo successfully built.
 echo.
 echo Product binaries are available at !__BinDir!
 echo Test binaries are available at !__TestBinDir!
-goto :eof
+exit /b 0
 
 :Usage
 echo.
index bcb0959..7a13474 100644 (file)
@@ -82,13 +82,13 @@ for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "&
 :: Check presence of VS
 if defined VS%__VSProductVersion%COMNTOOLS goto CheckVSExistence
 echo Installation of VS 2013 is a pre-requisite to build this repository.
-goto :eof
+exit /b 1
 
 :CheckVSExistence
 :: Does VS 2013 or VS 2015 really exist?
 if exist "!VS%__VSProductVersion%COMNTOOLS!\..\IDE\devenv.exe" goto CheckMSBuild
 echo Installation of VS 2013 is a pre-requisite to build this repository.
-goto :eof
+exit /b 1
 
 :CheckMSBuild
 if /i "%__VSVersion%" =="vs2015" goto MSBuild14
@@ -113,7 +113,7 @@ echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
 This is due to bug in VS Intaller. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
 at VS install location of previous version. Workaround is to copy DIA SDK folder from VS install location ^
 of previous version to "%VSINSTALLDIR%" and then resume build.
-goto :eof
+exit /b 1
 
 :GenVSSolution
 :: Regenerate the VS solution
@@ -124,14 +124,14 @@ popd
 :BuildComponents
 if exist "%__NativeTestIntermediatesDir%\install.vcxproj" goto BuildTestNativeComponents
 echo Failed to generate test native component build project!
-goto :eof
+exit /b 1
 
 REM Build CoreCLR
 :BuildTestNativeComponents
 %_msbuildexe% "%__NativeTestIntermediatesDir%\install.vcxproj" %__MSBCleanBuildArgs% /nologo /maxcpucount /nodeReuse:false /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% /fileloggerparameters:Verbosity=diag;LogFile="%__TestNativeBuildLog%"
 IF NOT ERRORLEVEL 1 goto PerformManagedTestBuild
 echo Native component build failed. Refer !__TestNativeBuildLog! for details.
-goto :eof
+exit /b 1
 
 :PerformManagedTestBuild
 REM endlocal to rid us of environment changes from vcvarsall.bat
@@ -161,19 +161,14 @@ set _buildprefix=
 set _buildpostfix=
 set _buildappend=
 call :build %1
-
-goto :eof
+exit /b %ERRORLEVEL%
 
 :build
 
 %_buildprefix% %_msbuildexe% "%__ProjectFilesDir%\build.proj" %__MSBCleanBuildArgs% /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__TestManagedBuildLog%";Append %* %_buildpostfix%
 IF ERRORLEVEL 1 echo Test build failed. Refer !__TestManagedBuildLog! for details && exit /b 1
+exit /b 0
 
-endlocal
-
-
-
-goto :eof
 :Usage
 echo.
 echo Usage:
index 1ed602b..fd2c611 100644 (file)
@@ -29,7 +29,7 @@ shift
 :: Check presence of VS
 if defined VS%__VSProductVersion%COMNTOOLS goto CheckMSbuild
 echo Installation of VS 2013 is a pre-requisite to build this repository.
-goto :eof
+exit /b 1
 
 :CheckMSBuild
 if /i "%__VSVersion%" =="vs2015" goto MSBuild14
@@ -95,26 +95,16 @@ set _buildprefix=
 set _buildpostfix=
 set _buildappend=
 call :PerformXunitWrapperBuild 
+IF ERRORLEVEL 1 (
+    echo XunitWrapperBuild build failed. Refer %__XunitWrapperBuildLog% for details.
+    exit /b 1
+)
 
-IF %BUILDERRORLEVEL% NEQ 0 echo XunitWrapperBuild build failed. Refer %__XunitWrapperBuildLog% for details. && exit /b %BUILDERRORLEVEL%
-
-call :preptests
-goto :eof
-
-:PerformXunitWrapperBuild
-
-%_buildprefix% %_msbuildexe% "%__ProjectFilesDir%runtest.proj" /p:NoRun=true /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__XunitWrapperBuildLog%";Append %1  %_buildappend%%_buildpostfix%
-
-set BUILDERRORLEVEL=%ERRORLEVEL%
-
-goto :eof
-
-:preptests
 :: Log build command line
 set _buildprefix=echo
 set _buildpostfix=^> "%__TestRunBuildLog%"
 set _buildappend=^>
-call :runtests 
+call :runtests
 
 :: Build
 set _buildprefix=
@@ -128,20 +118,21 @@ if exist %Core_Root% rd /s /q %Core_Root%
 md %Core_Root%
 xcopy /s %__BinDir% %Core_Root%
 call :runtests 
-
-IF %BUILDERRORLEVEL% NEQ 0 ( 
+if ERRORLEVEL 1 (
     echo Test Run failed. Refer to the following"
     echo Msbuild log: %__TestRunBuildLog%
     echo Html report: %__TestRunHtmlLog%
-    exit /b %BUILDERRORLEVEL%
+    exit /b 1
 )
-goto :eof
 
 :runtests
 %_buildprefix% %_msbuildexe% "%__ProjectFilesDir%runtest.proj" /p:NoBuild=true /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__TestRunBuildLog%";Append %1 %_buildpostfix%
+exit /b %ERRORLEVEL%
 
-set BUILDERRORLEVEL=%ERRORLEVEL%
-goto :eof
+:PerformXunitWrapperBuild
+
+%_buildprefix% %_msbuildexe% "%__ProjectFilesDir%runtest.proj" /p:NoRun=true /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__XunitWrapperBuildLog%";Append %1  %_buildappend%%_buildpostfix%
+exit /b %ERRORLEVEL%
 
 :Usage
 echo.