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