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