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