Skip to content

Commit

Permalink
Fix exit codes in build/test scripts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mmitche committed May 20, 2015
1 parent b8493d6 commit 85eac4c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 44 deletions.
20 changes: 10 additions & 10 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -153,15 +153,15 @@ 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
set "__CoreCLRBuildLog=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
%_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
Expand All @@ -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%
Expand All @@ -200,7 +200,7 @@ IF NOT ERRORLEVEL 1 (
)

echo CrossGen mscorlib failed. Refer !__CrossGenMScorlibLog! for details.
goto :eof
exit /b 1

:PerformTestBuild
echo.
Expand All @@ -209,15 +209,15 @@ 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
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.
Expand Down
19 changes: 7 additions & 12 deletions tests/buildtest.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
35 changes: 13 additions & 22 deletions tests/runtest.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=
Expand All @@ -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.
Expand Down

0 comments on commit 85eac4c

Please sign in to comment.