Fix TPA map hash calculation. (#288)
[platform/upstream/coreclr.git] / build.sh
1 #!/usr/bin/env bash
2
3 # Work around Jenkins CI + msbuild problem: Jenkins sometimes creates very large environment
4 # variables, and msbuild can't handle environment blocks with such large variables. So clear
5 # out the variables that might be too large.
6 export ghprbCommentBody=
7
8 # resolve python-version to use
9 if [ "$PYTHON" == "" ] ; then
10     if ! PYTHON=$(command -v python2.7 || command -v python2 || command -v python)
11     then
12        echo "Unable to locate build-dependency python2.x!" 1>&2
13        exit 1
14     fi
15 fi
16
17 # validate python-dependency
18 # useful in case of explicitly set option.
19 if ! command -v $PYTHON > /dev/null
20 then
21    echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
22    exit 1
23 fi
24
25 usage()
26 {
27     echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"
28     echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64"
29     echo "BuildType can be: -debug, -checked, -release"
30     echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
31     echo "-ninja - target ninja instead of GNU make"
32     echo "-clangx.y - optional argument to build using clang version x.y."
33     echo "-cross - optional argument to signify cross compilation,"
34     echo "       - will use ROOTFS_DIR environment variable if set."
35     echo "-crosscomponent - optional argument to build cross-architecture component,"
36     echo "                - will use CAC_ROOTFS_DIR environment variable if set."
37     echo "-nopgooptimize - do not use profile guided optimizations."
38     echo "-pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
39     echo "-ibcinstrument - generate IBC-tuning-enabled native images when invoking crossgen."
40     echo "-configureonly - do not perform any builds; just configure the build."
41     echo "-skipconfigure - skip build configuration."
42     echo "-skipnative - do not build native components."
43     echo "-skipmscorlib - do not build mscorlib.dll."
44     echo "-skiptests - skip the tests in the 'tests' subdirectory."
45     echo "-skipnuget - skip building nuget packages."
46     echo "-skiprestoreoptdata - skip restoring optimization data used by profile-based optimizations."
47     echo "-skipcrossgen - skip native image generation"
48     echo "-verbose - optional argument to enable verbose build output."
49     echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
50     echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
51     echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
52     echo "-Rebuild: passes /t:rebuild to the build projects."
53     echo "-stripSymbols - Optional argument to strip native symbols during the build."
54     echo "-skipgenerateversion - disable version generation even if MSBuild is supported."
55     echo "-ignorewarnings - do not treat warnings as errors"
56     echo "-cmakeargs - user-settable additional arguments passed to CMake."
57     echo "-bindir - output directory (defaults to $__ProjectRoot/bin)"
58     echo "-msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
59     echo "-numproc - set the number of build processes."
60     exit 1
61 }
62
63 initHostDistroRid()
64 {
65     __HostDistroRid=""
66     if [ "$__HostOS" == "Linux" ]; then
67         if [ -e /etc/os-release ]; then
68             source /etc/os-release
69             if [[ $ID == "rhel" ]]; then
70                 # remove the last version digit
71                 VERSION_ID=${VERSION_ID%.*}
72             fi
73             __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
74             if [[ $ID == "alpine" ]]; then
75                 __HostDistroRid="linux-musl-$__HostArch"
76             fi
77             if [[ $ID == "tizen" ]]; then
78                 __HostArch=armel
79                 export __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
80             fi
81         elif [ -e /etc/redhat-release ]; then
82             local redhatRelease=$(</etc/redhat-release)
83             if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
84                __HostDistroRid="rhel.6-$__HostArch"
85             fi
86         elif [ -e os-release ]; then
87             echo "Build using local os-release file !!!"
88             source os-release
89             if [[ $ID == "tizen" ]]; then
90                 __HostArch=armel
91                 export __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
92             fi
93         fi
94     fi
95     if [ "$__HostOS" == "FreeBSD" ]; then
96         __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
97         __HostDistroRid="freebsd.$__freebsd_version-$__HostArch"
98     fi
99
100     if [ "$__HostDistroRid" == "" ]; then
101         echo "WARNING: Can not determine runtime id for current distro."
102     fi
103 }
104
105 initTargetDistroRid()
106 {
107     if [ $__CrossBuild == 1 ]; then
108         if [ "$__BuildOS" == "Linux" ]; then
109             if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
110                 if [ -e $ROOTFS_DIR/android_platform ]; then
111                     source $ROOTFS_DIR/android_platform
112                     export __DistroRid="$RID"
113                 else
114                     echo "WARNING: Can not determine runtime id for current distro."
115                     export __DistroRid=""
116                 fi
117             else
118                 source $ROOTFS_DIR/etc/os-release
119                 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
120             fi
121         fi
122     else
123         export __DistroRid="$__HostDistroRid"
124     fi
125
126     if [ "$__BuildOS" == "OSX" ]; then
127         __PortableBuild=1
128     fi
129
130     # Portable builds target the base RID
131     if [ $__PortableBuild == 1 ]; then
132         if [ "$__BuildOS" == "Linux" ]; then
133             export __DistroRid="linux-$__BuildArch"
134         elif [ "$__BuildOS" == "OSX" ]; then
135             export __DistroRid="osx-$__BuildArch"
136         elif [ "$__BuildOS" == "FreeBSD" ]; then
137             export __DistroRid="freebsd-$__BuildArch"
138         fi
139     fi
140 }
141
142 setup_dirs()
143 {
144     echo Setting up directories for build
145
146     mkdir -p "$__RootBinDir"
147     mkdir -p "$__BinDir"
148     mkdir -p "$__LogsDir"
149     mkdir -p "$__IntermediatesDir"
150
151     if [ $__CrossBuild == 1 ]; then
152         mkdir -p "$__CrossComponentBinDir"
153         mkdir -p "$__CrossCompIntermediatesDir"
154     fi
155 }
156
157 # Check the system to ensure the right prereqs are in place
158
159 check_prereqs()
160 {
161     echo "Checking prerequisites..."
162
163     # Check presence of CMake on the path
164     hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
165
166
167     # Minimum required version of clang is version 4.0 for arm/armel cross build
168     if [[ $__CrossBuild == 1 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
169         if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
170             echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
171         fi
172     fi
173
174     # Check for clang
175     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; }
176
177 }
178
179 restore_optdata()
180 {
181     # we only need optdata on a Release build
182     if [[ "$__BuildType" != "Release" ]]; then __SkipRestoreOptData=1; fi
183
184     if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
185         echo "Restoring the OptimizationData package"
186         "$__ProjectRoot/run.sh" build -optdata $__RunArgs $__UnprocessedBuildArgs
187         if [ $? != 0 ]; then
188             echo "Failed to restore the optimization data package."
189             exit 1
190         fi
191     fi
192
193     if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
194         # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
195         local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
196         if [ ! -f $DotNetCli ]; then
197             source "$__ProjectRoot/init-tools.sh"
198             if [ $? != 0 ]; then
199                 echo "Failed to restore buildtools."
200                 exit 1
201             fi
202         fi
203         local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
204         __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
205         __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^\s*//')
206     fi
207 }
208
209 generate_event_logging_sources()
210 {
211     __OutputDir=$1
212     __ConsumingBuildSystem=$2
213
214     __OutputIncDir="$__OutputDir/src/inc"
215     __OutputEventingDir="$__OutputDir/eventing"
216     __OutputEventProviderDir="$__OutputEventingDir/eventprovider"
217
218     echo "Laying out dynamically generated files consumed by $__ConsumingBuildSystem"
219     echo "Laying out dynamically generated Event test files, etmdummy stub functions, and external linkages"
220
221     __PythonWarningFlags="-Wall"
222     if [[ $__IgnoreWarnings == 0 ]]; then
223         __PythonWarningFlags="$__PythonWarningFlags -Werror"
224     fi
225
226     $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventing.py" --inc $__OutputIncDir --dummy $__OutputIncDir/etmdummy.h --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --testdir "$__OutputEventProviderDir/tests"
227     if [[ $? != 0 ]]; then
228         exit 1
229     fi
230
231     echo "Laying out dynamically generated EventPipe Implementation"
232     $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
233
234     # determine the logging system
235     case $__BuildOS in
236         Linux|FreeBSD)
237             echo "Laying out dynamically generated Event Logging Implementation of Lttng"
238             $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genLttngProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
239             if [[ $? != 0 ]]; then
240                 exit 1
241             fi
242             ;;
243         *)
244             echo "Laying out dummy event logging provider"
245             $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genDummyProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
246             if [[ $? != 0 ]]; then
247                 exit 1
248             fi
249             ;;
250     esac
251 }
252
253 generate_event_logging()
254 {
255     # Event Logging Infrastructure
256     if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
257         generate_event_logging_sources "$__IntermediatesDir" "the native build system"
258     fi
259
260     if [[ $__CrossBuild == 1 && $__DoCrossArchBuild == 1 ]]; then
261         generate_event_logging_sources "$__CrossCompIntermediatesDir" "the crossarch build system"
262     fi
263  }
264
265 build_native()
266 {
267     skipCondition=$1
268     platformArch="$2"
269     intermediatesForBuild="$3"
270     extraCmakeArguments="$4"
271     message="$5"
272
273     if [ $skipCondition == 1 ]; then
274         echo "Skipping $message build."
275         return
276     fi
277
278     # All set to commence the build
279     echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
280
281     generator=""
282     buildFile="Makefile"
283     buildTool="make"
284     if [ $__UseNinja == 1 ]; then
285         generator="ninja"
286         buildFile="build.ninja"
287         if ! buildTool=$(command -v ninja || command -v ninja-build); then
288            echo "Unable to locate ninja!" 1>&2
289            exit 1
290         fi
291     fi
292
293     if [ $__SkipConfigure == 0 ]; then
294         # if msbuild is not supported, then set __SkipGenerateVersion to 1
295         if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
296         # Drop version.cpp file
297         __versionSourceFile="$intermediatesForBuild/version.cpp"
298         if [ $__SkipGenerateVersion == 0 ]; then
299             pwd
300             "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile -MsBuildEventLogging="/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log"  $__RunArgs $__UnprocessedBuildArgs
301         else
302             # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
303             __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
304             if [ -e $__versionSourceFile ]; then
305                 read existingVersionSourceLine < $__versionSourceFile
306             fi
307             if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
308                 echo $__versionSourceLine > $__versionSourceFile
309             fi
310         fi
311
312
313         pushd "$intermediatesForBuild"
314         # Regenerate the CMake solution
315         echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator $extraCmakeArguments $__cmakeargs"
316         "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$extraCmakeArguments" "$__cmakeargs"
317         popd
318     fi
319
320     if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
321         echo "Failed to generate $message build project!"
322         exit 1
323     fi
324
325     # Build
326     if [ $__ConfigureOnly == 1 ]; then
327         echo "Finish configuration & skipping $message build."
328         return
329     fi
330
331     # Check that the makefiles were created.
332     pushd "$intermediatesForBuild"
333
334     echo "Executing $buildTool install -j $__NumProc"
335
336     $buildTool install -j $__NumProc
337     if [ $? != 0 ]; then
338         echo "Failed to build $message."
339         exit 1
340     fi
341
342     popd
343 }
344
345 build_cross_arch_component()
346 {
347     __SkipCrossArchBuild=1
348     TARGET_ROOTFS=""
349     # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
350     if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && "$__CrossArch" == "x86" ]]; then
351         export CROSSCOMPILE=0
352         __SkipCrossArchBuild=0
353
354         # building x64-host/arm-target cross-architecture component need to use cross toolchain of x86
355         if [ "$__HostArch" == "x64" ]; then
356             export CROSSCOMPILE=1
357         fi
358     elif [[ ("$__BuildArch" == "arm64") && "$__CrossArch" == "x64" ]]; then
359         export CROSSCOMPILE=0
360         __SkipCrossArchBuild=0
361     else
362         # not supported
363         return
364     fi
365
366     export __CMakeBinDir="$__CrossComponentBinDir"
367     export CROSSCOMPONENT=1
368     __IncludeTests=
369
370     if [ $CROSSCOMPILE == 1 ]; then
371         TARGET_ROOTFS="$ROOTFS_DIR"
372         if [ -n "$CAC_ROOTFS_DIR" ]; then
373             export ROOTFS_DIR="$CAC_ROOTFS_DIR"
374         else
375             export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__CrossArch"
376         fi
377     fi
378
379     __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_VERSION=$__PgoOptDataVersion -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize"
380     build_native $__SkipCrossArchBuild "$__CrossArch" "$__CrossCompIntermediatesDir" "$__ExtraCmakeArgs" "cross-architecture component"
381
382     # restore ROOTFS_DIR, CROSSCOMPONENT, and CROSSCOMPILE
383     if [ -n "$TARGET_ROOTFS" ]; then
384         export ROOTFS_DIR="$TARGET_ROOTFS"
385     fi
386     export CROSSCOMPONENT=
387     export CROSSCOMPILE=1
388 }
389
390 isMSBuildOnNETCoreSupported()
391 {
392     __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
393
394     if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
395         return
396     fi
397
398     if [ "$__HostArch" == "x64" ]; then
399         if [ "$__HostOS" == "Linux" ]; then
400             __isMSBuildOnNETCoreSupported=1
401             # note: the RIDs below can use globbing patterns
402             UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
403             for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
404             do
405                 if [[ $__HostDistroRid == $UNSUPPORTED_RID ]]; then
406                     __isMSBuildOnNETCoreSupported=0
407                     break
408                 fi
409             done
410         elif [ "$__HostOS" == "OSX" ]; then
411             __isMSBuildOnNETCoreSupported=1
412         fi
413     fi
414 }
415
416
417 build_CoreLib_ni()
418 {
419     local __CrossGenExec=$1
420
421     echo "Generating native image for System.Private.CoreLib.dll"
422     echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
423     $__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll
424     if [ $? -ne 0 ]; then
425         echo "Failed to generate native image for System.Private.CoreLib."
426         exit 1
427     fi
428
429     if [ "$__BuildOS" == "Linux" ]; then
430         echo "Generating symbol file for System.Private.CoreLib.dll"
431         echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
432         $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll
433         if [ $? -ne 0 ]; then
434             echo "Failed to generate symbol file for System.Private.CoreLib."
435             exit 1
436         fi
437     fi
438 }
439
440 build_CoreLib()
441 {
442     if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
443         echo "System.Private.CoreLib.dll build unsupported."
444         return
445     fi
446
447     if [ $__SkipMSCorLib == 1 ]; then
448        echo "Skipping building System.Private.CoreLib."
449        return
450     fi
451
452     echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
453
454     # Invoke MSBuild
455     __ExtraBuildArgs=""
456     if [[ "$__IbcTuning" -eq "" ]]; then
457         __ExtraBuildArgs="$__ExtraBuildArgs -OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data/\""
458         __ExtraBuildArgs="$__ExtraBuildArgs -EnableProfileGuidedOptimization=true"
459     fi
460     $__ProjectRoot/run.sh build -Project=$__ProjectDir/build.proj -MsBuildEventLogging="/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log" -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false $__RunArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
461
462     if [ $? -ne 0 ]; then
463         echo "Failed to build managed components."
464         exit 1
465     fi
466
467     if [ $__SkipCrossgen == 1 ]; then
468         echo "Skipping generating native image"
469         return
470     fi
471
472     # The cross build generates a crossgen with the target architecture.
473     if [ $__CrossBuild == 0 ]; then
474        if [ $__SkipCoreCLR == 1 ]; then
475            return
476        fi
477
478        # The architecture of host pc must be same architecture with target.
479        if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
480            build_CoreLib_ni "$__BinDir/crossgen"
481        elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
482            build_CoreLib_ni "$__BinDir/crossgen"
483        elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
484            build_CoreLib_ni "$__BinDir/crossgen"
485        else
486            exit 1
487        fi
488     elif [ $__DoCrossArchBuild == 1 ]; then
489        if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
490            build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
491        elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
492            build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
493        fi
494     fi
495 }
496
497 generate_NugetPackages()
498 {
499     # We can only generate nuget package if we also support building mscorlib as part of this build.
500     if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
501         echo "Nuget package generation unsupported."
502         return
503     fi
504
505     # Since we can build mscorlib for this OS, did we build the native components as well?
506     if [ $__SkipCoreCLR == 1 ]; then
507         echo "Unable to generate nuget packages since native components were not built."
508         return
509     fi
510
511     echo "Generating nuget packages for "$__BuildOS
512     echo "DistroRid is "$__DistroRid
513     echo "ROOTFS_DIR is "$ROOTFS_DIR
514     # Build the packages
515     $__ProjectRoot/run.sh build -Project=$__SourceDir/.nuget/packages.builds -MsBuildEventLogging="/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log" -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false -__DoCrossArchBuild=$__DoCrossArchBuild $__RunArgs $__UnprocessedBuildArgs
516
517     if [ $? -ne 0 ]; then
518         echo "Failed to generate Nuget packages."
519         exit 1
520     fi
521 }
522
523 echo "Commencing CoreCLR Repo build"
524
525 # Argument types supported by this script:
526 #
527 # Build architecture - valid values are: x64, ARM.
528 # Build Type         - valid values are: Debug, Checked, Release
529 #
530 # Set the default arguments for build
531
532 # Obtain the location of the bash script to figure out where the root of the repo is.
533 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
534
535 # Use uname to determine what the CPU is.
536 CPUName=$(uname -p)
537 # Some Linux platforms report unknown for platform, but the arch for machine.
538 if [ "$CPUName" == "unknown" ]; then
539     CPUName=$(uname -m)
540 fi
541
542 case $CPUName in
543     i686)
544         echo "Unsupported CPU $CPUName detected, build might not succeed!"
545         __BuildArch=x86
546         __HostArch=x86
547         ;;
548
549     x86_64)
550         __BuildArch=x64
551         __HostArch=x64
552         ;;
553
554     armv7l)
555         echo "Unsupported CPU $CPUName detected, build might not succeed!"
556         __BuildArch=arm
557         __HostArch=arm
558         ;;
559
560     aarch64)
561         __BuildArch=arm64
562         __HostArch=arm64
563         ;;
564
565     amd64)
566         __BuildArch=x64
567         __HostArch=x64
568         ;;
569     *)
570         echo "Unknown CPU $CPUName detected, configuring as if for x64"
571         __BuildArch=x64
572         __HostArch=x64
573         ;;
574 esac
575
576 # Use uname to determine what the OS is.
577 OSName=$(uname -s)
578 case $OSName in
579     Linux)
580         __BuildOS=Linux
581         __HostOS=Linux
582         ;;
583
584     Darwin)
585         __BuildOS=OSX
586         __HostOS=OSX
587         ;;
588
589     FreeBSD)
590         __BuildOS=FreeBSD
591         __HostOS=FreeBSD
592         ;;
593
594     OpenBSD)
595         __BuildOS=OpenBSD
596         __HostOS=OpenBSD
597         ;;
598
599     NetBSD)
600         __BuildOS=NetBSD
601         __HostOS=NetBSD
602         ;;
603
604     SunOS)
605         __BuildOS=SunOS
606         __HostOS=SunOS
607         ;;
608
609     *)
610         echo "Unsupported OS $OSName detected, configuring as if for Linux"
611         __BuildOS=Linux
612         __HostOS=Linux
613         ;;
614 esac
615
616 __BuildType=Debug
617 __CodeCoverage=
618 __IncludeTests=Include_Tests
619 __IgnoreWarnings=0
620
621 # Set the various build properties here so that CMake and MSBuild can pick them up
622 __ProjectDir="$__ProjectRoot"
623 __SourceDir="$__ProjectDir/src"
624 __PackagesDir="${DotNetRestorePackagesPath:-${__ProjectDir}/packages}"
625 __RootBinDir="$__ProjectDir/bin"
626 __UnprocessedBuildArgs=
627 __RunArgs=
628 __MSBCleanBuildArgs=
629 __UseNinja=0
630 __VerboseBuild=0
631 __PgoInstrument=0
632 __PgoOptimize=1
633 __IbcTuning=""
634 __ConfigureOnly=0
635 __SkipConfigure=0
636 __SkipRestore=""
637 __SkipNuget=0
638 __SkipCoreCLR=0
639 __SkipMSCorLib=0
640 __SkipRestoreOptData=0
641 __SkipCrossgen=0
642 __CrossBuild=0
643 __ClangMajorVersion=0
644 __ClangMinorVersion=0
645 __NuGetPath="$__PackagesDir/NuGet.exe"
646 __HostDistroRid=""
647 __DistroRid=""
648 __cmakeargs=""
649 __SkipGenerateVersion=0
650 __DoCrossArchBuild=0
651 __PortableBuild=1
652 __msbuildonunsupportedplatform=0
653 __PgoOptDataVersion=""
654 __IbcOptDataVersion=""
655
656 # Get the number of processors available to the scheduler
657 # Other techniques such as `nproc` only get the number of
658 # processors available to a single process.
659 if [ `uname` = "FreeBSD" ]; then
660   __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
661 elif [ `uname` = "NetBSD" ]; then
662   __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
663 elif [ `uname` = "Darwin" ]; then
664   __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
665 else
666   __NumProc=$(nproc --all)
667 fi
668
669 while :; do
670     if [ $# -le 0 ]; then
671         break
672     fi
673
674     lowerI="$(echo $1 | awk '{print tolower($0)}')"
675     case $lowerI in
676         -\?|-h|--help)
677             usage
678             exit 1
679             ;;
680
681         x86|-x86)
682             __BuildArch=x86
683             ;;
684
685         x64|-x64)
686             __BuildArch=x64
687             ;;
688
689         arm|-arm)
690             __BuildArch=arm
691             ;;
692
693         armel|-armel)
694             __BuildArch=armel
695             ;;
696
697         arm64|-arm64)
698             __BuildArch=arm64
699             ;;
700
701         debug|-debug)
702             __BuildType=Debug
703             ;;
704
705         checked|-checked)
706             __BuildType=Checked
707             ;;
708
709         release|-release)
710             __BuildType=Release
711             ;;
712
713         coverage|-coverage)
714             __CodeCoverage=Coverage
715             ;;
716
717         cross|-cross)
718             __CrossBuild=1
719             ;;
720
721         -portablebuild=false)
722             __PortableBuild=0
723             ;;
724
725         verbose|-verbose)
726             __VerboseBuild=1
727             ;;
728
729         stripsymbols|-stripsymbols)
730             __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
731             ;;
732
733         clang3.5|-clang3.5)
734             __ClangMajorVersion=3
735             __ClangMinorVersion=5
736             ;;
737
738         clang3.6|-clang3.6)
739             __ClangMajorVersion=3
740             __ClangMinorVersion=6
741             ;;
742
743         clang3.7|-clang3.7)
744             __ClangMajorVersion=3
745             __ClangMinorVersion=7
746             ;;
747
748         clang3.8|-clang3.8)
749             __ClangMajorVersion=3
750             __ClangMinorVersion=8
751             ;;
752
753         clang3.9|-clang3.9)
754             __ClangMajorVersion=3
755             __ClangMinorVersion=9
756             ;;
757
758         clang4.0|-clang4.0)
759             __ClangMajorVersion=4
760             __ClangMinorVersion=0
761             ;;
762
763         clang5.0|-clang5.0)
764             __ClangMajorVersion=5
765             __ClangMinorVersion=0
766             ;;
767
768         clang6.0|-clang6.0)
769             __ClangMajorVersion=6
770             __ClangMinorVersion=0
771             ;;
772
773         ninja|-ninja)
774             __UseNinja=1
775             ;;
776
777         pgoinstrument|-pgoinstrument)
778             __PgoInstrument=1
779             ;;
780
781         nopgooptimize|-nopgooptimize)
782             __PgoOptimize=0
783             __SkipRestoreOptData=1
784             ;;
785
786         ibcinstrument|-ibcinstrument)
787             __IbcTuning="/Tuning"
788             ;;
789
790         configureonly|-configureonly)
791             __ConfigureOnly=1
792             __SkipMSCorLib=1
793             __SkipNuget=1
794             ;;
795
796         skipconfigure|-skipconfigure)
797             __SkipConfigure=1
798             ;;
799
800         skipnative|-skipnative)
801             # Use "skipnative" to use the same option name as build.cmd.
802             __SkipCoreCLR=1
803             ;;
804
805         skipcoreclr|-skipcoreclr)
806             # Accept "skipcoreclr" for backwards-compatibility.
807             __SkipCoreCLR=1
808             ;;
809
810         crosscomponent|-crosscomponent)
811             __DoCrossArchBuild=1
812             ;;
813
814         skipmscorlib|-skipmscorlib)
815             __SkipMSCorLib=1
816             ;;
817
818         skipgenerateversion|-skipgenerateversion)
819             __SkipGenerateVersion=1
820             ;;
821
822         skiprestoreoptdata|-skiprestoreoptdata)
823             __SkipRestoreOptData=1
824             ;;
825
826         skipcrossgen|-skipcrossgen)
827             __SkipCrossgen=1
828             ;;
829
830         includetests|-includetests)
831             ;;
832
833         skiptests|-skiptests)
834             __IncludeTests=
835             ;;
836
837         skipnuget|-skipnuget)
838             __SkipNuget=1
839             ;;
840
841         ignorewarnings|-ignorewarnings)
842             __IgnoreWarnings=1
843             __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
844             ;;
845
846         cmakeargs|-cmakeargs)
847             if [ -n "$2" ]; then
848                 __cmakeargs="$__cmakeargs $2"
849                 shift
850             else
851                 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
852                 exit 1
853             fi
854             ;;
855
856         bindir|-bindir)
857             if [ -n "$2" ]; then
858                 __RootBinDir="$2"
859                 if [ ! -d $__RootBinDir ]; then
860                     mkdir $__RootBinDir
861                 fi
862                 __RootBinParent=$(dirname $__RootBinDir)
863                 __RootBinName=${__RootBinDir##*/}
864                 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
865                 shift
866             else
867                 echo "ERROR: 'bindir' requires a non-empty option argument"
868                 exit 1
869             fi
870             ;;
871         msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
872             __msbuildonunsupportedplatform=1
873             ;;
874         numproc|-numproc)
875             if [ -n "$2" ]; then
876               __NumProc="$2"
877               shift
878             else
879               echo "ERROR: 'numproc' requires a non-empty option argument"
880               exit 1
881             fi
882             ;;
883         osgroup|-osgroup)
884             if [ -n "$2" ]; then
885               __BuildOS="$2"
886               shift
887             else
888               echo "ERROR: 'osgroup' requires a non-empty option argument"
889               exit 1
890             fi
891             ;;
892
893         *)
894             __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
895             ;;
896     esac
897
898     shift
899 done
900
901 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
902
903 # Configure environment if we are doing a verbose build
904 if [ $__VerboseBuild == 1 ]; then
905     export VERBOSE=1
906         __RunArgs="$__RunArgs -verbose"
907 fi
908
909 # Set default clang version
910 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
911         if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
912                 __ClangMajorVersion=5
913                 __ClangMinorVersion=0
914         else
915                 __ClangMajorVersion=3
916                 __ClangMinorVersion=9
917         fi
918 fi
919
920 if [[ "$__BuildArch" == "armel" ]]; then
921     # Armel cross build is Tizen specific and does not support Portable RID build
922     __PortableBuild=0
923 fi
924
925 if [ $__PortableBuild == 0 ]; then
926         __RunArgs="$__RunArgs -PortableBuild=false"
927 fi
928
929 # Set dependent variables
930 __LogsDir="$__RootBinDir/Logs"
931
932 # init the host distro name
933 initHostDistroRid
934
935 # Set the remaining variables based upon the determined build configuration
936 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
937 __PackagesBinDir="$__BinDir/.nuget"
938 __ToolsDir="$__RootBinDir/tools"
939 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
940 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
941 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
942 __isMSBuildOnNETCoreSupported=0
943 __CrossComponentBinDir="$__BinDir"
944 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
945
946 __CrossArch="$__HostArch"
947 if [[ "$__HostArch" == "x64" && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
948     __CrossArch="x86"
949 fi
950 if [ $__CrossBuild == 1 ]; then
951     __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
952 fi
953 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
954 __CrossgenExe="$__CrossComponentBinDir/crossgen"
955
956 # Init if MSBuild for .NET Core is supported for this platform
957 isMSBuildOnNETCoreSupported
958
959 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
960 # This is needed by CLI to function.
961 if [ -z "$HOME" ]; then
962     if [ ! -d "$__ProjectDir/temp_home" ]; then
963         mkdir temp_home
964     fi
965     export HOME=$__ProjectDir/temp_home
966     echo "HOME not defined; setting it to $HOME"
967 fi
968
969 # Specify path to be set for CMAKE_INSTALL_PREFIX.
970 # This is where all built CoreClr libraries will copied to.
971 export __CMakeBinDir="$__BinDir"
972
973 # Configure environment if we are doing a cross compile.
974 if [ $__CrossBuild == 1 ]; then
975     export CROSSCOMPILE=1
976     if ! [[ -n "$ROOTFS_DIR" ]]; then
977         export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
978     fi
979 fi
980
981 # init the target distro name
982 initTargetDistroRid
983
984 # Make the directories necessary for build if they don't exist
985 setup_dirs
986
987 # Check prereqs.
988 check_prereqs
989
990 # Restore the package containing profile counts for profile-guided optimizations
991 restore_optdata
992
993 # Generate event logging infrastructure sources
994 generate_event_logging
995
996 # Build the coreclr (native) components.
997 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_VERSION=$__PgoOptDataVersion -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize"
998 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
999
1000 # Build cross-architecture components
1001 if [[ $__CrossBuild == 1 && $__DoCrossArchBuild == 1 ]]; then
1002     build_cross_arch_component
1003 fi
1004
1005 # Build System.Private.CoreLib.
1006
1007 build_CoreLib
1008
1009 # Generate nuget packages
1010 if [ $__SkipNuget != 1 ]; then
1011     generate_NugetPackages
1012 fi
1013
1014
1015 # Build complete
1016
1017 echo "Repo successfully built."
1018 echo "Product binaries are available at $__BinDir"
1019 exit 0