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