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