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