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