Merge pull request #4041 from erozenfeld/gtTreeHasSideEffectsFix
[platform/upstream/coreclr.git] / build.cmd
1 @if not defined __echo @echo off
2 setlocal EnableDelayedExpansion EnableExtensions
3
4 set __ThisScriptShort=%0
5 set __ThisScriptFull="%~f0"
6 set __ThisScriptPath="%~dp0"
7
8 :: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set:
9 ::      __BuildArch         -- default: x64
10 ::      __BuildType         -- default: Debug
11 ::      __BuildOS           -- default: Windows_NT
12 ::      __ProjectDir        -- default: directory of the dir.props file
13 ::      __SourceDir         -- default: %__ProjectDir%\src\
14 ::      __PackagesDir       -- default: %__ProjectDir%\packages\
15 ::      __RootBinDir        -- default: %__ProjectDir%\bin\
16 ::      __BinDir            -- default: %__RootBinDir%\%__BuildOS%.%__BuildArch.%__BuildType%\
17 ::      __IntermediatesDir
18 ::      __PackagesBinDir    -- default: %__BinDir%\.nuget
19 ::      __TestWorkingDir    -- default: %__RootBinDir%\tests\%__BuildOS%.%__BuildArch.%__BuildType%\
20 ::
21 :: Thus, these variables are not simply internal to this script!
22 ::
23 :: The UseRoslynCompiler variable is used by src\mscorlib\GenerateCompilerResponseFile.targets.
24
25 :: Set the default arguments for build
26 set __BuildArch=x64
27 set __BuildType=Debug
28 set __BuildOS=Windows_NT
29
30 :: Default to highest Visual Studio version available
31 set __VSVersion=vs2015
32
33 if defined VS140COMNTOOLS set __VSVersion=vs2015
34
35 :: Define a prefix for most output progress messages that come from this script. That makes
36 :: it easier to see where these are coming from. Note that there is a trailing space here.
37 set __MsgPrefix=BUILD: 
38
39 :: Set the various build properties here so that CMake and MSBuild can pick them up
40 set "__ProjectDir=%~dp0"
41 :: remove trailing slash
42 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
43 set "__ProjectFilesDir=%__ProjectDir%"
44 set "__SourceDir=%__ProjectDir%\src"
45 set "__PackagesDir=%__ProjectDir%\packages"
46 set "__RootBinDir=%__ProjectDir%\bin"
47 set "__LogsDir=%__RootBinDir%\Logs"
48
49 set __CleanBuild=
50 set __MscorlibOnly=
51 set __ConfigureOnly=
52 set __SkipConfigure=
53 set __SkipMscorlibBuild=
54 set __SkipNativeBuild=
55 set __SkipTestBuild=
56 set __DoCrossgen=
57 set __BuildSequential=
58 set __msbuildCleanBuildArgs=
59 set __msbuildExtraArgs=
60 set __SignTypeReal=
61
62 set __BuildAll=
63
64 set __BuildArchX64=0
65 set __BuildArchX86=0
66 set __BuildArchArm=0
67 set __BuildArchArm64=0
68
69 set __BuildTypeDebug=0
70 set __BuildTypeChecked=0
71 set __BuildTypeRelease=0
72 set __GCStressLevel=0
73
74 REM __PassThroughArgs is a set of things that will be passed through to nested calls to build.cmd
75 REM when using "all".
76 set __PassThroughArgs=
77
78 :Arg_Loop
79 if "%1" == "" goto ArgsDone
80
81 if /i "%1" == "/?"    goto Usage
82 if /i "%1" == "-?"    goto Usage
83 if /i "%1" == "/h"    goto Usage
84 if /i "%1" == "-h"    goto Usage
85 if /i "%1" == "/help" goto Usage
86 if /i "%1" == "-help" goto Usage
87
88 if /i "%1" == "all"                 (set __BuildAll=1&shift&goto Arg_Loop)
89
90 if /i "%1" == "x64"                 (set __BuildArchX64=1&shift&goto Arg_Loop)
91 if /i "%1" == "x86"                 (set __BuildArchX86=1&shift&goto Arg_Loop)
92 if /i "%1" == "arm"                 (set __BuildArchArm=1&shift&goto Arg_Loop)
93 if /i "%1" == "arm64"               (set __BuildArchArm64=1&shift&goto Arg_Loop)
94
95 if /i "%1" == "debug"               (set __BuildTypeDebug=1&shift&goto Arg_Loop)
96 if /i "%1" == "checked"             (set __BuildTypeChecked=1&shift&goto Arg_Loop)
97 if /i "%1" == "release"             (set __BuildTypeRelease=1&shift&goto Arg_Loop)
98
99 REM All arguments after this point will be passed through directly to build.cmd on nested invocations
100 REM using the "all" argument, and must be added to the __PassThroughArgs variable.
101 set __PassThroughArgs=%__PassThroughArgs% %1
102
103 if /i "%1" == "clean"               (set __CleanBuild=1&shift&goto Arg_Loop)
104
105 if /i "%1" == "freebsdmscorlib"     (set __MscorlibOnly=1&set __BuildOS=FreeBSD&shift&goto Arg_Loop)
106 if /i "%1" == "linuxmscorlib"       (set __MscorlibOnly=1&set __BuildOS=Linux&shift&goto Arg_Loop)
107 if /i "%1" == "netbsdmscorlib"      (set __MscorlibOnly=1&set __BuildOS=NetBSD&shift&goto Arg_Loop)
108 if /i "%1" == "osxmscorlib"         (set __MscorlibOnly=1&set __BuildOS=OSX&shift&goto Arg_Loop)
109 if /i "%1" == "windowsmscorlib"     (set __MscorlibOnly=1&set __BuildOS=Windows_NT&shift&goto Arg_Loop)
110
111 if /i "%1" == "vs2015"              (set __VSVersion=%1&shift&goto Arg_Loop)
112 if /i "%1" == "configureonly"       (set __ConfigureOnly=1&set __SkipMscorlibBuild=1&set __SkipTestBuild=1&shift&goto Arg_Loop)
113 if /i "%1" == "skipconfigure"       (set __SkipConfigure=1&shift&goto Arg_Loop)
114 if /i "%1" == "skipmscorlib"        (set __SkipMscorlibBuild=1&shift&goto Arg_Loop)
115 if /i "%1" == "skipnative"          (set __SkipNativeBuild=1&shift&goto Arg_Loop)
116 if /i "%1" == "skiptests"           (set __SkipTestBuild=1&shift&goto Arg_Loop)
117 if /i "%1" == "docrossgen"          (set __DoCrossgen=1&shift&goto Arg_Loop)
118 if /i "%1" == "sequential"          (set __BuildSequential=1&shift&goto Arg_Loop)
119 if /i "%1" == "disableoss"          (set __SignTypeReal="/p:SignType=real"&shift&goto Arg_Loop)
120 if /i "%1" == "priority"            (set __TestPriority=%2&set __PassThroughArgs=%__PassThroughArgs% %2&shift&shift&goto Arg_Loop)
121 if /i "%1" == "gcstresslevel"       (set __GCStressLevel=%2&set __PassThroughArgs=%__PassThroughArgs% %2&shift&shift&goto Arg_Loop)
122
123 @REM For backwards compatibility, continue accepting "skiptestbuild", which was the original name of the option.
124 if /i "%1" == "skiptestbuild"       (set __SkipTestBuild=1&shift&goto Arg_Loop)
125
126 @REM It was initially /toolset_dir. Not sure why, since it doesn't match the other usage.
127 if /i "%1" == "/toolset_dir"        (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&shift&shift&goto Arg_Loop)
128 if /i "%1" == "toolset_dir"         (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&shift&shift&goto Arg_Loop)
129
130 if /i not "%1" == "msbuildargs" goto SkipMsbuildArgs
131 :: All the rest of the args will be collected and passed directly to msbuild.
132 :CollectMsbuildArgs
133 shift
134 if "%1"=="" goto ArgsDone
135 set __msbuildExtraArgs=%__msbuildExtraArgs% %1
136 set __PassThroughArgs=%__PassThroughArgs% %1
137 goto CollectMsbuildArgs
138 :SkipMsbuildArgs
139
140 echo Invalid command-line argument: %1
141 goto Usage
142
143 :ArgsDone
144
145 if defined __ConfigureOnly if defined __SkipConfigure (
146     echo "Error: option 'configureonly' is incompatible with 'skipconfigure'"
147     goto Usage
148 )
149
150 if defined __SkipMscorlibBuild if defined __MscorlibOnly (
151     echo Error: option 'skipmscorlib' is incompatible with 'freebsdmscorlib', 'linuxmscorlib', 'netbsdmscorlib', 'osxmscorlib' and 'windowsmscorlib'.
152     goto Usage
153 )
154
155 if defined __BuildAll goto BuildAll
156
157 set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
158 if %__TotalSpecifiedBuildArch% GTR 1 (
159     echo Error: more than one build architecture specified, but "all" not specified.
160     goto Usage
161 )
162
163 if %__BuildArchX64%==1      set __BuildArch=x64
164 if %__BuildArchX86%==1      set __BuildArch=x86
165 if %__BuildArchArm%==1      set __BuildArch=arm
166 if %__BuildArchArm64%==1    set __BuildArch=arm64
167
168 set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
169 if %__TotalSpecifiedBuildType% GTR 1 (
170     echo Error: more than one build type specified, but "all" not specified.
171     goto Usage
172 )
173
174 if %__BuildTypeDebug%==1    set __BuildType=Debug
175 if %__BuildTypeChecked%==1  set __BuildType=Checked
176 if %__BuildTypeRelease%==1  set __BuildType=Release
177
178 echo %__MsgPrefix%Commencing CoreCLR Repo build
179
180 :: Set the remaining variables based upon the determined build configuration
181 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
182 set "__IntermediatesDir=%__RootBinDir%\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
183 set "__PackagesBinDir=%__BinDir%\.nuget"
184 set "__TestRootDir=%__RootBinDir%\tests"
185 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
186 set "__TestIntermediatesDir=%__RootBinDir%\tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
187
188 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
189 set "__CMakeBinDir=%__BinDir%"
190 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
191
192 :: Configure environment if we are doing a clean build.
193 if not defined __CleanBuild goto SkipCleanBuild
194 echo %__MsgPrefix%Doing a clean build
195
196 :: MSBuild projects would need a rebuild
197 set __msbuildCleanBuildArgs=/t:rebuild
198
199 :: Cleanup the previous output for the selected configuration
200 if exist "%__BinDir%"               rd /s /q "%__BinDir%"
201 if exist "%__IntermediatesDir%"     rd /s /q "%__IntermediatesDir%"
202 if exist "%__TestBinDir%"           rd /s /q "%__TestBinDir%"
203 if exist "%__TestIntermediatesDir%" rd /s /q "%__TestIntermediatesDir%"
204 if exist "%__LogsDir%"              del /f /q "%__LogsDir%\*_%__BuildOS%__%__BuildArch%__%__BuildType%.*"
205
206 :SkipCleanBuild
207
208 if not exist "%__BinDir%"           md "%__BinDir%"
209 if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"
210 if not exist "%__LogsDir%"          md "%__LogsDir%"
211
212 :: CMake isn't a requirement when building mscorlib only
213 if defined __MscorlibOnly goto CheckVS
214
215 echo %__MsgPrefix%Checking prerequisites
216
217 :: Validate that PowerShell is accessibile.
218 for %%X in (powershell.exe) do (set __PSDir=%%~$PATH:X)
219 if not defined __PSDir goto NoPS
220
221 :: Eval the output from probe-win1.ps1
222 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
223
224 :CheckVS
225
226 set __VSProductVersion=
227 if /i "%__VSVersion%" == "vs2015" set __VSProductVersion=140
228
229 :: Check presence of VS
230 if not defined VS%__VSProductVersion%COMNTOOLS goto NoVS
231
232 set __VSToolsRoot=!VS%__VSProductVersion%COMNTOOLS!
233 if %__VSToolsRoot:~-1%==\ set "__VSToolsRoot=%__VSToolsRoot:~0,-1%"
234
235 :: Does VS really exist?
236 if not exist "%__VSToolsRoot%\..\IDE\devenv.exe"      goto NoVS
237 if not exist "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" goto NoVS
238 if not exist "%__VSToolsRoot%\VsDevCmd.bat"           goto NoVS
239
240 :MSBuild14
241 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
242 set UseRoslynCompiler=true
243 :CheckMSBuild14
244 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
245 if not exist %_msbuildexe% echo %__MsgPrefix%Error: Could not find MSBuild.exe.  Please see https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md for build instructions. && exit /b 1
246
247 :: Note: We've disabled node reuse because it causes file locking issues.
248 ::       The issue is that we extend the build with our own targets which
249 ::       means that that rebuilding cannot successfully delete the task
250 ::       assembly. 
251 set __msbuildCommonArgs=/nologo /nodeReuse:false %__msbuildCleanBuildArgs% %__msbuildExtraArgs%
252
253 if not defined __BuildSequential (
254     set __msbuildCommonArgs=%__msbuildCommonArgs% /maxcpucount
255 )
256
257 REM =========================================================================================
258 REM ===
259 REM === Restore Build Tools
260 REM ===
261 REM =========================================================================================
262 call %__ThisScriptPath%init-tools.cmd  
263
264 REM =========================================================================================
265 REM ===
266 REM === Start the build steps
267 REM ===
268 REM =========================================================================================
269
270 if defined __MscorlibOnly goto PerformMScorlibBuild
271
272 if defined __SkipNativeBuild (
273     echo %__MsgPrefix%Skipping native components build
274     goto SkipNativeBuild
275 )
276
277 echo %__MsgPrefix%Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType%
278
279 REM Use setlocal to restrict environment changes form vcvarsall.bat and more to just this native components build section.
280 setlocal EnableDelayedExpansion EnableExtensions
281
282 if /i "%__BuildArch%" == "arm64" ( 
283 rem arm64 builds currently use private toolset which has not been released yet
284 REM TODO, remove once the toolset is open.
285 call :PrivateToolSet
286
287 goto GenVSSolution
288 )
289
290 :: Set the environment for the native build
291 set __VCBuildArch=x86_amd64
292 if /i "%__BuildArch%" == "x86" (set __VCBuildArch=x86)
293 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
294 call                                 "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
295 @if defined __echo @echo on
296
297 if not defined VSINSTALLDIR (
298     echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
299     exit /b 1
300 )
301 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
302
303 :GenVSSolution
304
305 if defined __SkipConfigure goto SkipConfigure
306
307 echo %__MsgPrefix%Regenerating the Visual Studio solution
308
309 pushd "%__IntermediatesDir%"
310 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__BuildArch%
311 @if defined __echo @echo on
312 popd
313
314 :SkipConfigure
315
316 if not exist "%__IntermediatesDir%\install.vcxproj" (
317     echo %__MsgPrefix%Error: failed to generate native component build project!
318     exit /b 1
319 )
320
321 REM =========================================================================================
322 REM ===
323 REM === Build the CLR VM
324 REM ===
325 REM =========================================================================================
326
327 if defined __ConfigureOnly goto SkipNativeBuild
328
329 echo %__MsgPrefix%Invoking msbuild
330
331 set "__BuildLog=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
332 set "__BuildWrn=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
333 set "__BuildErr=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
334 set __msbuildLogArgs=^
335 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%" ^
336 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
337 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
338 /consoleloggerparameters:Summary ^
339 /verbosity:minimal
340
341 set __msbuildArgs="%__IntermediatesDir%\install.vcxproj" %__msbuildCommonArgs% %__msbuildLogArgs% /p:Configuration=%__BuildType%
342
343 if /i "%__BuildArch%" == "arm64" (  
344     REM TODO, remove once we have msbuild support for this platform.
345     set __msbuildArgs=%__msbuildArgs% /p:UseEnv=true
346 ) else (
347     set __msbuildArgs=%__msbuildArgs% /p:Platform=%__BuildArch%
348 )
349
350 %_msbuildexe% %__msbuildArgs%
351 if errorlevel 1 (
352     echo %__MsgPrefix%Error: native component build failed. Refer to the build log files for details:
353     echo     %__BuildLog%
354     echo     %__BuildWrn%
355     echo     %__BuildErr%
356     exit /b 1
357 )
358
359 REM endlocal to rid us of environment changes from vcvarsall.bat
360 endlocal
361
362 :SkipNativeBuild
363
364 REM =========================================================================================
365 REM ===
366 REM === Mscorlib build section.
367 REM ===
368 REM =========================================================================================
369
370 :PerformMScorlibBuild
371 if defined __SkipMscorlibBuild (
372     echo %__MsgPrefix%Skipping Mscorlib build
373     goto SkipMscorlibBuild
374 )
375
376 echo %__MsgPrefix%Commencing build of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType%
377
378 REM setlocal to prepare for vsdevcmd.bat
379 setlocal EnableDelayedExpansion EnableExtensions
380
381 rem Explicitly set Platform causes conflicts in mscorlib project files. Clear it to allow building from VS x64 Native Tools Command Prompt
382 set Platform=
383
384 :: Set the environment for the managed build
385 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
386 call                                 "%__VSToolsRoot%\VsDevCmd.bat"
387
388 set "__BuildLog=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
389 set "__BuildWrn=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
390 set "__BuildErr=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
391 set __msbuildLogArgs=^
392 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%" ^
393 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
394 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
395 /consoleloggerparameters:Summary ^
396 /verbosity:minimal
397
398 set __msbuildArgs="%__ProjectFilesDir%\build.proj" %__msbuildCommonArgs% %__msbuildLogArgs% %__SignTypeReal%
399
400 set __BuildNugetPackage=true
401 if defined __MscorlibOnly       set __BuildNugetPackage=false
402 if /i "%__BuildArch%" =="arm64" set __BuildNugetPackage=false
403 if %__BuildNugetPackage%==false set __msbuildArgs=%__msbuildArgs% /p:BuildNugetPackage=false
404
405 %_msbuildexe% %__msbuildArgs%
406 if errorlevel 1 (
407     echo %__MsgPrefix%Error: MScorlib build failed. Refer to the build log files for details:
408     echo     %__BuildLog%
409     echo     %__BuildWrn%
410     echo     %__BuildErr%
411     exit /b 1
412 )
413
414 if defined __MscorlibOnly (
415     echo %__MsgPrefix%Mscorlib successfully built.
416     exit /b 0
417 )
418
419 REM Consider doing crossgen build of mscorlib unless we are skipping it intentionally
420 if /i "%__BuildArch%" == "arm64" (
421     if not defined __DoCrossgen (
422         echo %__MsgPrefix%Skipping Crossgen
423         goto SkipCrossGenBuild
424     )
425 )
426
427 echo %__MsgPrefix%Generating native image of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType%
428
429 set "__CrossGenMScorlibLog=%__LogsDir%\CrossgenMScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
430 "%__BinDir%\crossgen.exe" "%__BinDir%\mscorlib.dll" > "%__CrossGenMScorlibLog%" 2>&1
431 if errorlevel 1 (
432     echo %__MsgPrefix%Error: CrossGen mscorlib build failed. Refer to the build log file for details:
433     echo     %__CrossGenMScorlibLog%
434     exit /b 1
435 )
436
437 :GenerateNuget
438 if /i "%__BuildArch%" =="arm64" goto :SkipNuget
439
440 set "__BuildLog=%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
441 set "__BuildWrn=%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
442 set "__BuildErr=%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
443 set __msbuildLogArgs=^
444 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%" ^
445 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
446 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
447 /consoleloggerparameters:Summary ^
448 /verbosity:minimal
449
450 set __msbuildArgs="%__ProjectFilesDir%\src\.nuget\Microsoft.NETCore.Runtime.CoreClr\Microsoft.NETCore.Runtime.CoreCLR.builds" /p:Platform=%__BuildArch%
451 %_msbuildexe% %__msbuildArgs% %__msbuildLogArgs%
452 if errorlevel 1 (
453     echo %__MsgPrefix%Error: Nuget package generation failed build failed. Refer to the build log files for details:
454     echo     %__BuildLog%
455     echo     %__BuildWrn%
456     echo     %__BuildErr%
457     exit /b 1
458 )
459
460 :SkipNuget
461
462 :SkipCrossGenBuild
463
464 REM endlocal to rid us of environment changes from vsdevenv.bat
465 endlocal
466
467 :SkipMscorlibBuild
468
469 REM =========================================================================================
470 REM ===
471 REM === Test build section
472 REM ===
473 REM =========================================================================================
474
475 if defined __SkipTestBuild (
476     echo %__MsgPrefix%Skipping test build
477     goto SkipTestBuild
478 )
479
480 echo %__MsgPrefix%Commencing build of tests for %__BuildOS%.%__BuildArch%.%__BuildType%
481
482 REM Construct the arguments to pass to the test build script.
483
484 set __BuildtestArgs=%__BuildArch% %__BuildType% %__VSVersion%
485
486 if defined __CleanBuild (
487     set "__BuildtestArgs=%__BuildtestArgs% clean"
488 )
489
490 if defined __BuildSequential (
491     set "__BuildtestArgs=%__BuildtestArgs% sequential"
492 )
493
494 if defined __TestPriority (
495     set "__BuildtestArgs=%__BuildtestArgs% Priority %__TestPriority%"
496 )
497
498 if %__GCStressLevel% GTR 0 (
499     set "__BuildtestArgs=%__BuildtestArgs% gcstresslevel %__GCStressLevel%"   
500 )
501
502 rem arm64 builds currently use private toolset which has not been released yet
503 REM TODO, remove once the toolset is open.
504 if /i "%__BuildArch%" == "arm64" call :PrivateToolSet 
505
506 call %__ProjectDir%\tests\buildtest.cmd %__BuildtestArgs%
507
508 if errorlevel 1 (
509     REM buildtest.cmd has already emitted an error message and mentioned the build log file to examine.
510     exit /b 1
511 )
512
513 :SkipTestBuild
514
515 REM =========================================================================================
516 REM ===
517 REM === All builds complete!
518 REM ===
519 REM =========================================================================================
520
521 echo %__MsgPrefix%Repo successfully built.
522 echo %__MsgPrefix%Product binaries are available at !__BinDir!
523 if not defined __SkipTestBuild (
524     echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
525 )
526 exit /b 0
527
528 REM =========================================================================================
529 REM ===
530 REM === Handle the "all" case.
531 REM ===
532 REM =========================================================================================
533
534 :BuildAll
535
536 set __BuildArchList=
537
538 set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
539 if %__TotalSpecifiedBuildArch% EQU 0 (
540     REM Nothing specified means we want to build all architectures.
541     set __BuildArchList=x64 x86 arm arm64
542 )
543
544 REM Otherwise, add all the specified architectures to the list.
545
546 if %__BuildArchX64%==1      set __BuildArchList=%__BuildArchList% x64
547 if %__BuildArchX86%==1      set __BuildArchList=%__BuildArchList% x86
548 if %__BuildArchArm%==1      set __BuildArchList=%__BuildArchList% arm
549 if %__BuildArchArm64%==1    set __BuildArchList=%__BuildArchList% arm64
550
551 set __BuildTypeList=
552
553 set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
554 if %__TotalSpecifiedBuildType% EQU 0 (
555     REM Nothing specified means we want to build all build types.
556     set __BuildTypeList=Debug Checked Release
557 )
558
559 if %__BuildTypeDebug%==1    set __BuildTypeList=%__BuildTypeList% Debug
560 if %__BuildTypeChecked%==1  set __BuildTypeList=%__BuildTypeList% Checked
561 if %__BuildTypeRelease%==1  set __BuildTypeList=%__BuildTypeList% Release
562
563 REM Create a temporary file to collect build results. We always build all flavors specified, and
564 REM report a summary of the results at the end.
565
566 set __AllBuildSuccess=true
567 set __BuildResultFile=%TEMP%\build-all-summary-%RANDOM%.txt
568 if exist %__BuildResultFile% del /f /q %__BuildResultFile%
569
570 for %%i in (%__BuildArchList%) do (
571     for %%j in (%__BuildTypeList%) do (
572         call :BuildOne %%i %%j
573     )
574 )
575
576 if %__AllBuildSuccess%==true (
577     echo %__MsgPrefix%All builds succeeded!
578     exit /b 0
579 ) else (
580     echo %__MsgPrefix%Builds failed:
581     type %__BuildResultFile%
582     del /f /q %__BuildResultFile%
583     exit /b 1
584 )
585
586 REM This code is unreachable, but leaving it nonetheless, just in case things change.
587 exit /b 99
588
589 :BuildOne
590 set __BuildArch=%1
591 set __BuildType=%2
592 set __NextCmd=call %__ThisScriptFull% %__BuildArch% %__BuildType% %__PassThroughArgs%
593 echo %__MsgPrefix%Invoking: %__NextCmd%
594 %__NextCmd%
595 if errorlevel 1 (
596     echo %__MsgPrefix%    %__BuildArch% %__BuildType% %__PassThroughArgs% >> %__BuildResultFile%
597     set __AllBuildSuccess=false
598 )
599 exit /b 0
600
601 REM =========================================================================================
602 REM ===
603 REM === Helper routines
604 REM ===
605 REM =========================================================================================
606
607 :Usage
608 echo.
609 echo Build the CoreCLR repo.
610 echo.
611 echo Usage:
612 echo     %__ThisScriptShort% [option1] [option2] ...
613 echo or:
614 echo     %__ThisScriptShort% all [option1] [option2] ...
615 echo.
616 echo All arguments are optional. The options are:
617 echo.
618 echo./? -? /h -h /help -help: view this message.
619 echo Build architecture: one of x64, x86, arm, arm64 ^(default: x64^).
620 echo Build type: one of Debug, Checked, Release ^(default: Debug^).
621 echo Visual Studio version: ^(default: VS2015^).
622 echo clean: force a clean build ^(default is to perform an incremental build^).
623 echo docrossgen: do a crossgen build of mscorlib.
624 echo msbuildargs ... : all arguments following this tag will be passed directly to msbuild.
625 echo mscorlib version: one of freebsdmscorlib, linuxmscorlib, netbsdmscorlib, osxmscorlib,
626 echo     or windowsmscorlib. If one of these is passed, only mscorlib is built,
627 echo     for the specified platform ^(FreeBSD, Linux, NetBSD, OS X or Windows,
628 echo     respectively^).
629 echo priority ^<N^> : specify a set of test that will be built and run, with priority N.
630 echo gcstresslevel ^<N^> : specify the GCStress level the tests should run under.
631 echo sequential: force a non-parallel build ^(default is to build in parallel
632 echo     using all processors^).
633 echo configureonly: skip all builds; only run CMake ^(default: CMake and builds are run^)
634 echo skipconfigure: skip CMake ^(default: CMake is run^)
635 echo skipmscorlib: skip building mscorlib ^(default: mscorlib is built^).
636 echo skipnative: skip building native components ^(default: native components are built^).
637 echo skiptests: skip building tests ^(default: tests are built^).
638 echo disableoss: Disable Open Source Signing for mscorlib.
639 echo toolset_dir ^<dir^> : set the toolset directory -- Arm64 use only. Required for Arm64 builds.
640 echo.
641 echo If "all" is specified, then all build architectures and types are built. If, in addition,
642 echo one or more build architectures or types is specified, then only those build architectures
643 echo and types are built.
644 echo.
645 echo For example:
646 echo     build all
647 echo        -- builds all architectures, and all build types per architecture
648 echo     build all x86
649 echo        -- builds all build types for x86
650 echo     build all x64 x86 Checked Release
651 echo        -- builds x64 and x86 architectures, Checked and Release build types for each
652 exit /b 1
653
654 :NoPS
655 echo PowerShell is a prerequisite to build this repository, but it is not accessible.
656 echo Ensure that it is defined in the PATH environment variable.
657 echo Typically it should be %%SYSTEMROOT%%\System32\WindowsPowerShell\v1.0\.
658 exit /b 1
659
660 :NoVS
661 echo Visual Studio 2015+ ^(Community is free^) is a prerequisite to build this repository.
662 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
663 exit /b 1
664
665 :NoDIA
666 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
667 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
668 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
669 of the previous version to "%VSINSTALLDIR%" and then build.
670 :: DIA SDK not included in Express editions
671 echo Visual Studio Express does not include the DIA SDK. ^
672 You need Visual Studio 2015+ (Community is free).
673 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
674 exit /b 1
675
676 :PrivateToolSet
677
678 echo %__MsgPrefix% Setting Up the usage of __ToolsetDir:%__ToolsetDir%
679
680 if /i "%__ToolsetDir%" == "" (
681     echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
682     exit /b 1
683 )
684
685 set PATH=%__ToolsetDir%\cpp\bin;%PATH%
686 set LIB=%__ToolsetDir%\cpp\libWin9CoreSystem;%__ToolsetDir%\OS\lib;%__ToolsetDir%\cpp\lib
687 set INCLUDE=^
688 %__ToolsetDir%\cpp\inc;^
689 %__ToolsetDir%\OS\inc\Windows;^
690 %__ToolsetDir%\OS\inc\Windows\crt;^
691 %__ToolsetDir%\cpp\inc\vc;^
692 %__ToolsetDir%\OS\inc\win8
693 exit /b 0