1 @if not defined _echo @echo off
2 setlocal EnableDelayedExpansion
4 :: Set the default arguments for build
6 set __VCBuildArch=x86_amd64
8 set __BuildOS=Windows_NT
10 set __VSToolsRoot=%VS140COMNTOOLS%
12 :: Define a prefix for most output progress messages that come from this script. That makes
13 :: it easier to see where these are coming from. Note that there is a trailing space here.
14 set __MsgPrefix=BUILDTEST:
16 set "__ProjectDir=%~dp0"
17 :: remove trailing slash
18 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
19 set "__TestDir=%__ProjectDir%\tests"
20 set "__ProjectFilesDir=%__TestDir%"
21 set "__SourceDir=%__ProjectDir%\src"
22 set "__PackagesDir=%__ProjectDir%\packages"
23 set "__RootBinDir=%__ProjectDir%\bin"
24 set "__LogsDir=%__RootBinDir%\Logs"
26 :: Default __Exclude to issues.targets
27 set __Exclude=%__TestDir%\issues.targets
29 REM __unprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
32 set __unprocessedBuildArgs=
34 set __BuildAgainstPackagesArg=
39 if "%1" == "" goto ArgsDone
41 if /i "%1" == "-?" goto Usage
42 if /i "%1" == "-h" goto Usage
43 if /i "%1" == "-help" goto Usage
45 if /i "%1" == "x64" (set __BuildArch=x64&set __VCBuildArch=x86_amd64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
46 if /i "%1" == "x86" (set __BuildArch=x86&set __VCBuildArch=x86&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
47 if /i "%1" == "arm" (set __BuildArch=arm&set __VCBuildArch=x86_arm&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
48 if /i "%1" == "arm64" (set __BuildArch=arm64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
50 if /i "%1" == "debug" (set __BuildType=Debug&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
51 if /i "%1" == "release" (set __BuildType=Release&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
52 if /i "%1" == "checked" (set __BuildType=Checked&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
54 if /i "%1" == "skipmanaged" (set __SkipManaged=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
55 if /i "%1" == "updateinvalidpackages" (set __UpdateInvalidPackagesArg=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
56 if /i "%1" == "toolset_dir" (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
57 if /i "%1" == "buildagainstpackages" (set __ZipTests=1&set __BuildAgainstPackagesArg=-BuildTestsAgainstPackages&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
58 if /i "%1" == "ziptests" (set __ZipTests=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
59 if /i "%1" == "runtimeid" (set __RuntimeId=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
60 if /i "%1" == "Exclude" (set __Exclude=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
62 if [!processedArgs!]==[] (
63 call set __UnprocessedBuildArgs=!__args!
65 call set __UnprocessedBuildArgs=%%__args:*!processedArgs!=%%
70 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
71 call "%__VSToolsRoot%\VsDevCmd.bat"
73 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
75 rem arm64 builds currently use private toolset which has not been released yet
76 REM TODO, remove once the toolset is open.
77 if /i "%__BuildArch%" == "arm64" call :PrivateToolSet
79 echo %__MsgPrefix%Commencing CoreCLR repo test build
81 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
82 set "__TestRootDir=%__RootBinDir%\tests"
83 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
84 :: We have different managed and native intermediate dirs because the managed bits will include
85 :: the configuration information deeper in the intermediates path.
86 :: These variables are used by the msbuild project files.
88 if not defined __TestIntermediateDir (
89 set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
91 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
92 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
94 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
95 set "__CMakeBinDir=%__TestBinDir%"
96 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
98 if not exist "%__TestBinDir%" md "%__TestBinDir%"
99 if not exist "%__NativeTestIntermediatesDir%" md "%__NativeTestIntermediatesDir%"
100 if not exist "%__ManagedTestIntermediatesDir%" md "%__ManagedTestIntermediatesDir%"
101 if not exist "%__LogsDir%" md "%__LogsDir%"
103 echo %__MsgPrefix%Checking prerequisites
105 :: Eval the output from probe-win1.ps1
106 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
108 REM =========================================================================================
110 REM === Restore Build Tools
112 REM =========================================================================================
113 call "%__ProjectDir%\init-tools.cmd"
115 REM =========================================================================================
117 REM === Resolve runtime dependences
119 REM =========================================================================================
120 call "%__TestDir%\setup-runtime-dependencies.cmd" /arch %__BuildArch% /outputdir %__BinDir%
122 if defined __UpdateInvalidPackagesArg (
126 REM =========================================================================================
128 REM === Native test build section
130 REM =========================================================================================
132 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
134 if defined __ToolsetDir (
135 echo %__MsgPrefix%ToolsetDir is defined to be :%__ToolsetDir%
136 goto GenVSSolution :: Private ToolSet is Defined
139 :: Set the environment for the native build
140 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
141 call "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
142 @if defined _echo @echo on
144 if not defined VSINSTALLDIR (
145 echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
148 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
152 pushd "%__NativeTestIntermediatesDir%"
153 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" ""%__ProjectFilesDir%"" %__VSVersion% %__BuildArch%
154 @if defined _echo @echo on
157 if not exist "%__NativeTestIntermediatesDir%\install.vcxproj" (
158 echo %__MsgPrefix%Failed to generate test native component build project!
162 set __msbuildNativeArgs=-configuration=%__BuildType%
164 if defined __ToolsetDir (
165 set __msbuildNativeArgs=%__msbuildNativeArgs% -UseEnv
167 set __msbuildNativeArgs=%__msbuildNativeArgs% -platform=%__BuildArch%
170 set __BuildLogRootName=Tests_Native
171 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
172 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
173 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
174 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
175 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
176 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
178 call "%__ProjectDir%\run.cmd" build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__msbuildNativeArgs% %__RunArgs% %__unprocessedBuildArgs%
180 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
189 set __BuildLogRootName=Restore_Product
190 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
191 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
192 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
193 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
194 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
195 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
197 set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
199 if not defined __BuildAgainstPackagesArg goto SkipRestoreProduct
200 REM =========================================================================================
202 REM === Restore product binaries from packages
204 REM =========================================================================================
206 if not defined XunitTestBinBase set XunitTestBinBase=%__TestWorkingDir%
207 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
208 set "CORE_OVERLAY=%XunitTestBinBase%\Tests\Core_Root_%__RuntimeId%"
210 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -UpdateDependencies -BatchRestorePackages -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
212 set __BuildLogRootName=Tests_GenerateRuntimeLayout
214 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
216 echo BinPlace of mscorlib.dll failed
220 if defined __RuntimeId (
222 if not exist %__PackagesDir%\TestNativeBins (
223 echo %__MsgPrefix%Error: Ensure you have run sync.cmd -ab before building a non-Windows test overlay against packages
227 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -CreateNonWindowsTestOverlay -RuntimeId="%__RuntimeId%" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
228 for /R %__PackagesDir%\TestNativeBins\%__RuntimeId%\%__BuildType% %%f in (*.so) do copy %%f %Core_Overlay%
229 for /R %__PackagesDir%\TestNativeBins\%__RuntimeId%\%__BuildType% %%f in (*.dylib) do copy %%f %Core_Overlay%
231 echo %__MsgPrefix% Created the runtime layout for %__RuntimeId% in %CORE_OVERLAY%
234 echo %__MsgPrefix% Restored CoreCLR product from packages
238 if defined __SkipManaged exit /b 0
240 set __BuildLogRootName=Tests_Managed
241 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
242 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
243 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
244 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
245 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
246 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
248 REM =========================================================================================
250 REM === Managed test build section
252 REM =========================================================================================
254 echo %__MsgPrefix%Starting the Managed Tests Build
256 if not defined VSINSTALLDIR (
257 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.
261 if defined __UpdateInvalidPackagesArg (
262 set __up=-updateinvalidpackageversions
265 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__up% %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
267 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
274 REM Prepare the Test Drop
275 REM Cleans any NI from the last run
276 powershell "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
277 REM Cleans up any lock folder used for synchronization from last run
278 powershell "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force | where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
280 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
281 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
283 xcopy /s "%__BinDir%" "%CORE_ROOT%"
285 echo %__MsgPrefix%Creating test wrappers...
289 if defined __RuntimeId (
290 set RuntimeIdArg=-RuntimeID="%__RuntimeId%"
293 set __BuildLogRootName=Tests_XunitWrapper
294 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
295 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
296 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
297 set __msbuildLog=/flp:Verbosity=diag;LogFile="%__BuildLog%"
298 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
299 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
301 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -BuildWrappers -MsBuildEventLogging=" " -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs% %RuntimeIdArg%
303 echo Xunit Wrapper build failed
307 echo %__MsgPrefix%Creating test overlay...
309 set __BuildLogRootName=Tests_Overlay_Managed
310 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
311 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
312 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
313 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
314 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
315 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
317 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testOverlay -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__unprocessedBuildArgs%
319 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
326 if not defined __ZipTests goto SkipPrepForPublish
328 set __BuildLogRootName=Helix_Prep
329 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
330 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
331 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
332 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
333 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
334 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
336 REM =========================================================================================
338 REM === Prep test binaries for Helix publishing
340 REM =========================================================================================
342 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\helixprep.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs% %RuntimeIdArg%
344 echo %__MsgPrefix% Prepped test binaries for publishing
348 REM =========================================================================================
350 REM === All builds complete!
352 REM =========================================================================================
354 echo %__MsgPrefix%Test build successful.
355 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
361 echo %0 [option1] [option2] ...
362 echo All arguments are optional. Options are case-insensitive. The options are:
364 echo. -? -h -help: view this message.
365 echo Build architecture: -buildArch: only x64 is currently allowed ^(default: x64^).
366 echo Build type: -buildType: one of Debug, Checked, Release ^(default: Debug^).
367 echo updateinvalidpackageversions: Runs the target to update package versions.
368 echo buildagainstpackages: builds tests against restored packages, instead of against a built product.
369 echo runtimeid ^<ID^>: Builds a test overlay for the specified OS (Only supported when building against packages). Supported IDs are:
370 echo alpine.3.4.3-x64: Builds overlay for Alpine 3.4.3
371 echo debian.8-x64: Builds overlay for Debian 8
372 echo fedora.23-x64: Builds overlay for Fedora 23
373 echo fedora.24-x64: Builds overlay for Fedora 23
374 echo opensuse.42.1-x64: Builds overlay for OpenSUSE 42.1
375 echo osx.10.10-x64: Builds overlay for OSX 10.10
376 echo rhel.7-x64: Builds overlay for RHEL 7 or CentOS
377 echo ubuntu.14.04-x64: Builds overlay for Ubuntu 14.04
378 echo ubuntu.16.04-x64: Builds overlay for Ubuntu 16.04
379 echo ubuntu.16.10-x64: Builds overlay for Ubuntu 16.10
380 echo ziptests: zips CoreCLR tests & Core_Root for a Helix run
381 echo Exclude- Optional parameter - specify location of default exclusion file (defaults to tests\issues.targets if not specified)
382 echo Set to "" to disable default exclusion file.
383 echo -- ... : all arguments following this tag will be passed directly to msbuild.
384 echo -priority=^<N^> : specify a set of test that will be built and run, with priority N.
385 echo 0: Build only priority 0 cases as essential testcases (default)
386 echo 1: Build all tests with priority 0 and 1
387 echo 666: Build all tests with priority 0, 1 ... 666
388 echo -sequential: force a non-parallel build ^(default is to build in parallel
389 echo using all processors^).
390 echo -ilasmroundtrip: enables ilasm round trip build and run of the tests before executing them.
391 echo -verbose: enables detailed file logging for the msbuild tasks into the msbuild log file.
395 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
396 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
397 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
398 of the previous version to "%VSINSTALLDIR%" and then build.
399 :: DIA SDK not included in Express editions
400 echo Visual Studio 2013 Express does not include the DIA SDK. ^
401 You need Visual Studio 2013+ (Community is free).
402 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
408 echo %__MsgPrefix% Setting Up the usage of __ToolsetDir:%__ToolsetDir%
410 if /i "%__ToolsetDir%" == "" (
411 echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
415 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
416 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
418 %__ToolsetDir%\VC_sdk\inc;^
419 %__ToolsetDir%\sdpublic\sdk\inc;^
420 %__ToolsetDir%\sdpublic\shared\inc;^
421 %__ToolsetDir%\sdpublic\shared\inc\minwin;^
422 %__ToolsetDir%\sdpublic\sdk\inc\ucrt;^
423 %__ToolsetDir%\sdpublic\sdk\inc\minwin;^
424 %__ToolsetDir%\sdpublic\sdk\inc\mincore;^
425 %__ToolsetDir%\sdpublic\sdk\inc\abi;^
426 %__ToolsetDir%\sdpublic\sdk\inc\clientcore;^
427 %__ToolsetDir%\diasdk\include