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 __BuildAgainstPackages=
35 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 __BuildAgainstPackages=1&set __BuildAgainstPackagesArg=-BuildTestsAgainstPackages&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
58 if /i "%1" == "runtimeid" (set __RuntimeId=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
59 if /i "%1" == "Exclude" (set __Exclude=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
61 if [!processedArgs!]==[] (
62 call set __UnprocessedBuildArgs=!__args!
64 call set __UnprocessedBuildArgs=%%__args:*!processedArgs!=%%
69 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
70 call "%__VSToolsRoot%\VsDevCmd.bat"
72 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
74 rem arm64 builds currently use private toolset which has not been released yet
75 REM TODO, remove once the toolset is open.
76 if /i "%__BuildArch%" == "arm64" call :PrivateToolSet
78 echo %__MsgPrefix%Commencing CoreCLR repo test build
80 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
81 set "__TestRootDir=%__RootBinDir%\tests"
82 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
83 :: We have different managed and native intermediate dirs because the managed bits will include
84 :: the configuration information deeper in the intermediates path.
85 :: These variables are used by the msbuild project files.
87 if not defined __TestIntermediateDir (
88 set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
90 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
91 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
93 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
94 set "__CMakeBinDir=%__TestBinDir%"
95 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
97 if not exist "%__TestBinDir%" md "%__TestBinDir%"
98 if not exist "%__NativeTestIntermediatesDir%" md "%__NativeTestIntermediatesDir%"
99 if not exist "%__ManagedTestIntermediatesDir%" md "%__ManagedTestIntermediatesDir%"
100 if not exist "%__LogsDir%" md "%__LogsDir%"
102 echo %__MsgPrefix%Checking prerequisites
104 :: Eval the output from probe-win1.ps1
105 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
107 REM =========================================================================================
109 REM === Restore Build Tools
111 REM =========================================================================================
112 call "%__ProjectDir%\init-tools.cmd"
114 REM =========================================================================================
116 REM === Resolve runtime dependences
118 REM =========================================================================================
119 call "%__TestDir%\setup-runtime-dependencies.cmd" /arch %__BuildArch% /outputdir %__BinDir%
121 if defined __UpdateInvalidPackagesArg (
125 REM =========================================================================================
127 REM === Native test build section
129 REM =========================================================================================
131 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
133 if defined __ToolsetDir (
134 echo %__MsgPrefix%ToolsetDir is defined to be :%__ToolsetDir%
135 goto GenVSSolution :: Private ToolSet is Defined
138 :: Set the environment for the native build
139 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
140 call "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
141 @if defined _echo @echo on
143 if not defined VSINSTALLDIR (
144 echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
147 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
151 pushd "%__NativeTestIntermediatesDir%"
152 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" ""%__ProjectFilesDir%"" %__VSVersion% %__BuildArch%
153 @if defined _echo @echo on
156 if not exist "%__NativeTestIntermediatesDir%\install.vcxproj" (
157 echo %__MsgPrefix%Failed to generate test native component build project!
161 set __msbuildNativeArgs=-configuration=%__BuildType%
163 if defined __ToolsetDir (
164 set __msbuildNativeArgs=%__msbuildNativeArgs% -UseEnv
166 set __msbuildNativeArgs=%__msbuildNativeArgs% -platform=%__BuildArch%
169 set __BuildLogRootName=Tests_Native
170 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
171 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
172 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
173 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
174 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
175 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
177 call "%__ProjectDir%\run.cmd" build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__msbuildNativeArgs% %__RunArgs% %__unprocessedBuildArgs%
179 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
188 set __BuildLogRootName=Restore_Product
189 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
190 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
191 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
192 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
193 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
194 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
196 if not defined __BuildAgainstPackages goto SkipRestoreProduct
197 REM =========================================================================================
199 REM === Restore product binaries from packages
201 REM =========================================================================================
203 set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
204 if not defined XunitTestBinBase set XunitTestBinBase=%__TestWorkingDir%
205 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
206 set "CORE_OVERLAY=%XunitTestBinBase%\Tests\Core_Root_%__RuntimeId%"
208 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -UpdateDependencies -BatchRestorePackages -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
210 set __BuildLogRootName=Tests_GenerateRuntimeLayout
212 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
214 echo BinPlace of mscorlib.dll failed
218 if defined __RuntimeId (
220 if not exist %__PackagesDir%\TestNativeBins (
221 echo %__MsgPrefix%Error: Ensure you have run sync.cmd -ab before building a non-Windows test overlay against packages
225 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -CreateNonWindowsTestOverlay -RuntimeId="%__RuntimeId%" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
226 for /R %__PackagesDir%\TestNativeBins\%__RuntimeId% %%f in (*.so) do copy %%f %Core_Overlay%
227 for /R %__PackagesDir%\TestNativeBins\%__RuntimeId% %%f in (*.dylib) do copy %%f %Core_Overlay%
229 echo %__MsgPrefix% Created the runtime layout for %__RuntimeId% in %CORE_OVERLAY%
232 echo %__MsgPrefix% Restored CoreCLR product from packages
236 if defined __SkipManaged exit /b 0
238 set __BuildLogRootName=Tests_Managed
239 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
240 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
241 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
242 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
243 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
244 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
246 REM =========================================================================================
248 REM === Managed test build section
250 REM =========================================================================================
252 echo %__MsgPrefix%Starting the Managed Tests Build
254 if not defined VSINSTALLDIR (
255 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.
259 if defined __UpdateInvalidPackagesArg (
260 set __up=-updateinvalidpackageversions
263 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__up% %__RunArgs% %__unprocessedBuildArgs%
265 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
272 REM Prepare the Test Drop
273 REM Cleans any NI from the last run
274 powershell "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
275 REM Cleans up any lock folder used for synchronization from last run
276 powershell "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force | where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
278 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
279 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
281 xcopy /s "%__BinDir%" "%CORE_ROOT%"
283 echo %__MsgPrefix%Creating test wrappers...
287 if defined __RuntimeId (
288 set RuntimeIdArg=-RuntimeID="%__RuntimeId%"
291 set __BuildLogRootName=Tests_XunitWrapper
292 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
293 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
294 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
295 set __msbuildLog=/flp:Verbosity=diag;LogFile="%__BuildLog%"
296 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
297 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
299 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -BuildWrappers -MsBuildEventLogging=" " -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs% %RuntimeIdArg%
301 echo Xunit Wrapper build failed
305 echo %__MsgPrefix%Creating test overlay...
307 set __BuildLogRootName=Tests_Overlay_Managed
308 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
309 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
310 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
311 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
312 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
313 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
315 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -testOverlay -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__unprocessedBuildArgs%
317 echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
324 if not defined __BuildAgainstPackages goto SkipPrepForPublish
326 set __BuildLogRootName=Helix_Prep
327 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
328 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
329 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
330 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
331 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
332 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
334 REM =========================================================================================
336 REM === Prep test binaries for Helix publishing
338 REM =========================================================================================
340 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\helixprep.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs% %RuntimeIdArg%
342 echo %__MsgPrefix% Prepped test binaries for publishing
346 REM =========================================================================================
348 REM === All builds complete!
350 REM =========================================================================================
352 echo %__MsgPrefix%Test build successful.
353 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
359 echo %0 [option1] [option2] ...
360 echo All arguments are optional. Options are case-insensitive. The options are:
362 echo. -? -h -help: view this message.
363 echo Build architecture: -buildArch: only x64 is currently allowed ^(default: x64^).
364 echo Build type: -buildType: one of Debug, Checked, Release ^(default: Debug^).
365 echo updateinvalidpackageversions: Runs the target to update package versions.
366 echo buildagainstpackages: builds tests against restored packages, instead of against a built product.
367 echo runtimeid ^<ID^>: Builds a test overlay for the specified OS (Only supported when building against packages). Supported IDs are:
368 echo alpine.3.4.3-x64: Builds overlay for Alpine 3.4.3
369 echo debian.8-x64: Builds overlay for Debian 8
370 echo fedora.23-x64: Builds overlay for Fedora 23
371 echo fedora.24-x64: Builds overlay for Fedora 23
372 echo opensuse.13.2-x64: Builds overlay for OpenSUSE 13.2
373 echo opensuse.42.1-x64: Builds overlay for OpenSUSE 42.1
374 echo osx.10.10-x64: Builds overlay for OSX 10.10
375 echo rhel.7-x64: Builds overlay for RHEL 7 or CentOS
376 echo ubuntu.14.04-x64: Builds overlay for Ubuntu 14.04
377 echo ubuntu.16.04-x64: Builds overlay for Ubuntu 16.04
378 echo ubuntu.16.10-x64: Builds overlay for Ubuntu 16.10
379 echo Exclude- Optional parameter - specify location of default exclusion file (defaults to tests\issues.targets if not specified)
380 echo Set to "" to disable default exclusion file.
381 echo -- ... : all arguments following this tag will be passed directly to msbuild.
382 echo -priority=^<N^> : specify a set of test that will be built and run, with priority N.
383 echo 0: Build only priority 0 cases as essential testcases (default)
384 echo 1: Build all tests with priority 0 and 1
385 echo 666: Build all tests with priority 0, 1 ... 666
386 echo -sequential: force a non-parallel build ^(default is to build in parallel
387 echo using all processors^).
388 echo -ilasmroundtrip: enables ilasm round trip build and run of the tests before executing them.
389 echo -verbose: enables detailed file logging for the msbuild tasks into the msbuild log file.
393 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
394 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
395 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
396 of the previous version to "%VSINSTALLDIR%" and then build.
397 :: DIA SDK not included in Express editions
398 echo Visual Studio 2013 Express does not include the DIA SDK. ^
399 You need Visual Studio 2013+ (Community is free).
400 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
406 echo %__MsgPrefix% Setting Up the usage of __ToolsetDir:%__ToolsetDir%
408 if /i "%__ToolsetDir%" == "" (
409 echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
413 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
414 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
416 %__ToolsetDir%\VC_sdk\inc;^
417 %__ToolsetDir%\sdpublic\sdk\inc;^
418 %__ToolsetDir%\sdpublic\shared\inc;^
419 %__ToolsetDir%\sdpublic\shared\inc\minwin;^
420 %__ToolsetDir%\sdpublic\sdk\inc\ucrt;^
421 %__ToolsetDir%\sdpublic\sdk\inc\minwin;^
422 %__ToolsetDir%\sdpublic\sdk\inc\mincore;^
423 %__ToolsetDir%\sdpublic\sdk\inc\abi;^
424 %__ToolsetDir%\sdpublic\sdk\inc\clientcore;^
425 %__ToolsetDir%\diasdk\include