Update CoreClr, CoreFx, IbcData, PgoData to preview-27112-01, preview.18562.1, master...
[platform/upstream/coreclr.git] / build-test.cmd
index b278996..790b75f 100644 (file)
@@ -1,33 +1,33 @@
 @if not defined _echo @echo off
-setlocal EnableDelayedExpansion
-
-:: Set the default arguments for build
-set __BuildArch=x64
-set __VCBuildArch=x86_amd64
-set __BuildType=Debug
-set __BuildOS=Windows_NT
-
-set "__ProjectDir=%~dp0"
+setlocal EnableDelayedExpansion EnableExtensions
 
 :: Define a prefix for most output progress messages that come from this script. That makes
 :: it easier to see where these are coming from. Note that there is a trailing space here.
 set "__MsgPrefix=BUILDTEST: "
 
-call "%__ProjectDir%"\setup_vs_tools.cmd
+echo %__MsgPrefix%Starting Build at %TIME%
 
-REM setup_vs_tools.cmd will correctly echo error message.
+set __ThisScriptDir="%~dp0"
+
+call "%__ThisScriptDir%"\setup_vs_tools.cmd
 if NOT '%ERRORLEVEL%' == '0' exit /b 1
 
 if defined VS150COMNTOOLS (
-  set "__VSToolsRoot=%VS150COMNTOOLS%"
-  set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
-  set __VSVersion=vs2017
+    set "__VSToolsRoot=%VS150COMNTOOLS%"
+    set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
+    set __VSVersion=vs2017
 ) else (
-  set "__VSToolsRoot=%VS140COMNTOOLS%"
-  set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC"
-  set __VSVersion=vs2015
+    set "__VSToolsRoot=%VS140COMNTOOLS%"
+    set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC"
+    set __VSVersion=vs2015
 )
 
+:: Set the default arguments for build
+set __BuildArch=x64
+set __BuildType=Debug
+set __BuildOS=Windows_NT
+
+set "__ProjectDir=%~dp0"
 :: remove trailing slash
 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
 set "__TestDir=%__ProjectDir%\tests"
@@ -40,11 +40,12 @@ set "__LogsDir=%__RootBinDir%\Logs"
 :: Default __Exclude to issues.targets
 set __Exclude=%__TestDir%\issues.targets
 
-REM __unprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
+REM __UnprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
 set "__args= %*"
 set processedArgs=
-set __unprocessedBuildArgs=
+set __UnprocessedBuildArgs=
 set __RunArgs=
+
 set __BuildAgainstPackagesArg=
 set __BuildAgainstPackagesMsbuildArg=
 set __SkipRestorePackages=
@@ -66,14 +67,18 @@ set __PassThroughArg=
 :Arg_Loop
 if "%1" == "" goto ArgsDone
 
-if /i "%1" == "-?"    goto Usage
-if /i "%1" == "-h"    goto Usage
-if /i "%1" == "-help" goto Usage
+if /i "%1" == "/?"     goto Usage
+if /i "%1" == "-?"     goto Usage
+if /i "%1" == "/h"     goto Usage
+if /i "%1" == "-h"     goto Usage
+if /i "%1" == "/help"  goto Usage
+if /i "%1" == "-help"  goto Usage
+if /i "%1" == "--help" goto Usage
 
