Merge pull request #10021 from adityamandaleeka/fix_broken_ci_badges
[platform/upstream/coreclr.git] / build.sh
1 #!/usr/bin/env bash
2
3 # resolve python-version to use
4 if [ "$PYTHON" == "" ] ; then
5     if ! PYTHON=$(command -v python || command -v python2 || command -v python 2.7)
6     then
7        echo "Unable to locate build-dependency python2.x!" 1>&2
8        exit 1
9     fi
10 fi
11
12 # validate python-dependency
13 # useful in case of explicitly set option.
14 if ! command -v $PYTHON > /dev/null
15 then
16    echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
17    exit 1
18 fi
19
20 usage()
21 {
22     echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [configureonly] [skipconfigure] [skipnative] [skipmscorlib] [skiptests] [stripsymbols] [cmakeargs] [bindir]"
23     echo "BuildArch can be: x64, x86, arm, armel, arm64"
24     echo "BuildType can be: debug, checked, release"
25     echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
26     echo "ninja - target ninja instead of GNU make"
27     echo "clangx.y - optional argument to build using clang version x.y."
28     echo "cross - optional argument to signify cross compilation,"
29     echo "      - will use ROOTFS_DIR environment variable if set."
30     echo "crosscomponent - optional argument to build cross-architecture component,"
31     echo "               - will use CAC_ROOTFS_DIR environment variable if set."
32     echo "pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
33     echo "configureonly - do not perform any builds; just configure the build."
34     echo "skipconfigure - skip build configuration."
35     echo "skipnative - do not build native components."
36     echo "skipmscorlib - do not build mscorlib.dll."
37     echo "skiptests - skip the tests in the 'tests' subdirectory."
38     echo "skipnuget - skip building nuget packages."
39     echo "portableLinux - build for Portable Linux Distribution"
40     echo "verbose - optional argument to enable verbose build output."
41     echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
42         echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
43         echo "-sequential: force a non-parallel build ^(default is to build in parallel"
44         echo "   using all processors^)."
45         echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
46         echo "-Rebuild: passes /t:rebuild to the build projects."
47     echo "stripSymbols - Optional argument to strip native symbols during the build."
48     echo "skipgenerateversion - disable version generation even if MSBuild is supported."
49     echo "cmakeargs - user-settable additional arguments passed to CMake."
50     echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
51     echo "buildstandalonegc - builds the GC in a standalone mode. Can't be used with \"cmakeargs\"."
52     echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
53     exit 1
54 }
55
56 initHostDistroRid()
57 {
58     if [ "$__HostOS" == "Linux" ]; then
59         if [ ! -e /etc/os-release ]; then
60             echo "WARNING: Can not determine runtime id for current distro."
61             __HostDistroRid=""
62         else
63             source /etc/os-release
64             __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
65         fi
66     fi
67 }
68
69 initTargetDistroRid()
70 {
71     if [ $__CrossBuild == 1 ]; then
72         if [ "$__BuildOS" == "Linux" ]; then
73             if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
74                 echo "WARNING: Can not determine runtime id for current distro."
75                 export __DistroRid=""
76             else
77                 source $ROOTFS_DIR/etc/os-release
78                 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
79             fi
80         fi
81     else
82         export __DistroRid="$__HostDistroRid"
83     fi
84
85     # Portable builds target the base RID only for Linux based platforms
86     if [ $__PortableLinux == 1 ]; then
87         export __DistroRid="linux-$__BuildArch"
88     fi
89 }
90
91 setup_dirs()
92 {
93     echo Setting up directories for build
94
95     mkdir -p "$__RootBinDir"
96     mkdir -p "$__BinDir"
97     mkdir -p "$__LogsDir"
98     mkdir -p "$__IntermediatesDir"
99
100     if [ $__CrossBuild == 1 ]; then
101         mkdir -p "$__CrossComponentBinDir"
102         mkdir -p "$__CrossCompIntermediatesDir"
103     fi
104 }
105
106 # Check the system to ensure the right prereqs are in place
107
108 check_prereqs()
109 {
110     echo "Checking prerequisites..."
111
112     # Check presence of CMake on the path
113     hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
114
115     # Check for clang
116     hash clang-$__ClangMajorVersion.$__ClangMinorVersion 2>/dev/null ||  hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null ||  hash clang 2>/dev/null || { echo >&2 "Please install clang-$__ClangMajorVersion.$__ClangMinorVersion before running this script"; exit 1; }
117
118 }
119
120
121 generate_event_logging_sources()
122 {
123     if [ $__SkipCoreCLR == 1 ]; then
124         return
125     fi
126
127 # Event Logging Infrastructure
128    __GeneratedIntermediate="$__IntermediatesDir/Generated"
129    __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
130     if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
131         rm -rf  "$__GeneratedIntermediateEventProvider"
132     fi
133
134     if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
135         mkdir -p "$__GeneratedIntermediate/eventprovider"
136     fi
137
138     mkdir -p "$__GeneratedIntermediateEventProvider"
139     if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
140         echo "Laying out dynamically generated files consumed by the build system "
141         echo "Laying out dynamically generated Event Logging Test files"
142         $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
143
144         if  [[ $? != 0 ]]; then
145             exit
146         fi
147
148         #determine the logging system
149         case $__BuildOS in
150             Linux)
151                 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
152                 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
153                 if  [[ $? != 0 ]]; then
154                     exit
155                 fi
156                 ;;
157             *)
158                 ;;
159         esac
160     fi
161
162     echo "Cleaning the temp folder of dynamically generated Event Logging files"
163     $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
164     if  [[ $? != 0 ]]; then
165         exit
166     fi
167
168     rm -rf "$__GeneratedIntermediateEventProvider"
169 }
170
171 build_native()
172 {
173     skipCondition=$1
174     platformArch="$2"
175     intermediatesForBuild="$3"
176     extraCmakeArguments="$4"
177     message="$5"
178
179     if [ $skipCondition == 1 ]; then
180         echo "Skipping $message build."
181         return
182     fi
183
184     # All set to commence the build
185     echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
186
187     generator=""
188     buildFile="Makefile"
189     buildTool="make"
190     if [ $__UseNinja == 1 ]; then
191         generator="ninja"
192         buildFile="build.ninja"
193         if ! buildTool=$(command -v ninja || command -v ninja-build); then
194            echo "Unable to locate ninja!" 1>&2
195            exit 1
196         fi
197     fi
198
199     if [ $__SkipConfigure == 0 ]; then
200         # if msbuild is not supported, then set __SkipGenerateVersion to 1
201         if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
202         # Drop version.cpp file
203         __versionSourceFile="$intermediatesForBuild/version.cpp"
204         if [ $__SkipGenerateVersion == 0 ]; then
205             pwd
206             "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile $__RunArgs $__UnprocessedBuildArgs
207         else
208             # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
209             __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
210             if [ -e $__versionSourceFile ]; then
211                 read existingVersionSourceLine < $__versionSourceFile
212             fi
213             if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
214                 echo $__versionSourceLine > $__versionSourceFile
215             fi
216         fi
217
218         pushd "$intermediatesForBuild"
219         # Regenerate the CMake solution
220         echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator $extraCmakeArguments $__cmakeargs"
221         "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$extraCmakeArguments" "$__cmakeargs"
222         popd
223     fi
224
225     if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
226         echo "Failed to generate $message build project!"
227         exit 1
228     fi
229     
230     # Get the number of processors available to the scheduler
231     # Other techniques such as `nproc` only get the number of
232     # processors available to a single process.
233     if [ `uname` = "FreeBSD" ]; then
234         NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
235     elif [ `uname` = "NetBSD" ]; then
236         NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
237     else
238         NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
239     fi
240
241     # Build
242     if [ $__ConfigureOnly == 1 ]; then
243         echo "Finish configuration & skipping $message build."
244         return
245     fi
246
247     # Check that the makefiles were created.
248     pushd "$intermediatesForBuild"
249
250     echo "Executing $buildTool install -j $NumProc"
251
252     $buildTool install -j $NumProc
253     if [ $? != 0 ]; then
254         echo "Failed to build $message."
255         exit 1
256     fi
257
258     popd
259 }
260
261 build_cross_arch_component()
262 {
263     __SkipCrossArchBuild=1
264     TARGET_ROOTFS=""
265     # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
266     if [[ "$__BuildArch" == "arm" && "$__CrossArch" == "x86" ]]; then
267         export CROSSCOMPILE=0
268         __SkipCrossArchBuild=0
269
270         # building x64-host/arm-target cross-architecture component need to use cross toolchain of x86
271         if [ "$__HostArch" == "x64" ]; then
272             export CROSSCOMPILE=1
273         fi
274     else
275         # not supported
276         return
277     fi    
278     
279     export __CMakeBinDir="$__CrossComponentBinDir"
280     export CROSSCOMPONENT=1
281     __IncludeTests=
282
283     if [ $CROSSCOMPILE == 1 ]; then
284         TARGET_ROOTFS="$ROOTFS_DIR"
285         if [ -n "$CAC_ROOTFS_DIR" ]; then
286             export ROOTFS_DIR="$CAC_ROOTFS_DIR"
287         else
288             export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__CrossArch"
289         fi
290     fi
291
292     __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
293     build_native $__SkipCrossArchBuild "$__CrossArch" "$__CrossCompIntermediatesDir" "$__ExtraCmakeArgs" "cross-architecture component"
294    
295     # restore ROOTFS_DIR, CROSSCOMPONENT, and CROSSCOMPILE 
296     if [ -n "$TARGET_ROOTFS" ]; then
297         export ROOTFS_DIR="$TARGET_ROOTFS"
298     fi
299     export CROSSCOMPONENT=
300     export CROSSCOMPILE=1
301 }
302
303 isMSBuildOnNETCoreSupported()
304 {
305     # This needs to be updated alongwith corresponding changes to netci.groovy.
306     __isMSBuildOnNETCoreSupported=0
307
308     if [ "$__HostArch" == "x64" ]; then
309         if [ "$__HostOS" == "Linux" ]; then
310             case "$__HostDistroRid" in
311                 "centos.7-x64")
312                     __isMSBuildOnNETCoreSupported=1
313                     ;;
314                 "debian.8-x64")
315                     __isMSBuildOnNETCoreSupported=1
316                     ;;
317                 "fedora.23-x64")
318                     __isMSBuildOnNETCoreSupported=1
319                     ;;
320                 "fedora.24-x64")
321                     __isMSBuildOnNETCoreSupported=1
322                     ;;
323                 "opensuse.42.1-x64")
324                     __isMSBuildOnNETCoreSupported=1
325                     ;;
326                 "rhel.7"*"-x64")
327                     __isMSBuildOnNETCoreSupported=1
328                     ;;
329                 "ubuntu.14.04-x64")
330                     __isMSBuildOnNETCoreSupported=1
331                     ;;
332                 "ubuntu.16.04-x64")
333                     __isMSBuildOnNETCoreSupported=1
334                     ;;
335                 "ubuntu.16.10-x64")
336                     __isMSBuildOnNETCoreSupported=1
337                     ;;
338                 "alpine.3.4.3-x64")
339                     __isMSBuildOnNETCoreSupported=1
340                     ;;
341                 *)
342                 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
343             esac
344         elif [ "$__HostOS" == "OSX" ]; then
345             __isMSBuildOnNETCoreSupported=1
346         fi
347     fi
348 }
349
350 build_CoreLib_ni()
351 {
352     if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
353         echo "Generating native image for System.Private.CoreLib."
354         $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
355         if [ $? -ne 0 ]; then
356             echo "Failed to generate native image for System.Private.CoreLib."
357             exit 1
358         fi
359
360         echo "Generating native image for MScorlib Facade."
361         $__BinDir/crossgen $__BinDir/mscorlib.dll
362         if [ $? -ne 0 ]; then
363             echo "Failed to generate native image for mscorlib facade."
364             exit 1
365         fi
366
367         if [ "$__BuildOS" == "Linux" ]; then
368             echo "Generating symbol file for System.Private.CoreLib."
369             $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
370             if [ $? -ne 0 ]; then
371                 echo "Failed to generate symbol file for System.Private.CoreLib."
372                 exit 1
373             fi
374         fi
375     fi
376 }
377
378 build_CoreLib()
379 {
380
381     if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
382         echo "System.Private.CoreLib.dll build unsupported."
383         return
384     fi
385
386     if [ $__SkipMSCorLib == 1 ]; then
387        echo "Skipping building System.Private.CoreLib."
388        return
389     fi
390
391     echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
392
393     # Invoke MSBuild
394     $__ProjectRoot/run.sh build -Project=$__ProjectDir/build.proj -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false $__RunArgs $__UnprocessedBuildArgs
395
396     if [ $? -ne 0 ]; then
397         echo "Failed to build managed components."
398         exit 1
399     fi
400
401     # The cross build generates a crossgen with the target architecture.
402     if [ $__CrossBuild != 1 ]; then
403        # The architecture of host pc must be same architecture with target.
404        if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
405            build_CoreLib_ni
406        elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
407            build_CoreLib_ni
408        elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
409            build_CoreLib_ni
410        else 
411            exit 1
412        fi
413     fi 
414 }
415
416 generate_NugetPackages()
417 {
418     # We can only generate nuget package if we also support building mscorlib as part of this build.
419     if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
420         echo "Nuget package generation unsupported."
421         return
422     fi
423
424     # Since we can build mscorlib for this OS, did we build the native components as well?
425     if [ $__SkipCoreCLR == 1 ]; then
426         echo "Unable to generate nuget packages since native components were not built."
427         return
428     fi
429
430     echo "Generating nuget packages for "$__BuildOS
431
432     # Build the packages
433     $__ProjectRoot/run.sh build -Project=$__SourceDir/.nuget/packages.builds -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false $__RunArgs $__UnprocessedBuildArgs
434
435     if [ $? -ne 0 ]; then
436         echo "Failed to generate Nuget packages."
437         exit 1
438     fi
439 }
440
441 echo "Commencing CoreCLR Repo build"
442
443 # Argument types supported by this script:
444 #
445 # Build architecture - valid values are: x64, ARM.
446 # Build Type         - valid values are: Debug, Checked, Release
447 #
448 # Set the default arguments for build
449
450 # Obtain the location of the bash script to figure out where the root of the repo is.
451 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
452
453 # Use uname to determine what the CPU is.
454 CPUName=$(uname -p)
455 # Some Linux platforms report unknown for platform, but the arch for machine.
456 if [ "$CPUName" == "unknown" ]; then
457     CPUName=$(uname -m)
458 fi
459
460 case $CPUName in
461     i686)
462         echo "Unsupported CPU $CPUName detected, build might not succeed!"
463         __BuildArch=x86
464         __HostArch=x86
465         ;;
466
467     x86_64)
468         __BuildArch=x64
469         __HostArch=x64
470         ;;
471
472     armv7l)
473         echo "Unsupported CPU $CPUName detected, build might not succeed!"
474         __BuildArch=arm
475         __HostArch=arm
476         ;;
477
478     aarch64)
479         __BuildArch=arm64
480         __HostArch=arm64
481         ;;
482
483     *)
484         echo "Unknown CPU $CPUName detected, configuring as if for x64"
485         __BuildArch=x64
486         __HostArch=x64
487         ;;
488 esac
489
490 # Use uname to determine what the OS is.
491 OSName=$(uname -s)
492 case $OSName in
493     Linux)
494         __BuildOS=Linux
495         __HostOS=Linux
496         ;;
497
498     Darwin)
499         __BuildOS=OSX
500         __HostOS=OSX
501         ;;
502
503     FreeBSD)
504         __BuildOS=FreeBSD
505         __HostOS=FreeBSD
506         ;;
507
508     OpenBSD)
509         __BuildOS=OpenBSD
510         __HostOS=OpenBSD
511         ;;
512
513     NetBSD)
514         __BuildOS=NetBSD
515         __HostOS=NetBSD
516         ;;
517
518     SunOS)
519         __BuildOS=SunOS
520         __HostOS=SunOS
521         ;;
522
523     *)
524         echo "Unsupported OS $OSName detected, configuring as if for Linux"
525         __BuildOS=Linux
526         __HostOS=Linux
527         ;;
528 esac
529
530 __BuildType=Debug
531 __CodeCoverage=
532 __IncludeTests=Include_Tests
533
534 # Set the various build properties here so that CMake and MSBuild can pick them up
535 __ProjectDir="$__ProjectRoot"
536 __SourceDir="$__ProjectDir/src"
537 __PackagesDir="$__ProjectDir/packages"
538 __RootBinDir="$__ProjectDir/bin"
539 __UnprocessedBuildArgs=
540 __RunArgs=
541 __MSBCleanBuildArgs=
542 __UseNinja=0
543 __VerboseBuild=0
544 __PgoInstrument=0
545 __ConfigureOnly=0
546 __SkipConfigure=0
547 __SkipRestore=""
548 __SkipNuget=0
549 __SkipCoreCLR=0
550 __SkipMSCorLib=0
551 __CrossBuild=0
552 __ClangMajorVersion=0
553 __ClangMinorVersion=0
554 __NuGetPath="$__PackagesDir/NuGet.exe"
555 __HostDistroRid=""
556 __DistroRid=""
557 __cmakeargs=""
558 __SkipGenerateVersion=0
559 __DoCrossArchBuild=0
560 __PortableLinux=0
561 __msbuildonunsupportedplatform=0
562
563 while :; do
564     if [ $# -le 0 ]; then
565         break
566     fi
567
568     lowerI="$(echo $1 | awk '{print tolower($0)}')"
569     case $lowerI in
570         -\?|-h|--help)
571             usage
572             exit 1
573             ;;
574
575         x86)
576             __BuildArch=x86
577             ;;
578
579         x64)
580             __BuildArch=x64
581             ;;
582
583         arm)
584             __BuildArch=arm
585             ;;
586
587         armel)
588             __BuildArch=armel
589             ;;
590
591         arm64)
592             __BuildArch=arm64
593             ;;
594
595         debug)
596             __BuildType=Debug
597             ;;
598
599         checked)
600             __BuildType=Checked
601             ;;
602
603         release)
604             __BuildType=Release
605             ;;
606
607         coverage)
608             __CodeCoverage=Coverage
609             ;;
610
611         cross)
612             __CrossBuild=1
613             ;;
614             
615         portablelinux)
616             if [ "$__BuildOS" == "Linux" ]; then
617                 __PortableLinux=1
618             else
619                 echo "ERROR: portableLinux not supported for non-Linux platforms."
620                 exit 1
621             fi
622             ;;
623             
624         verbose)
625             __VerboseBuild=1
626             ;;
627
628         stripsymbols)
629             __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
630             ;;
631
632         clang3.5)
633             __ClangMajorVersion=3
634             __ClangMinorVersion=5
635             ;;
636
637         clang3.6)
638             __ClangMajorVersion=3
639             __ClangMinorVersion=6
640             ;;
641
642         clang3.7)
643             __ClangMajorVersion=3
644             __ClangMinorVersion=7
645             ;;
646
647         clang3.8)
648             __ClangMajorVersion=3
649             __ClangMinorVersion=8
650             ;;
651
652         clang3.9)
653             __ClangMajorVersion=3
654             __ClangMinorVersion=9
655             ;;
656
657         ninja)
658             __UseNinja=1
659             ;;
660
661         pgoinstrument)
662             __PgoInstrument=1
663             ;;
664
665         configureonly)
666             __ConfigureOnly=1
667             __SkipMSCorLib=1
668             __SkipNuget=1
669             ;;
670
671         skipconfigure)
672             __SkipConfigure=1
673             ;;
674
675         skipnative)
676             # Use "skipnative" to use the same option name as build.cmd.
677             __SkipCoreCLR=1
678             ;;
679
680         skipcoreclr)
681             # Accept "skipcoreclr" for backwards-compatibility.
682             __SkipCoreCLR=1
683             ;;
684
685         crosscomponent)
686             __DoCrossArchBuild=1
687             ;;
688
689         skipmscorlib)
690             __SkipMSCorLib=1
691             ;;
692
693         skipgenerateversion)
694             __SkipGenerateVersion=1
695             ;;
696
697         includetests)
698             ;;
699
700         skiptests)
701             __IncludeTests=
702             ;;
703
704         skipnuget)
705             __SkipNuget=1
706             ;;
707
708         cmakeargs)
709             if [ -n "$2" ]; then
710                 __cmakeargs="$2"
711                 shift
712             else
713                 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
714                 exit 1
715             fi
716             ;;
717
718         bindir)
719             if [ -n "$2" ]; then
720                 __RootBinDir="$2"
721                 if [ ! -d $__RootBinDir ]; then
722                     mkdir $__RootBinDir
723                 fi
724                 __RootBinParent=$(dirname $__RootBinDir)
725                 __RootBinName=${__RootBinDir##*/}
726                 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
727                 shift
728             else
729                 echo "ERROR: 'bindir' requires a non-empty option argument"
730                 exit 1
731             fi
732             ;;
733         buildstandalonegc)
734             __cmakeargs="-DFEATURE_STANDALONE_GC=1"
735             ;;
736         msbuildonunsupportedplatform)
737             __msbuildonunsupportedplatform=1
738             ;;
739         *)
740             __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
741             ;;
742     esac
743
744     shift
745 done
746
747 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
748
749 # Configure environment if we are doing a verbose build
750 if [ $__VerboseBuild == 1 ]; then
751     export VERBOSE=1
752         __RunArgs="$__RunArgs -verbose"
753 fi
754
755 # Set default clang version
756 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
757     if [ $__CrossBuild == 1 ]; then
758         __ClangMajorVersion=3
759         __ClangMinorVersion=6
760     else
761         __ClangMajorVersion=3
762         __ClangMinorVersion=5
763     fi
764 fi
765
766 # Set dependent variables
767 __LogsDir="$__RootBinDir/Logs"
768
769 # init the host distro name
770 initHostDistroRid
771
772 # Set the remaining variables based upon the determined build configuration
773 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
774 __PackagesBinDir="$__BinDir/.nuget"
775 __ToolsDir="$__RootBinDir/tools"
776 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
777 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
778 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
779 __isMSBuildOnNETCoreSupported=0
780 __CrossComponentBinDir="$__BinDir"
781 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
782
783 __CrossArch="$__HostArch"
784 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
785     __CrossArch="x86"
786 fi
787 if [ $__CrossBuild == 1 ]; then
788     __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
789 fi
790 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
791 __CrossgenExe="$__CrossComponentBinDir/crossgen"
792
793 # Init if MSBuild for .NET Core is supported for this platform
794 isMSBuildOnNETCoreSupported
795
796 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
797 # This is needed by CLI to function.
798 if [ -z "$HOME" ]; then
799     if [ ! -d "$__ProjectDir/temp_home" ]; then
800         mkdir temp_home
801     fi
802     export HOME=$__ProjectDir/temp_home
803     echo "HOME not defined; setting it to $HOME"
804 fi
805
806 # Specify path to be set for CMAKE_INSTALL_PREFIX.
807 # This is where all built CoreClr libraries will copied to.
808 export __CMakeBinDir="$__BinDir"
809
810 # Configure environment if we are doing a cross compile.
811 if [ $__CrossBuild == 1 ]; then
812     export CROSSCOMPILE=1
813     if ! [[ -n "$ROOTFS_DIR" ]]; then
814         export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
815     fi
816 fi
817
818 # init the target distro name
819 initTargetDistroRid
820
821 # Make the directories necessary for build if they don't exist
822 setup_dirs
823
824 # Check prereqs.
825 check_prereqs
826
827 # Generate event logging infrastructure sources
828 generate_event_logging_sources
829
830 # Build the coreclr (native) components.
831 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
832 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
833
834 # Build cross-architecture components
835 if [[ $__CrossBuild == 1 && $__DoCrossArchBuild == 1 ]]; then
836     build_cross_arch_component
837 fi
838
839 # Build System.Private.CoreLib.
840
841 build_CoreLib
842
843 # Generate nuget packages
844 if [ $__SkipNuget != 1 ]; then
845     generate_NugetPackages
846 fi
847
848
849 # Build complete
850
851 echo "Repo successfully built."
852 echo "Product binaries are available at $__BinDir"
853 exit 0