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