-if /i "%1" == "x64"                   (set __BuildArch=x64&set __VCBuildArch=x86_amd64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
-if /i "%1" == "x86"                   (set __BuildArch=x86&set __VCBuildArch=x86&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
-if /i "%1" == "arm"                   (set __BuildArch=arm&set __VCBuildArch=x86_arm&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
-if /i "%1" == "arm64"                 (set __BuildArch=arm64&set __VCBuildArch=x86_arm64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
+if /i "%1" == "x64"                   (set __BuildArch=x64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
+if /i "%1" == "x86"                   (set __BuildArch=x86&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
+if /i "%1" == "arm"                   (set __BuildArch=arm&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
+if /i "%1" == "arm64"                 (set __BuildArch=arm64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
 
 if /i "%1" == "debug"                 (set __BuildType=Debug&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
 if /i "%1" == "release"               (set __BuildType=Release&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
@@ -93,12 +98,12 @@ if /i "%1" == "-priority"             (set __Priority=%2&shift&set processedArgs
 if /i "%1" == "--"                    (set __PassThroughArg=%1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
 
 if [!processedArgs!]==[] (
-  set __UnprocessedBuildArgs=%__args%
+    set __UnprocessedBuildArgs=%__args%
 ) else (
-  set __UnprocessedBuildArgs=%__args%
-  for %%t in (!processedArgs!) do (
-    set __UnprocessedBuildArgs=!__UnprocessedBuildArgs:*%%t=!
-  )
+    set __UnprocessedBuildArgs=%__args%
+    for %%t in (!processedArgs!) do (
+        set __UnprocessedBuildArgs=!__UnprocessedBuildArgs:*%%t=!
+    )
 )
 
 :ArgsDone
@@ -106,7 +111,7 @@ if [!processedArgs!]==[] (
 @REM Special handling for -priority=N argument.
 if %__Priority% GTR 0 (
     set "__PriorityArg=-priority=%__Priority%"
-    set "__PriorityMsbuildArg=/p:priority=%__Priority%"
+    set "__PriorityMsbuildArg=/p:CLRTestPriorityToBuild=%__Priority%"
 )
 
 if defined __BuildAgainstPackagesArg (
@@ -116,20 +121,31 @@ if defined __BuildAgainstPackagesArg (
     )
 )
 
+set TargetsWindowsArg=
+set TargetsWindowsMsbuildArg=
+if "%__TargetsWindows%"=="1" (
+    set TargetsWindowsArg=-TargetsWindows=true
+    set TargetsWindowsMsbuildArg=/p:TargetsWindows=true
+) else if "%__TargetsWindows%"=="0" (
+    set TargetsWindowsArg=-TargetsWindows=false
+    set TargetsWindowsMsbuildArg=/p:TargetsWindows=false
+)
+
 @if defined _echo @echo on
 
 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
 REM As we move from buildtools to arcade, __RunArgs should be replaced with __msbuildArgs
-set __msbuildArgs=/p:__BuildOS=%__BuildOS% /p:__BuildType=%__BuildType% /p:__BuildArch=%__BuildArch% /nologo /verbosity:minimal /clp:Summary
+set __msbuildArgs=/p:__BuildOS=%__BuildOS% /p:__BuildType=%__BuildType% /p:__BuildArch=%__BuildArch% /nologo /verbosity:minimal /clp:Summary /maxcpucount
 
-echo %__MsgPrefix%Commencing CoreCLR repo test build
+echo %__MsgPrefix%Commencing CoreCLR test build
 
 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
 set "__TestRootDir=%__RootBinDir%\tests"
 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
-:: We have different managed and native intermediate dirs because the managed bits will include
-:: the configuration information deeper in the intermediates path.
-:: These variables are used by the msbuild project files.
+
+REM We have different managed and native intermediate dirs because the managed bits will include
+REM the configuration information deeper in the intermediates path.
+REM These variables are used by the msbuild project files.
 
 if not defined __TestIntermediateDir (
     set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
@@ -137,7 +153,7 @@ if not defined __TestIntermediateDir (
 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
 
-:: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
+REM Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
 set "__CMakeBinDir=%__TestBinDir%"
 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
 
@@ -148,7 +164,7 @@ if not exist "%__LogsDir%"                      md "%__LogsDir%"
 
 echo %__MsgPrefix%Checking prerequisites
 
-:: Eval the output from probe-win1.ps1
+REM Eval the output from probe-win1.ps1
 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
 
 REM =========================================================================================
@@ -156,13 +172,15 @@ REM ===
 REM === Restore Build Tools
 REM ===
 REM =========================================================================================
+
 call "%__ProjectDir%\init-tools.cmd"
 @if defined _echo @echo on
+
 set "__ToolsDir=%__ProjectDir%\Tools"
-set "__DotnetHost=%__ToolsDir%\dotnetcli\dotnet.exe"
-if not exist "%__DotnetHost%" (
-   echo %__DotnetHost% not found after init-tools.
-   exit /b 1
+set "DotNetCli=%__ToolsDir%\dotnetcli\dotnet.exe"
+if not exist "%DotNetCli%" (
+    echo %__MsgPrefix%"%DotNetCli%" not found after init-tools.
+    exit /b 1
 )
 
 REM =========================================================================================
@@ -174,17 +192,22 @@ REM ============================================================================
 call "%__TestDir%\setup-stress-dependencies.cmd" /arch %__BuildArch% /outputdir %__BinDir%
 @if defined _echo @echo on
 
-if defined __SkipNative goto skipnative
-
 REM =========================================================================================
 REM ===
 REM === Native test build section
 REM ===
 REM =========================================================================================
 
+if defined __SkipNative goto skipnative
+
 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
 
-:: Set the environment for the native build
+REM Set the environment for the native build
+set __VCBuildArch=x86_amd64
+if /i "%__BuildArch%" == "x86" ( set __VCBuildArch=x86 )
+if /i "%__BuildArch%" == "arm" ( set __VCBuildArch=x86_arm )
+if /i "%__BuildArch%" == "arm64" ( set __VCBuildArch=x86_arm64 )
+
 echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" %__VCBuildArch%
 call                                 "%__VCToolsRoot%\vcvarsall.bat" %__VCBuildArch%
 @if defined _echo @echo on
@@ -209,11 +232,12 @@ set __BuildLogRootName=Tests_Native
 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 __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
+set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
+set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
+set __Logging=-MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr!
 
-call "%__ProjectDir%\run.cmd" build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! -configuration=%__BuildType% -platform=%__BuildArch% %__RunArgs% %__PriorityArg% %__PassThroughArg% %__unprocessedBuildArgs%
+call "%__ProjectDir%\run.cmd" build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" !__Logging! -configuration=%__BuildType% -platform=%__BuildArch% %__RunArgs% %__PriorityArg% %__PassThroughArg% %__UnprocessedBuildArgs%
 if errorlevel 1 (
     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
     echo     %__BuildLog%
@@ -224,54 +248,62 @@ if errorlevel 1 (
 
 :skipnative
 
-set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
-if "%__SkipRestorePackages%" == 1 goto SkipRestoreProduct
 REM =========================================================================================
 REM ===
 REM === Restore product binaries from packages
 REM ===
 REM =========================================================================================
 
-if not defined XunitTestBinBase       set  XunitTestBinBase=%__TestWorkingDir%
+if "%__SkipRestorePackages%" == 1 goto SkipRestoreProduct
+
+echo %__MsgPrefix%Restoring CoreCLR product from packages
+
+if not defined XunitTestBinBase set XunitTestBinBase=%__TestBinDir%
 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%"
+set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
+set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
+set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
+set __Logging=-MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr!
 
-call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -BatchRestorePackages -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__PriorityArg% %__PassThroughArg% %__unprocessedBuildArgs%
+call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -BatchRestorePackages !__Logging! %__RunArgs% %__BuildAgainstPackagesArg% %__PriorityArg% %__PassThroughArg% %__UnprocessedBuildArgs%
 
 if not defined __BuildAgainstPackagesArg goto SkipRestoreProduct
+
+echo %__MsgPrefix%BinPlacing CoreLib
+
 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%"
+set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
+set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
+set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
+set __Logging=-MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr!
 
-call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct -RuntimeId="%__RuntimeId%" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__PriorityArg% %__PassThroughArg% %__unprocessedBuildArgs%
+call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct -RuntimeId="%__RuntimeId%" !__Logging! %__RunArgs% %__BuildAgainstPackagesArg% %__PriorityArg% %__PassThroughArg% %__UnprocessedBuildArgs%
 if errorlevel 1 (
-    echo BinPlace of mscorlib.dll failed
+    echo %__MsgPrefix%Error: BinPlace of mscorlib.dll failed. Refer to the build log files for details:
+    echo     %__BuildLog%
+    echo     %__BuildWrn%
+    echo     %__BuildErr%
     exit /b 1
 )
 
-echo %__MsgPrefix% Restored CoreCLR product from packages
-
 :SkipRestoreProduct
 
-if defined __SkipManaged goto SkipManagedBuild
-
 REM =========================================================================================
 REM ===
 REM === Managed test build section
 REM ===
 REM =========================================================================================
 
+if defined __SkipManaged goto SkipManagedBuild
+
 echo %__MsgPrefix%Starting the Managed Tests Build
 
 if not defined VSINSTALLDIR (
@@ -297,12 +329,14 @@ echo %__MsgPrefix%Building tests group %__TestGroupToBuild% with %__BuildLoopCou
 
 for /l %%G in (1, 1, %__BuildLoopCount%) do (
 
-    set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%";Append=!__AppendToLog!
-    set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%";Append=!__AppendToLog!
-    set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%";Append=!__AppendToLog!
+    set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%";Append=!__AppendToLog!
+    set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%";Append=!__AppendToLog!
+    set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%";Append=!__AppendToLog!
 
     set TestBuildSlice=%%G
-    call %__DotnetHost% msbuild %__ProjectDir%\tests\build.proj !__msbuildLog! !__msbuildWrn! !__msbuildErr! %__msbuildArgs% %__BuildAgainstPackagesMsbuildArg% %__PriorityMsbuildArg% %__PassThroughArg% %__unprocessedBuildArgs%
+    echo Running: msbuild %__ProjectDir%\tests\build.proj !__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! %TargetsWindowsMsbuildArg% %__msbuildArgs% %__BuildAgainstPackagesMsbuildArg% !__PriorityMsbuildArg! %__UnprocessedBuildArgs%
+
+    call msbuild %__ProjectDir%\tests\build.proj !__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! %TargetsWindowsMsbuildArg% %__msbuildArgs% %__BuildAgainstPackagesMsbuildArg% !__PriorityMsbuildArg! %__UnprocessedBuildArgs%
 
     if errorlevel 1 (
         echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
@@ -317,12 +351,29 @@ for /l %%G in (1, 1, %__BuildLoopCount%) do (
     set __AppendToLog=true
 )
 
+REM Check that we've built about as many tests as we expect. This is primarily intended to prevent accidental changes that cause us to build
+REM drastically fewer Pri-1 tests than expected.
+echo %__MsgPrefix%Check the managed tests build
+echo Running: msbuild %__ProjectDir%\tests\runtest.proj /t:CheckTestBuild /p:CLRTestPriorityToBuild=%__Priority% %__msbuildArgs% %__unprocessedBuildArgs%
+call msbuild %__ProjectDir%\tests\runtest.proj /t:CheckTestBuild /p:CLRTestPriorityToBuild=%__Priority% %__msbuildArgs% %__unprocessedBuildArgs%
+if errorlevel 1 (
+    echo %__MsgPrefix%Error: build failed.
+    exit /b 1
+)
+
 :SkipManagedBuild
-REM Prepare the Test Drop
-REM Cleans any NI from the last run
-powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
-REM Cleans up any lock folder used for synchronization from last run
-powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force |  where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
+
+REM =========================================================================================
+REM ===
+REM === Prepare the test drop
+REM ===
+REM =========================================================================================
+
+echo %__MsgPrefix%Removing 'ni' files and 'lock' folders from %__TestBinDir%
+REM Remove any NI from previous runs.
+powershell -NoProfile "Get-ChildItem -path %__TestBinDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
+REM Remove any lock folder used for synchronization from previous runs.
+powershell -NoProfile "Get-ChildItem -path %__TestBinDir% -Include 'lock' -Recurse -Force |  where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
 
 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
 set CORE_ROOT_STAGE=%__TestBinDir%\Tests\Core_Root_Stage
@@ -332,18 +383,17 @@ md "%CORE_ROOT%"
 md "%CORE_ROOT_STAGE%"
 xcopy "%__BinDir%" "%CORE_ROOT_STAGE%"
 
-
 if defined __BuildAgainstPackagesArg ( 
-  if "%__TargetsWindows%"=="0" (
+    if "%__TargetsWindows%"=="0" (
 
-    if not exist %__PackagesDir%\TestNativeBins (
-        echo %__MsgPrefix%Error: Ensure you have run sync.cmd -ab before building a non-Windows test overlay against packages
-        exit /b 1
-    )
+        if not exist %__PackagesDir%\TestNativeBins (
+            echo %__MsgPrefix%Error: Ensure you have run sync.cmd -ab before building a non-Windows test overlay against packages
+            exit /b 1
+        )
 
-    for /R %__PackagesDir%\TestNativeBins\%__RuntimeId%\%__BuildType% %%f in (*.so) do copy %%f %CORE_ROOT_STAGE%
-    for /R %__PackagesDir%\TestNativeBins\%__RuntimeId%\%__BuildType% %%f in (*.dylib) do copy %%f %CORE_ROOT_STAGE%
-  )
+        for /R %__PackagesDir%\TestNativeBins\%__RuntimeId%\%__BuildType% %%f in (*.so) do copy %%f %CORE_ROOT_STAGE%
+        for /R %__PackagesDir%\TestNativeBins\%__RuntimeId%\%__BuildType% %%f in (*.dylib) do copy %%f %CORE_ROOT_STAGE%
+    )
 )
 
 REM =========================================================================================
@@ -352,32 +402,23 @@ REM === Create the test overlay
 REM ===
 REM =========================================================================================
 
+echo %__MsgPrefix%Creating test overlay
+
 set RuntimeIdArg=
 if defined __RuntimeId (
     set RuntimeIdArg=-RuntimeID="%__RuntimeId%"
 )
 
-set TargetsWindowsArg=
-set TargetsWindowsMsbuildArg=
-if "%__TargetsWindows%"=="1" (
-    set TargetsWindowsArg=-TargetsWindows=true
-    set TargetsWindowsMsbuildArg=/p:TargetsWindows=true
-) else if "%__TargetsWindows%"=="0" (
-    set TargetsWindowsArg=-TargetsWindows=false
-    set TargetsWindowsMsbuildArg=/p:TargetsWindows=false
-)
-
-echo %__MsgPrefix%Creating test overlay...
-
 set __BuildLogRootName=Tests_Overlay_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%"
+set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
+set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
+set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
+set __Logging=-MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr!
 
-call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testOverlay -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %RuntimeIdArg% %__PriorityArg% %__PassThroughArg% %__unprocessedBuildArgs%
+call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testOverlay !__Logging! %__RunArgs% %RuntimeIdArg% %__PriorityArg% %__PassThroughArg% %__UnprocessedBuildArgs%
 if errorlevel 1 (
     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
     echo     %__BuildLog%
@@ -388,18 +429,25 @@ if errorlevel 1 (
 
 xcopy /s /y "%CORE_ROOT_STAGE%" "%CORE_ROOT%"
 
-REM Create the test host necessary for running CoreFX tests 
-REM The test host includes a dotnet executable, system libraries and CoreCLR assemblies found in CoreRoot
+REM =========================================================================================
+REM ===
+REM === Create the test host necessary for running CoreFX tests.
+REM === The test host includes a dotnet executable, system libraries and CoreCLR assemblies found in CORE_ROOT.
+REM ===
+REM =========================================================================================
+
+echo %__MsgPrefix%Building CoreFX test host
 
 set __BuildLogRootName=Tests_CoreFX_Testhost
 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 __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
+set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
+set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
+set __Logging=-MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr!
 
-call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testHost -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %RuntimeIdArg% %__PriorityArg% %__PassThroughArg% %__unprocessedBuildArgs%
+call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testHost !__Logging! %__RunArgs% %RuntimeIdArg% %__PriorityArg% %__PassThroughArg% %__UnprocessedBuildArgs%
 if errorlevel 1 (
     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
     echo     %__BuildLog%
@@ -408,55 +456,78 @@ if errorlevel 1 (
     exit /b 1
 )
 
+REM =========================================================================================
+REM ===
+REM === Create test wrappers.
+REM ===
+REM =========================================================================================
+
 if defined __SkipManaged goto SkipBuildingWrappers
 
-echo %__MsgPrefix%Creating test wrappers...
+echo %__MsgPrefix%Creating test wrappers
 
 set __BuildLogRootName=Tests_XunitWrapper
 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 __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
+set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
+set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
+set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr!
 
 REM Build wrappers using the local SDK's msbuild. As we move to arcade, the other builds should be moved away from run.exe as well.
-call %__DotnetHost% msbuild %__ProjectDir%\tests\runtest.proj /p:RestoreAdditionalProjectSources=https://dotnet.myget.org/F/dotnet-core/  /p:BuildWrappers=true !__msbuildLog! !__msbuildWrn! !__msbuildErr! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__BuildAgainstPackagesMsbuildArg% %__unprocessedBuildArgs%
+call %DotNetCli% msbuild %__ProjectDir%\tests\runtest.proj /p:RestoreAdditionalProjectSources=https://dotnet.myget.org/F/dotnet-core/  /p:BuildWrappers=true !__Logging! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__BuildAgainstPackagesMsbuildArg% %__UnprocessedBuildArgs%
 if errorlevel 1 (
-    echo Xunit Wrapper build failed
+    echo %__MsgPrefix%Error: Xunit wrapper build failed. Refer to the build log files for details:
+    echo     %__BuildLog%
+    echo     %__BuildWrn%
+    echo     %__BuildErr%
     exit /b 1
 )
+
+echo { "build_os": "%__BuildOS%", "build_arch": "%__BuildArch%", "build_type": "%__BuildType%" } > "%__TestBinDir%/build_info.json"
+
 :SkipBuildingWrappers
 
+REM =========================================================================================
+REM ===
+REM === Crossgen assemblies if needed.
+REM ===
+REM =========================================================================================
+
 set __CrossgenArg = ""
 if defined __DoCrossgen (
-  set __CrossgenArg="-Crossgen"
-  if "%__TargetsWindows%" == "1" (
-    call :PrecompileFX
-  ) else (
-    echo "%__MsgPrefix% Crossgen only supported on Windows, for now"
-  )
+    set __CrossgenArg="-Crossgen"
+    if "%__TargetsWindows%" == "1" (
+        echo %__MsgPrefix%Running crossgen on framework assemblies
+        call :PrecompileFX
+    ) else (
+        echo "%__MsgPrefix%Crossgen only supported on Windows, for now"
+    )
 )
 
 rd /s /q "%CORE_ROOT_STAGE%"
 
+REM =========================================================================================
+REM ===
+REM === Prep test binaries for Helix publishing
+REM ===
+REM =========================================================================================
+
 if not defined __ZipTests goto SkipPrepForPublish
 
+echo %__MsgPrefix%Preparing test binaries for Helix publishing
+
 set __BuildLogRootName=Helix_Prep
 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 __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
+set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
+set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
+set __Logging=-MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr!
 
-REM =========================================================================================
-REM ===
-REM === Prep test binaries for Helix publishing
-REM ===
-REM =========================================================================================
-
-call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\helixprep.proj  -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %RuntimeIdArg% %TargetsWindowsArg% %__CrossgenArg% %__PriorityArg% %__PassThroughArg% %__unprocessedBuildArgs%
+call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\helixprep.proj !__Logging! %__RunArgs% %RuntimeIdArg% %TargetsWindowsArg% %__CrossgenArg% %__PriorityArg% %__PassThroughArg% %__UnprocessedBuildArgs%
 if errorlevel 1 (
     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
     echo     %__BuildLog%
@@ -465,8 +536,6 @@ if errorlevel 1 (
     exit /b 1
 )
 
-echo %__MsgPrefix% Prepped test binaries for publishing
-
 :SkipPrepForPublish
 
 REM =========================================================================================
@@ -475,7 +544,7 @@ REM === All builds complete!
 REM ===
 REM =========================================================================================
 
-echo %__MsgPrefix%Test build successful.
+echo %__MsgPrefix%Test build succeeded.  Finished at %TIME%
 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
 exit /b 0
 
@@ -487,7 +556,7 @@ echo Usage:
 echo     %0 [option1] [option2] ...
 echo All arguments are optional. Options are case-insensitive. The options are:
 echo.
-echo. -? -h -help: view this message.
+echo.-? -h -help --help: view this message.
 echo Build architecture: one of x64, x86, arm, arm64 ^(default: x64^).
 echo Build type: one of Debug, Checked, Release ^(default: Debug^).
 echo skipmanaged: skip the managed tests build
@@ -515,7 +584,7 @@ echo targetsNonWindows:
 echo Exclude- Optional parameter - specify location of default exclusion file ^(defaults to tests\issues.targets if not specified^)
 echo     Set to "" to disable default exclusion file.
 echo -- ... : all arguments following this tag will be passed directly to msbuild.
-echo -priority=^<N^> : specify a set of test that will be built and run, with priority N.
+echo -priority=^<N^> : specify a set of tests that will be built and run, with priority N.
 echo     0: Build only priority 0 cases as essential testcases (default)
 echo     1: Build all tests with priority 0 and 1
 echo     666: Build all tests with priority 0, 1 ... 666
@@ -527,7 +596,7 @@ echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
 of the previous version to "%VSINSTALLDIR%" and then build.
-:: DIA SDK not included in Express editions
+REM DIA SDK not included in Express editions
 echo Visual Studio Express does not include the DIA SDK. ^
 You need Visual Studio 2015 or 2017 (Community is free).
 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
@@ -558,7 +627,7 @@ if %__exitCode% neq 0 (
     exit /b 0
 )
 
-:: Delete original .dll & replace it with the Crossgened .dll
+REM Delete original .dll & replace it with the Crossgened .dll
 del %1
 ren "%CORE_ROOT%\temp.ni.dll" %2