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