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