From fdc8bc20e453c928e0c2c4f4fb64c8003fcc0647 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Fri, 25 Aug 2017 17:12:07 -0700 Subject: Scope environment variable setting The product and test build scripts invoke Visual Studio environment setting scripts several times during the build process. If doing a full cross architecture build including test build, it's as many as five times. These environment changes are cumulative. For the PATH variable, in particular, they can lead to a failure by exceeding the variable length limit. This seems to have been exacerbated by VS2017, which has very long paths, and for which many things are added to the PATH. Fix this by adding "setlocal" / "endlocal" around various sections of the scripts, so that the multiple calls to the environment script are not cumulative. (There is still some cumulative environment setting, as build.cmd calls VsDevCmd.bat, then if tests are being built, calls build-test.cmd, which also calls VsDevCmd.bat, and then possibly in addition calls vcvarsall.bat.) In addition, I simplified the code that sets up the msbuild logging parameters, so it is more readable, regular, and doesn't have so much repeated text. --- build-test.cmd | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'build-test.cmd') diff --git a/build-test.cmd b/build-test.cmd index df7df4452f..9b8f64b049 100644 --- a/build-test.cmd +++ b/build-test.cmd @@ -105,6 +105,7 @@ if defined __BuildAgainstPackagesArg ( echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat" call "%__VSToolsRoot%\VsDevCmd.bat" +@if defined _echo @echo on set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch% @@ -147,6 +148,7 @@ REM === Restore Build Tools REM === REM ========================================================================================= call "%__ProjectDir%\init-tools.cmd" +@if defined _echo @echo on REM ========================================================================================= REM === @@ -155,6 +157,7 @@ REM === REM ========================================================================================= call "%__TestDir%\setup-stress-dependencies.cmd" /arch %__BuildArch% /outputdir %__BinDir% +@if defined _echo @echo on REM ========================================================================================= REM === @@ -219,14 +222,6 @@ if errorlevel 1 ( :skipnative -set __BuildLogRootName=Restore_Product -set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log -set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn -set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err -set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%" -set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%" -set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%" - set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%" if not defined __BuildAgainstPackagesArg goto SkipRestoreProduct @@ -239,9 +234,23 @@ REM ============================================================================ if not defined XunitTestBinBase set XunitTestBinBase=%__TestWorkingDir% set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root" +set __BuildLogRootName=Restore_Product +set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log +set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn +set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err +set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%" +set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%" +set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%" + call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -BatchRestorePackages -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs% set __BuildLogRootName=Tests_GenerateRuntimeLayout +set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log +set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn +set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err +set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%" +set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%" +set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%" call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct -RuntimeId="%__RuntimeId%" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs% if errorlevel 1 ( @@ -255,14 +264,6 @@ echo %__MsgPrefix% Restored CoreCLR product from packages if defined __SkipManaged exit /b 0 -set __BuildLogRootName=Tests_Managed -set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log -set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn -set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err -set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%" -set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%" -set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%" - REM ========================================================================================= REM === REM === Managed test build section @@ -272,10 +273,18 @@ REM ============================================================================ echo %__MsgPrefix%Starting the Managed Tests Build if not defined VSINSTALLDIR ( - echo %__MsgPrefix%Error: buildtest.cmd should be run from a Visual Studio Command Prompt. Please see https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md for build instructions. + echo %__MsgPrefix%Error: build-test.cmd should be run from a Visual Studio Command Prompt. Please see https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md for build instructions. exit /b 1 ) +set __BuildLogRootName=Tests_Managed +set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log +set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn +set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err +set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%" +set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%" +set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%" + call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs% if errorlevel 1 ( echo %__MsgPrefix%Error: build failed. Refer to the build log files for details: -- cgit v1.2.3