Merge remote-tracking branch 'dotnet/master' into merge-master-nullable
[platform/upstream/coreclr.git] / build-test.cmd
1 @if not defined _echo @echo off
2 setlocal EnableDelayedExpansion EnableExtensions
3
4 :: Define a prefix for most output progress messages that come from this script. That makes
5 :: it easier to see where these are coming from. Note that there is a trailing space here.
6 set "__MsgPrefix=BUILDTEST: "
7
8 echo %__MsgPrefix%Starting Build at %TIME%
9
10 set __ThisScriptDir="%~dp0"
11
12 call "%__ThisScriptDir%"\setup_vs_tools.cmd
13 if NOT '%ERRORLEVEL%' == '0' exit /b 1
14
15 if defined VS160COMNTOOLS (
16     set "__VSToolsRoot=%VS160COMNTOOLS%"
17     set "__VCToolsRoot=%VS160COMNTOOLS%\..\..\VC\Auxiliary\Build"
18     set __VSVersion=vs2019
19 ) else if defined VS150COMNTOOLS (
20     set "__VSToolsRoot=%VS150COMNTOOLS%"
21     set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
22     set __VSVersion=vs2017
23 )
24
25 :: Set the default arguments for build
26 set __BuildArch=x64
27 set __BuildType=Debug
28 set __BuildOS=Windows_NT
29
30 set "__ProjectDir=%~dp0"
31 :: remove trailing slash
32 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
33 set "__TestDir=%__ProjectDir%\tests"
34 set "__ProjectFilesDir=%__TestDir%"
35 set "__SourceDir=%__ProjectDir%\src"
36 set "__PackagesDir=%__ProjectDir%\packages"
37 set "__RootBinDir=%__ProjectDir%\bin"
38 set "__LogsDir=%__RootBinDir%\Logs"
39 set "__MsbuildDebugLogsDir=%__LogsDir%\MsbuildDebugLogs"
40
41 :: Default __Exclude to issues.targets
42 set __Exclude=%__TestDir%\issues.targets
43
44 REM __UnprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
45 set "__args= %*"
46 set processedArgs=
47 set __UnprocessedBuildArgs=
48 set __CommonMSBuildArgs=
49
50 set __SkipRestorePackages=
51 set __SkipManaged=
52 set __SkipNative=
53 set __RuntimeId=
54 set __TargetsWindows=1
55 set __DoCrossgen=
56
57 @REM CMD has a nasty habit of eating "=" on the argument list, so passing:
58 @REM    -priority=1
59 @REM appears to CMD parsing as "-priority 1". Handle -priority specially to avoid problems,
60 @REM and allow the "-priority=1" syntax.
61 set __Priority=0
62 set __PriorityArg=
63
64 :Arg_Loop
65 if "%1" == "" goto ArgsDone
66
67 if /i "%1" == "/?"     goto Usage
68 if /i "%1" == "-?"     goto Usage
69 if /i "%1" == "/h"     goto Usage
70 if /i "%1" == "-h"     goto Usage
71 if /i "%1" == "/help"  goto Usage
72 if /i "%1" == "-help"  goto Usage
73 if /i "%1" == "--help" goto Usage
74
75 if /i "%1" == "x64"                   (set __BuildArch=x64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
76 if /i "%1" == "x86"                   (set __BuildArch=x86&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
77 if /i "%1" == "arm"                   (set __BuildArch=arm&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
78 if /i "%1" == "arm64"                 (set __BuildArch=arm64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
79
80 if /i "%1" == "debug"                 (set __BuildType=Debug&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
81 if /i "%1" == "release"               (set __BuildType=Release&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
82 if /i "%1" == "checked"               (set __BuildType=Checked&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
83
84 if /i "%1" == "skipmanaged"           (set __SkipManaged=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
85 if /i "%1" == "skipnative"            (set __SkipNative=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
86 if /i "%1" == "buildtesthostonly"     (set __SkipNative=1&set __SkipManaged=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
87 if /i "%1" == "buildagainstpackages"  (echo error: Remove /BuildAgainstPackages switch&&exit /b1)
88 if /i "%1" == "skiprestorepackages"   (set __SkipRestorePackages=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
89 if /i "%1" == "crossgen"              (set __DoCrossgen=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
90 if /i "%1" == "runtimeid"             (set __RuntimeId=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
91 if /i "%1" == "targetsNonWindows"     (set __TargetsWindows=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
92 if /i "%1" == "Exclude"               (set __Exclude=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
93 if /i "%1" == "-priority"             (set __Priority=%2&shift&set processedArgs=!processedArgs! %1=%2&shift&goto Arg_Loop)
94 if /i "%1" == "--"                    (set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
95
96 if [!processedArgs!]==[] (
97     set __UnprocessedBuildArgs=%__args%
98 ) else (
99     set __UnprocessedBuildArgs=%__args%
100     for %%t in (!processedArgs!) do (
101         set __UnprocessedBuildArgs=!__UnprocessedBuildArgs:*%%t=!
102     )
103 )
104
105 :ArgsDone
106
107 @REM Special handling for -priority=N argument.
108 if %__Priority% GTR 0 (
109     set "__PriorityArg=/p:CLRTestPriorityToBuild=%__Priority%"
110 )
111
112 set TargetsWindowsArg=
113 set TargetsWindowsMsbuildArg=
114 if "%__TargetsWindows%"=="1" (
115     set TargetsWindowsArg=-TargetsWindows=true
116     set TargetsWindowsMsbuildArg=/p:TargetsWindows=true
117 ) else if "%__TargetsWindows%"=="0" (
118     set TargetsWindowsArg=-TargetsWindows=false
119     set TargetsWindowsMsbuildArg=/p:TargetsWindows=false
120 )
121
122 @if defined _echo @echo on
123
124 set __CommonMSBuildArgs=/p:__BuildOS=%__BuildOS% /p:__BuildType=%__BuildType% /p:__BuildArch=%__BuildArch%
125 REM As we move from buildtools to arcade, __RunArgs should be replaced with __msbuildArgs
126 set __msbuildArgs=/p:__BuildOS=%__BuildOS% /p:__BuildType=%__BuildType% /p:__BuildArch=%__BuildArch% /nologo /verbosity:minimal /clp:Summary /maxcpucount
127
128 echo %__MsgPrefix%Commencing CoreCLR test build
129
130 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
131 set "__TestRootDir=%__RootBinDir%\tests"
132 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
133
134 REM We have different managed and native intermediate dirs because the managed bits will include
135 REM the configuration information deeper in the intermediates path.
136 REM These variables are used by the msbuild project files.
137
138 if not defined __TestIntermediateDir (
139     set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
140 )
141 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
142 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
143
144 REM Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
145 set "__CMakeBinDir=%__TestBinDir%"
146 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
147
148 if not exist "%__TestBinDir%"                   md "%__TestBinDir%"
149 if not exist "%__NativeTestIntermediatesDir%"   md "%__NativeTestIntermediatesDir%"
150 if not exist "%__ManagedTestIntermediatesDir%"  md "%__ManagedTestIntermediatesDir%"
151 if not exist "%__LogsDir%"                      md "%__LogsDir%"
152 if not exist "%__MsbuildDebugLogsDir%"          md "%__MsbuildDebugLogsDir%"
153
154 REM Set up the directory for MSBuild debug logs.
155 set MSBUILDDEBUGPATH=%__MsbuildDebugLogsDir%
156
157 echo %__MsgPrefix%Checking prerequisites
158
159 REM Eval the output from set-cmake-path.ps1
160 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\set-cmake-path.ps1"""') do %%a
161
162 REM =========================================================================================
163 REM ===
164 REM === Restore Build Tools
165 REM ===
166 REM =========================================================================================
167
168 call "%__ProjectDir%\init-tools.cmd"
169 @if defined _echo @echo on
170
171 set "__ToolsDir=%__ProjectDir%\Tools"
172
173 REM =========================================================================================
174 REM ===
175 REM === Resolve runtime dependences
176 REM ===
177 REM =========================================================================================
178
179 call "%__TestDir%\setup-stress-dependencies.cmd" /arch %__BuildArch% /outputdir %__BinDir%
180 @if defined _echo @echo on
181
182 REM =========================================================================================
183 REM ===
184 REM === Native test build section
185 REM ===
186 REM =========================================================================================
187
188 if defined __SkipNative goto skipnative
189
190 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
191
192 REM Set the environment for the native build
193 set __VCBuildArch=x86_amd64
194 if /i "%__BuildArch%" == "x86" ( set __VCBuildArch=x86 )
195 if /i "%__BuildArch%" == "arm" ( set __VCBuildArch=x86_arm )
196 if /i "%__BuildArch%" == "arm64" ( set __VCBuildArch=x86_arm64 )
197
198 echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" %__VCBuildArch%
199 call                                 "%__VCToolsRoot%\vcvarsall.bat" %__VCBuildArch%
200 @if defined _echo @echo on
201
202 if not defined VSINSTALLDIR (
203     echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
204     exit /b 1
205 )
206 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
207
208 pushd "%__NativeTestIntermediatesDir%"
209 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" ""%__ProjectFilesDir%"" %__VSVersion% %__BuildArch%
210 @if defined _echo @echo on
211 popd
212
213 if not exist "%__NativeTestIntermediatesDir%\install.vcxproj" (
214     echo %__MsgPrefix%Failed to generate test native component build project!
215     exit /b 1
216 )
217
218 set __BuildLogRootName=Tests_Native
219 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
220 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
221 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
222 set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
223 set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
224 set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
225 set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr!
226
227 call "%__ProjectDir%\cmake_msbuild.cmd" /nologo /verbosity:minimal /clp:Summary /nodeReuse:false^
228   /l:BinClashLogger,Tools/net46/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log^
229   /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true^
230   /p:UsePartialNGENOptimization=false /maxcpucount^
231   "%__NativeTestIntermediatesDir%\install.vcxproj"^
232   !__Logging! /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% %__CommonMSBuildArgs% %__PriorityArg% %__UnprocessedBuildArgs%
233 if errorlevel 1 (
234     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
235     echo     %__BuildLog%
236     echo     %__BuildWrn%
237     echo     %__BuildErr%
238     exit /b 1
239 )
240
241 :skipnative
242
243 REM =========================================================================================
244 REM ===
245 REM === Restore product binaries from packages
246 REM ===
247 REM =========================================================================================
248
249 if "%__SkipRestorePackages%" == 1 goto SkipRestoreProduct
250
251 echo %__MsgPrefix%Restoring CoreCLR product from packages
252
253 if not defined XunitTestBinBase set XunitTestBinBase=%__TestBinDir%
254 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
255
256 set __BuildLogRootName=Restore_Product
257 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
258 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
259 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
260 set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
261 set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
262 set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
263 set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr!
264
265 call "%__ProjectDir%\dotnet.cmd" msbuild /nologo /verbosity:minimal /clp:Summary /nodeReuse:false^
266   /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log^
267   /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true^
268   /p:UsePartialNGENOptimization=false /maxcpucount^
269   %__ProjectDir%\tests\build.proj /t:BatchRestorePackages^
270   !__Logging! %__CommonMSBuildArgs% %__PriorityArg% %__UnprocessedBuildArgs%
271
272 :SkipRestoreProduct
273
274 REM =========================================================================================
275 REM ===
276 REM === Managed test build section
277 REM ===
278 REM =========================================================================================
279
280 if defined __SkipManaged goto SkipManagedBuild
281
282 echo %__MsgPrefix%Starting the Managed Tests Build
283
284 if not defined VSINSTALLDIR (
285     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.
286     exit /b 1
287 )
288 set __AppendToLog=false
289 set __BuildLogRootName=Tests_Managed
290 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
291 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
292 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
293
294 REM Execute msbuild test build in stages - workaround for excessive data retention in MSBuild ConfigCache
295 REM See https://github.com/Microsoft/msbuild/issues/2993
296
297 set __SkipPackageRestore=false
298 set __SkipTargetingPackBuild=false
299 set __NumberOfTestGroups=3
300
301 if %__Priority% GTR 0 (set __NumberOfTestGroups=10)
302 echo %__MsgPrefix%Building tests divided into %__NumberOfTestGroups% test groups
303
304 for /l %%G in (1, 1, %__NumberOfTestGroups%) do (
305
306     set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%";Append=!__AppendToLog!
307     set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%";Append=!__AppendToLog!
308     set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%";Append=!__AppendToLog!
309
310     set __TestGroupToBuild=%%G
311     echo Running: msbuild %__ProjectDir%\tests\build.proj !__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! %TargetsWindowsMsbuildArg% %__msbuildArgs% !__PriorityArg! %__UnprocessedBuildArgs%
312
313     call "%__ProjectDir%\dotnet.cmd" msbuild %__ProjectDir%\tests\build.proj !__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! %TargetsWindowsMsbuildArg% %__msbuildArgs% !__PriorityArg! %__UnprocessedBuildArgs%
314
315     if errorlevel 1 (
316         echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
317         echo     %__BuildLog%
318         echo     %__BuildWrn%
319         echo     %__BuildErr%
320         REM This is necessary because of a(n apparent) bug in the FOR /L command.  Under certain circumstances,
321         REM such as when this script is invoke with CMD /C "build-test.cmd", a non-zero exit directly from
322         REM within the loop body will not propagate to the caller.  For some reason, goto works around it.
323         goto     :Exit_Failure
324     )
325
326     set __SkipPackageRestore=true
327     set __SkipTargetingPackBuild=true
328     set __AppendToLog=true
329 )
330
331 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
332 REM drastically fewer Pri-1 tests than expected.
333 echo %__MsgPrefix%Check the managed tests build
334 echo Running: dotnet msbuild %__ProjectDir%\tests\runtest.proj /t:CheckTestBuild /p:CLRTestPriorityToBuild=%__Priority% %__msbuildArgs% %__unprocessedBuildArgs%
335 call "%__ProjectDir%\dotnet.cmd" msbuild %__ProjectDir%\tests\runtest.proj /t:CheckTestBuild /p:CLRTestPriorityToBuild=%__Priority% %__msbuildArgs% %__unprocessedBuildArgs%
336 if errorlevel 1 (
337     echo %__MsgPrefix%Error: build failed.
338     exit /b 1
339 )
340
341 :SkipManagedBuild
342
343 REM =========================================================================================
344 REM ===
345 REM === Prepare the test drop
346 REM ===
347 REM =========================================================================================
348
349 echo %__MsgPrefix%Removing 'ni' files and 'lock' folders from %__TestBinDir%
350 REM Remove any NI from previous runs.
351 powershell -NoProfile "Get-ChildItem -path %__TestBinDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
352 REM Remove any lock folder used for synchronization from previous runs.
353 powershell -NoProfile "Get-ChildItem -path %__TestBinDir% -Include 'lock' -Recurse -Force |  where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
354
355 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
356 set CORE_ROOT_STAGE=%__TestBinDir%\Tests\Core_Root_Stage
357 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
358 if exist "%CORE_ROOT_STAGE%" rd /s /q "%CORE_ROOT_STAGE%"
359 md "%CORE_ROOT%"
360 md "%CORE_ROOT_STAGE%"
361 xcopy "%__BinDir%" "%CORE_ROOT_STAGE%"
362
363 REM =========================================================================================
364 REM ===
365 REM === Create the test overlay
366 REM ===
367 REM =========================================================================================
368
369 echo %__MsgPrefix%Creating test overlay
370
371 set RuntimeIdArg=
372 if defined __RuntimeId (
373     set RuntimeIdArg=/p:RuntimeId="%__RuntimeId%"
374 )
375
376 set __BuildLogRootName=Tests_Overlay_Managed
377 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
378 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
379 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
380 set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
381 set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
382 set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
383 set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr!
384
385 call %__ProjectDir%\dotnet.cmd msbuild /nologo /verbosity:minimal /clp:Summary /nodeReuse:false^
386   /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log^
387   /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true^
388   /p:UsePartialNGENOptimization=false /maxcpucount^
389   %__ProjectDir%\tests\runtest.proj /t:CreateTestOverlay^
390   !__Logging! %__CommonMSBuildArgs% %RuntimeIdArg% %__PriorityArg% %__UnprocessedBuildArgs%
391 if errorlevel 1 (
392     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
393     echo     %__BuildLog%
394     echo     %__BuildWrn%
395     echo     %__BuildErr%
396     exit /b 1
397 )
398
399 xcopy /s /y "%CORE_ROOT_STAGE%" "%CORE_ROOT%"
400
401 REM =========================================================================================
402 REM ===
403 REM === Create the test host necessary for running CoreFX tests.
404 REM === The test host includes a dotnet executable, system libraries and CoreCLR assemblies found in CORE_ROOT.
405 REM ===
406 REM =========================================================================================
407
408 echo %__MsgPrefix%Building CoreFX test host
409
410 set __BuildLogRootName=Tests_CoreFX_Testhost
411 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
412 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
413 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
414 set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
415 set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
416 set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
417 set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr!
418
419 call %__ProjectDir%\dotnet.cmd msbuild /nologo /verbosity:minimal /clp:Summary /nodeReuse:false^
420   /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log^
421   /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true^
422   /p:UsePartialNGENOptimization=false /maxcpucount^
423   %__ProjectDir%\tests\runtest.proj /t:CreateTestHost^
424   !__Logging! %__CommonMSBuildArgs% %RuntimeIdArg% %__PriorityArg% %__UnprocessedBuildArgs%
425 if errorlevel 1 (
426     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
427     echo     %__BuildLog%
428     echo     %__BuildWrn%
429     echo     %__BuildErr%
430     exit /b 1
431 )
432
433 REM =========================================================================================
434 REM ===
435 REM === Create test wrappers.
436 REM ===
437 REM =========================================================================================
438
439 if defined __SkipManaged goto SkipBuildingWrappers
440
441 echo %__MsgPrefix%Creating test wrappers
442
443 set __BuildLogRootName=Tests_XunitWrapper
444 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
445 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
446 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
447 set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
448 set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
449 set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
450 set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr!
451
452 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.
453 call "%__ProjectDir%\dotnet.cmd" msbuild %__ProjectDir%\tests\runtest.proj /p:RestoreAdditionalProjectSources=https://dotnet.myget.org/F/dotnet-core/  /p:BuildWrappers=true !__Logging! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__UnprocessedBuildArgs%
454 if errorlevel 1 (
455     echo %__MsgPrefix%Error: Xunit wrapper build failed. Refer to the build log files for details:
456     echo     %__BuildLog%
457     echo     %__BuildWrn%
458     echo     %__BuildErr%
459     exit /b 1
460 )
461
462 echo { "build_os": "%__BuildOS%", "build_arch": "%__BuildArch%", "build_type": "%__BuildType%" } > "%__TestBinDir%/build_info.json"
463
464 :SkipBuildingWrappers
465
466 REM =========================================================================================
467 REM ===
468 REM === Crossgen assemblies if needed.
469 REM ===
470 REM =========================================================================================
471
472 set __CrossgenArg = ""
473 if defined __DoCrossgen (
474     set __CrossgenArg="/p:Crossgen=true"
475     if "%__TargetsWindows%" == "1" (
476         echo %__MsgPrefix%Running crossgen on framework assemblies
477         call :PrecompileFX
478     ) else (
479         echo "%__MsgPrefix%Crossgen only supported on Windows, for now"
480     )
481 )
482
483 rd /s /q "%CORE_ROOT_STAGE%"
484
485 REM =========================================================================================
486 REM ===
487 REM === All builds complete!
488 REM ===
489 REM =========================================================================================
490
491 echo %__MsgPrefix%Test build succeeded.  Finished at %TIME%
492 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
493 exit /b 0
494
495 :Usage
496 echo.
497 echo Build the CoreCLR tests.
498 echo.
499 echo Usage:
500 echo     %0 [option1] [option2] ...
501 echo All arguments are optional. Options are case-insensitive. The options are:
502 echo.
503 echo.-? -h -help --help: view this message.
504 echo Build architecture: one of x64, x86, arm, arm64 ^(default: x64^).
505 echo Build type: one of Debug, Checked, Release ^(default: Debug^).
506 echo skipmanaged: skip the managed tests build
507 echo skipnative: skip the native tests build
508 echo buildtesthostonly: build the CoreFX testhost only
509 echo skiprestorepackages: skip package restore
510 echo runtimeid ^<ID^>: Builds a test overlay for the specified OS ^(Only supported when building against packages^). Supported IDs are:
511 echo     alpine.3.4.3-x64: Builds overlay for Alpine 3.4.3
512 echo     debian.8-x64: Builds overlay for Debian 8
513 echo     fedora.24-x64: Builds overlay for Fedora 24
514 echo     linux-x64: Builds overlay for portable linux
515 echo     opensuse.42.1-x64: Builds overlay for OpenSUSE 42.1
516 echo     osx.10.12-x64: Builds overlay for OSX 10.12
517 echo     osx-x64: Builds overlay for portable OSX
518 echo     rhel.7-x64: Builds overlay for RHEL 7 or CentOS
519 echo     ubuntu.14.04-x64: Builds overlay for Ubuntu 14.04
520 echo     ubuntu.16.04-x64: Builds overlay for Ubuntu 16.04
521 echo     ubuntu.16.10-x64: Builds overlay for Ubuntu 16.10
522 echo     win-x64: Builds overlay for portable Windows
523 echo     win7-x64: Builds overlay for Windows 7
524 echo crossgen: Precompiles the framework managed assemblies
525 echo targetsNonWindows:
526 echo Exclude- Optional parameter - specify location of default exclusion file ^(defaults to tests\issues.targets if not specified^)
527 echo     Set to "" to disable default exclusion file.
528 echo -- ... : all arguments following this tag will be passed directly to msbuild.
529 echo -priority=^<N^> : specify a set of tests that will be built and run, with priority N.
530 echo     0: Build only priority 0 cases as essential testcases (default)
531 echo     1: Build all tests with priority 0 and 1
532 echo     666: Build all tests with priority 0, 1 ... 666
533 echo -verbose: enables detailed file logging for the msbuild tasks into the msbuild log file.
534 exit /b 1
535
536 :NoDIA
537 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
538 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
539 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
540 of the previous version to "%VSINSTALLDIR%" and then build.
541 REM DIA SDK not included in Express editions
542 echo Visual Studio Express does not include the DIA SDK. ^
543 You need Visual Studio 2017 or 2019 (Community is free).
544 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
545 exit /b 1
546
547 :PrecompileFX
548 for %%F in (%CORE_ROOT%\*.dll) do call :PrecompileAssembly "%%F" %%~nF%%~xF
549 exit /b 0
550
551 REM Compile the managed assemblies in Core_ROOT before running the tests
552 :PrecompileAssembly
553
554 REM Skip mscorlib since it is already precompiled.
555 if /I "%2" == "mscorlib.dll" exit /b 0
556 if /I "%2" == "mscorlib.ni.dll" exit /b 0
557 REM don't precompile anything from CoreCLR
558 if /I exist %CORE_ROOT_STAGE%\%2 exit /b 0
559
560 REM Don't precompile xunit.* files
561 echo "%2" | findstr /b "xunit." >nul && (
562   exit /b 0
563 )
564
565 "%CORE_ROOT_STAGE%\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" /in "%1" /out "%CORE_ROOT%/temp.ni.dll" >nul 2>nul
566 set /a __exitCode = %errorlevel%
567 if "%__exitCode%" == "-2146230517" (
568     echo %2 is not a managed assembly.
569     exit /b 0
570 )
571
572 if %__exitCode% neq 0 (
573     echo Unable to precompile %2
574     exit /b 0
575 )
576
577 REM Delete original .dll & replace it with the Crossgened .dll
578 del %1
579 ren "%CORE_ROOT%\temp.ni.dll" %2
580     
581 echo Successfully precompiled %2
582 exit /b 0
583
584 :Exit_Failure
585 exit /b 1