Break current culture initialization cycle (#15938)
[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 :: Define a prefix for most output progress messages that come from this script. That makes
11 :: it easier to see where these are coming from. Note that there is a trailing space here.
12 set "__MsgPrefix=BUILDTEST: "
13
14 :: Default to highest Visual Studio version available
15 ::
16 :: For VS2015 (and prior), only a single instance is allowed to be installed on a box
17 :: and VS140COMNTOOLS is set as a global environment variable by the installer. This
18 :: allows users to locate where the instance of VS2015 is installed.
19 ::
20 :: For VS2017, multiple instances can be installed on the same box SxS and VS150COMNTOOLS
21 :: is no longer set as a global environment variable and is instead only set if the user
22 :: has launched the VS2017 Developer Command Prompt.
23 ::
24 :: Following this logic, we will default to the VS2017 toolset if VS150COMNTOOLS tools is
25 :: set, as this indicates the user is running from the VS2017 Developer Command Prompt and
26 :: is already configured to use that toolset. Otherwise, we will fallback to using the VS2015
27 :: toolset if it is installed. Finally, we will fail the script if no supported VS instance
28 :: can be found.
29 if defined VisualStudioVersion ( 
30     if not defined __VSVersion echo %__MsgPrefix%Detected Visual Studio %VisualStudioVersion% developer command ^prompt environment
31     goto Run
32 )
33
34 set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
35 if exist %_VSWHERE% (
36   for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools
37 )
38 if not exist "%_VSCOMNTOOLS%" set _VSCOMNTOOLS=%VS140COMNTOOLS%
39 if not exist "%_VSCOMNTOOLS%" (
40   echo %__MsgPrefix%Error: Visual Studio 2015 or 2017 required.
41   echo        Please see https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/developer-guide.md for build instructions.
42   exit /b 1
43 )
44
45 call "%_VSCOMNTOOLS%\VsDevCmd.bat"
46
47 :Run
48
49 if defined VS150COMNTOOLS (
50   set "__VSToolsRoot=%VS150COMNTOOLS%"
51   set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
52   set __VSVersion=vs2017
53 ) else (
54   set "__VSToolsRoot=%VS140COMNTOOLS%"
55   set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC"
56   set __VSVersion=vs2015
57 )
58
59 set "__ProjectDir=%~dp0"
60 :: remove trailing slash
61 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
62 set "__TestDir=%__ProjectDir%\tests"
63 set "__ProjectFilesDir=%__TestDir%"
64 set "__SourceDir=%__ProjectDir%\src"
65 set "__PackagesDir=%__ProjectDir%\packages"
66 set "__RootBinDir=%__ProjectDir%\bin"
67 set "__LogsDir=%__RootBinDir%\Logs"
68
69 :: Default __Exclude to issues.targets
70 set __Exclude=%__TestDir%\issues.targets
71
72 REM __unprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
73 set "__args= %*"
74 set processedArgs=
75 set __unprocessedBuildArgs=
76 set __RunArgs=
77 set __BuildAgainstPackagesArg=
78 set __RuntimeId=
79 set __ZipTests=
80 set __TargetsWindows=1
81 set __DoCrossgen=
82
83 :Arg_Loop
84 if "%1" == "" goto ArgsDone
85
86 if /i "%1" == "-?"    goto Usage
87 if /i "%1" == "-h"    goto Usage
88 if /i "%1" == "-help" goto Usage
89
90 if /i "%1" == "x64"                   (set __BuildArch=x64&set __VCBuildArch=x86_amd64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
91 if /i "%1" == "x86"                   (set __BuildArch=x86&set __VCBuildArch=x86&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
92 if /i "%1" == "arm"                   (set __BuildArch=arm&set __VCBuildArch=x86_arm&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
93 if /i "%1" == "arm64"                 (set __BuildArch=arm64&set __VCBuildArch=x86_arm64&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
94
95 if /i "%1" == "debug"                 (set __BuildType=Debug&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
96 if /i "%1" == "release"               (set __BuildType=Release&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
97 if /i "%1" == "checked"               (set __BuildType=Checked&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
98
99 if /i "%1" == "skipmanaged"           (set __SkipManaged=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
100 if /i "%1" == "toolset_dir"           (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
101 if /i "%1" == "buildagainstpackages"  (set __ZipTests=1&set __BuildAgainstPackagesArg=-BuildTestsAgainstPackages&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
102 if /i "%1" == "ziptests"              (set __ZipTests=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
103 if /i "%1" == "crossgen"              (set __DoCrossgen=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
104 if /i "%1" == "runtimeid"             (set __RuntimeId=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
105 if /i "%1" == "targetsNonWindows"     (set __TargetsWindows=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
106 if /i "%1" == "Exclude"               (set __Exclude=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
107
108 if [!processedArgs!]==[] (
109   set __UnprocessedBuildArgs=%__args%
110 ) else (
111   set __UnprocessedBuildArgs=%__args%
112   for %%t in (!processedArgs!) do (
113     set __UnprocessedBuildArgs=!__UnprocessedBuildArgs:*%%t=!
114   )
115 )
116
117 :ArgsDone
118
119 if defined __BuildAgainstPackagesArg (
120     if not defined __RuntimeID (
121         echo %__MsgPrefix%Error: When building against packages, you must supply a target Runtime ID.
122         exit /b 1
123     )
124 )
125
126 @if defined _echo @echo on
127
128 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
129
130 if defined __ToolsetDir (
131     rem arm64 builds currently use private toolset which has not been released yet
132     REM TODO, remove once the toolset is open.
133     call :PrivateToolSet
134 )
135
136 echo %__MsgPrefix%Commencing CoreCLR repo test build
137
138 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
139 set "__TestRootDir=%__RootBinDir%\tests"
140 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
141 :: We have different managed and native intermediate dirs because the managed bits will include
142 :: the configuration information deeper in the intermediates path.
143 :: These variables are used by the msbuild project files.
144
145 if not defined __TestIntermediateDir (
146     set "__TestIntermediateDir=tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
147 )
148 set "__NativeTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Native"
149 set "__ManagedTestIntermediatesDir=%__RootBinDir%\%__TestIntermediateDir%\Managed"
150
151 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
152 set "__CMakeBinDir=%__TestBinDir%"
153 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
154
155 if not exist "%__TestBinDir%"                   md "%__TestBinDir%"
156 if not exist "%__NativeTestIntermediatesDir%"   md "%__NativeTestIntermediatesDir%"
157 if not exist "%__ManagedTestIntermediatesDir%"  md "%__ManagedTestIntermediatesDir%"
158 if not exist "%__LogsDir%"                      md "%__LogsDir%"
159
160 echo %__MsgPrefix%Checking prerequisites
161
162 :: Eval the output from probe-win1.ps1
163 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
164
165 REM =========================================================================================
166 REM ===
167 REM === Restore Build Tools
168 REM ===
169 REM =========================================================================================
170 call "%__ProjectDir%\init-tools.cmd"
171 @if defined _echo @echo on
172
173 REM =========================================================================================
174 REM ===
175 REM === Resolve runtime dependences
176 REM ===
177 REM =========================================================================================
178
179 call "%__TestDir%\setup-stress-dependencies.cmd" /arch %__BuildArch% /outputdir %__BinDir%
180 @if defined _echo @echo on
181
182 REM =========================================================================================
183 REM ===
184 REM === Native test build section
185 REM ===
186 REM =========================================================================================
187
188 echo %__MsgPrefix%Commencing build of native test components for %__BuildArch%/%__BuildType%
189
190 if defined __ToolsetDir (
191     echo %__MsgPrefix%ToolsetDir is defined to be %__ToolsetDir%
192     goto GenVSSolution :: Private ToolSet is Defined
193 )
194
195 :: Set the environment for the native build
196 echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" %__VCBuildArch%
197 call                                 "%__VCToolsRoot%\vcvarsall.bat" %__VCBuildArch%
198 @if defined _echo @echo on
199
200 if not defined VSINSTALLDIR (
201     echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
202     exit /b 1
203 )
204 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
205
206 :GenVSSolution
207
208 pushd "%__NativeTestIntermediatesDir%"
209 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" ""%__ProjectFilesDir%"" %__VSVersion% %__BuildArch%
210 @if defined _echo @echo on
211 popd
212
213 if not exist "%__NativeTestIntermediatesDir%\install.vcxproj" (
214     echo %__MsgPrefix%Failed to generate test native component build project!
215     exit /b 1
216 )
217
218 set __msbuildNativeArgs=-configuration=%__BuildType%
219
220 if defined __ToolsetDir (
221     set __msbuildNativeArgs=%__msbuildNativeArgs% -UseEnv
222 ) else (
223     set __msbuildNativeArgs=%__msbuildNativeArgs% -platform=%__BuildArch%
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
234 call "%__ProjectDir%\run.cmd" build -Project="%__NativeTestIntermediatesDir%\install.vcxproj" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__msbuildNativeArgs% %__RunArgs% %__unprocessedBuildArgs%
235 if errorlevel 1 (
236     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
237     echo     %__BuildLog%
238     echo     %__BuildWrn%
239     echo     %__BuildErr%
240     exit /b 1
241 )
242
243 :skipnative
244
245 set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
246
247 if not defined __BuildAgainstPackagesArg 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% %__unprocessedBuildArgs%
266
267 set __BuildLogRootName=Tests_GenerateRuntimeLayout
268 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
269 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
270 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
271 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
272 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
273 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
274
275 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\runtest.proj -BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct -RuntimeId="%__RuntimeId%" -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
276 if errorlevel 1 (
277     echo BinPlace of mscorlib.dll failed
278     exit /b 1
279 )
280
281 echo %__MsgPrefix% Restored CoreCLR product from packages
282
283 :SkipRestoreProduct
284
285 if defined __SkipManaged exit /b 0
286
287 REM =========================================================================================
288 REM ===
289 REM === Managed test build section
290 REM ===
291 REM =========================================================================================
292
293 echo %__MsgPrefix%Starting the Managed Tests Build
294
295 if not defined VSINSTALLDIR (
296     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.
297     exit /b 1
298 )
299
300 set __BuildLogRootName=Tests_Managed
301 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
302 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
303 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
304 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
305 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
306 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
307
308 call "%__ProjectDir%\run.cmd" build -Project=%__ProjectDir%\tests\build.proj -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %__unprocessedBuildArgs%
309 if errorlevel 1 (
310     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
311     echo     %__BuildLog%
312     echo     %__BuildWrn%
313     echo     %__BuildErr%
314     exit /b 1
315 )
316
317 REM Prepare the Test Drop
318 REM Cleans any NI from the last run
319 powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
320 REM Cleans up any lock folder used for synchronization from last run
321 powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force |  where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
322
323 set CORE_ROOT=%__TestBinDir%\Tests\Core_Root
324 set CORE_ROOT_STAGE=%__TestBinDir%\Tests\Core_Root_Stage
325 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
326 if exist "%CORE_ROOT_STAGE%" rd /s /q "%CORE_ROOT_STAGE%"
327 md "%CORE_ROOT%"
328 md "%CORE_ROOT_STAGE%"
329 xcopy "%__BinDir%" "%CORE_ROOT_STAGE%"
330
331
332 if defined __BuildAgainstPackagesArg ( 
333   if "%__TargetsWindows%"=="0" (
334
335     if not exist %__PackagesDir%\TestNativeBins (
336         echo %__MsgPrefix%Error: Ensure you have run sync.cmd -ab before building a non-Windows test overlay against packages
337         exit /b 1
338     )
339
340     for /R %__PackagesDir%\TestNativeBins\%__RuntimeId%\%__BuildType% %%f in (*.so) do copy %%f %CORE_ROOT_STAGE%
341     for /R %__PackagesDir%\TestNativeBins\%__RuntimeId%\%__BuildType% %%f in (*.dylib) do copy %%f %CORE_ROOT_STAGE%
342   )
343 )
344
345 echo %__MsgPrefix%Creating test wrappers...
346
347 set RuntimeIdArg=
348 set TargetsWindowsArg=
349
350 if defined __RuntimeId (
351     set RuntimeIdArg=-RuntimeID="%__RuntimeId%"
352 )
353
354 if "%__TargetsWindows%"=="1" (
355     set TargetsWindowsArg=-TargetsWindows=true
356 ) else if "%__TargetsWindows%"=="0" (
357     set TargetsWindowsArg=-TargetsWindows=false
358 )
359
360 set __BuildLogRootName=Tests_XunitWrapper
361 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
362 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
363 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
364 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
365 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
366 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
367
368 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\runtest.proj -BuildWrappers -MsBuildEventLogging=" " -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %TargetsWindowsArg% %__unprocessedBuildArgs%
369 if errorlevel 1 (
370     echo Xunit Wrapper build failed
371     exit /b 1
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 set __CrossgenArg = ""
396 if defined __DoCrossgen (
397   set __CrossgenArg="-Crossgen"
398   if "%__TargetsWindows%" == "1" (
399     call :PrecompileFX
400   ) else (
401     echo "%__MsgPrefix% Crossgen only supported on Windows, for now"
402   )
403 )
404
405 rd /s /q "%CORE_ROOT_STAGE%"
406
407 if not defined __ZipTests goto SkipPrepForPublish
408
409 set __BuildLogRootName=Helix_Prep
410 set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log
411 set __BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn
412 set __BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err
413 set __msbuildLog=/flp:Verbosity=normal;LogFile="%__BuildLog%"
414 set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
415 set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
416
417 REM =========================================================================================
418 REM ===
419 REM === Prep test binaries for Helix publishing
420 REM ===
421 REM =========================================================================================
422
423 call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\tests\helixprep.proj  -MsBuildLog=!__msbuildLog! -MsBuildWrn=!__msbuildWrn! -MsBuildErr=!__msbuildErr! %__RunArgs% %__BuildAgainstPackagesArg% %RuntimeIdArg% %TargetsWindowsArg% %__CrossgenArg% %__unprocessedBuildArgs%
424 if errorlevel 1 (
425     echo %__MsgPrefix%Error: build failed. Refer to the build log files for details:
426     echo     %__BuildLog%
427     echo     %__BuildWrn%
428     echo     %__BuildErr%
429     exit /b 1
430 )
431
432 echo %__MsgPrefix% Prepped test binaries for publishing
433
434 :SkipPrepForPublish
435
436 REM =========================================================================================
437 REM ===
438 REM === All builds complete!
439 REM ===
440 REM =========================================================================================
441
442 echo %__MsgPrefix%Test build successful.
443 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
444 exit /b 0
445
446 :Usage
447 echo.
448 echo Usage:
449 echo     %0 [option1] [option2] ...
450 echo All arguments are optional. Options are case-insensitive. The options are:
451 echo.
452 echo. -? -h -help: view this message.
453 echo Build architecture: -buildArch: only x64 is currently allowed ^(default: x64^).
454 echo Build type: -buildType: one of Debug, Checked, Release ^(default: Debug^).
455 echo buildagainstpackages: builds tests against restored packages, instead of against a built product.
456 echo runtimeid ^<ID^>: Builds a test overlay for the specified OS (Only supported when building against packages). Supported IDs are:
457 echo     alpine.3.4.3-x64: Builds overlay for Alpine 3.4.3
458 echo     debian.8-x64: Builds overlay for Debian 8
459 echo     fedora.24-x64: Builds overlay for Fedora 24
460 echo     linux-x64: Builds overlay for portable linux
461 echo     opensuse.42.1-x64: Builds overlay for OpenSUSE 42.1
462 echo     osx.10.12-x64: Builds overlay for OSX 10.12
463 echo     osx-x64: Builds overlay for portable OSX
464 echo     rhel.7-x64: Builds overlay for RHEL 7 or CentOS
465 echo     ubuntu.14.04-x64: Builds overlay for Ubuntu 14.04
466 echo     ubuntu.16.04-x64: Builds overlay for Ubuntu 16.04
467 echo     ubuntu.16.10-x64: Builds overlay for Ubuntu 16.10
468 echo     win-x64: Builds overlay for portable Windows
469 echo     win7-x64: Builds overlay for Windows 7
470 echo ziptests: zips CoreCLR tests & Core_Root for a Helix run
471 echo crossgen: Precompiles the framework managed assemblies
472 echo Exclude- Optional parameter - specify location of default exclusion file (defaults to tests\issues.targets if not specified)
473 echo     Set to "" to disable default exclusion file.
474 echo -- ... : all arguments following this tag will be passed directly to msbuild.
475 echo -priority=^<N^> : specify a set of test that will be built and run, with priority N.
476 echo     0: Build only priority 0 cases as essential testcases (default)
477 echo     1: Build all tests with priority 0 and 1
478 echo     666: Build all tests with priority 0, 1 ... 666
479 echo -verbose: enables detailed file logging for the msbuild tasks into the msbuild log file.
480 exit /b 1
481
482 :NoDIA
483 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
484 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
485 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
486 of the previous version to "%VSINSTALLDIR%" and then build.
487 :: DIA SDK not included in Express editions
488 echo Visual Studio Express does not include the DIA SDK. ^
489 You need Visual Studio 2015 or 2017 (Community is free).
490 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
491 exit /b 1
492
493
494 :PrivateToolSet
495
496 echo %__MsgPrefix%Setting up the usage of __ToolsetDir:%__ToolsetDir%
497
498 if /i "%__ToolsetDir%" == "" (
499     echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
500     exit /b 1
501 )
502
503 if not exist "%__ToolsetDir%"\buildenv_arm64.cmd goto :Not_EWDK
504 call "%__ToolsetDir%"\buildenv_arm64.cmd
505 exit /b 0
506
507 :Not_EWDK
508 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
509 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
510 set INCLUDE=^
511 %__ToolsetDir%\VC_sdk\inc;^
512 %__ToolsetDir%\sdpublic\sdk\inc;^
513 %__ToolsetDir%\sdpublic\shared\inc;^
514 %__ToolsetDir%\sdpublic\shared\inc\minwin;^
515 %__ToolsetDir%\sdpublic\sdk\inc\ucrt;^
516 %__ToolsetDir%\sdpublic\sdk\inc\minwin;^
517 %__ToolsetDir%\sdpublic\sdk\inc\mincore;^
518 %__ToolsetDir%\sdpublic\sdk\inc\abi;^
519 %__ToolsetDir%\sdpublic\sdk\inc\clientcore;^
520 %__ToolsetDir%\diasdk\include
521 exit /b 0
522
523 :PrecompileFX
524 for %%F in (%CORE_ROOT%\*.dll) do call :PrecompileAssembly "%%F" %%~nF%%~xF
525 exit /b 0
526
527 REM Compile the managed assemblies in Core_ROOT before running the tests
528 :PrecompileAssembly
529
530 REM Skip mscorlib since it is already precompiled.
531 if /I "%2" == "mscorlib.dll" exit /b 0
532 if /I "%2" == "mscorlib.ni.dll" exit /b 0
533 REM don't precompile anything from CoreCLR
534 if /I exist %CORE_ROOT_STAGE%\%2 exit /b 0
535
536 "%CORE_ROOT_STAGE%\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" /in "%1" /out "%CORE_ROOT%/temp.ni.dll" >nul 2>nul
537 set /a __exitCode = %errorlevel%
538 if "%__exitCode%" == "-2146230517" (
539     echo %2 is not a managed assembly.
540     exit /b 0
541 )
542
543 if %__exitCode% neq 0 (
544     echo Unable to precompile %2
545     exit /b 0
546 )
547
548 :: Delete original .dll & replace it with the Crossgened .dll
549 del %1
550 ren "%CORE_ROOT%\temp.ni.dll" %2
551     
552 echo Successfully precompiled %2
553 exit /b 0