Fix regeression with Containment
[platform/upstream/coreclr.git] / build.sh
index 30856d5..c02b5b0 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -19,54 +19,63 @@ fi
 
 usage()
 {
-    echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [configureonly] [skipconfigure] [skipnative] [skipmscorlib] [skiptests] [stripsymbols] [ignorewarnings] [cmakeargs] [bindir]"
-    echo "BuildArch can be: x64, x86, arm, armel, arm64"
-    echo "BuildType can be: debug, checked, release"
-    echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
-    echo "ninja - target ninja instead of GNU make"
-    echo "clangx.y - optional argument to build using clang version x.y."
-    echo "cross - optional argument to signify cross compilation,"
-    echo "      - will use ROOTFS_DIR environment variable if set."
-    echo "crosscomponent - optional argument to build cross-architecture component,"
-    echo "               - will use CAC_ROOTFS_DIR environment variable if set."
-    echo "pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
-    echo "ibcinstrument - generate IBC-tuning-enabled native images when invoking crossgen."
-    echo "configureonly - do not perform any builds; just configure the build."
-    echo "skipconfigure - skip build configuration."
-    echo "skipnative - do not build native components."
-    echo "skipmscorlib - do not build mscorlib.dll."
-    echo "skiptests - skip the tests in the 'tests' subdirectory."
-    echo "skipnuget - skip building nuget packages."
-    echo "skiprestoreoptdata - skip restoring optimization data used by profile-based optimizations."
-    echo "verbose - optional argument to enable verbose build output."
+    echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"
+    echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64"
+    echo "BuildType can be: -debug, -checked, -release"
+    echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
+    echo "-ninja - target ninja instead of GNU make"
+    echo "-clangx.y - optional argument to build using clang version x.y."
+    echo "-cross - optional argument to signify cross compilation,"
+    echo "       - will use ROOTFS_DIR environment variable if set."
+    echo "-crosscomponent - optional argument to build cross-architecture component,"
+    echo "                - will use CAC_ROOTFS_DIR environment variable if set."
+    echo "-nopgooptimize - do not use profile guided optimizations."
+    echo "-pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
+    echo "-ibcinstrument - generate IBC-tuning-enabled native images when invoking crossgen."
+    echo "-configureonly - do not perform any builds; just configure the build."
+    echo "-skipconfigure - skip build configuration."
+    echo "-skipnative - do not build native components."
+    echo "-skipmscorlib - do not build mscorlib.dll."
+    echo "-skiptests - skip the tests in the 'tests' subdirectory."
+    echo "-skipnuget - skip building nuget packages."
+    echo "-skiprestoreoptdata - skip restoring optimization data used by profile-based optimizations."
+    echo "-skipcrossgen - skip native image generation"
+    echo "-verbose - optional argument to enable verbose build output."
     echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
        echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
        echo "-sequential: force a non-parallel build ^(default is to build in parallel"
        echo "   using all processors^)."
        echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
        echo "-Rebuild: passes /t:rebuild to the build projects."
-    echo "stripSymbols - Optional argument to strip native symbols during the build."
-    echo "skipgenerateversion - disable version generation even if MSBuild is supported."
-    echo "ignorewarnings - do not treat warnings as errors"
-    echo "cmakeargs - user-settable additional arguments passed to CMake."
-    echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
-    echo "buildstandalonegc - builds the GC in a standalone mode. Can't be used with \"cmakeargs\"."
-    echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
-    echo "numproc - set the number of build processes."
+    echo "-stripSymbols - Optional argument to strip native symbols during the build."
+    echo "-skipgenerateversion - disable version generation even if MSBuild is supported."
+    echo "-ignorewarnings - do not treat warnings as errors"
+    echo "-cmakeargs - user-settable additional arguments passed to CMake."
+    echo "-bindir - output directory (defaults to $__ProjectRoot/bin)"
+    echo "-buildstandalonegc - builds the GC in a standalone mode. Can't be used with \"cmakeargs\"."
+    echo "-msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
+    echo "-numproc - set the number of build processes."
     exit 1
 }
 
 initHostDistroRid()
 {
+    __HostDistroRid=""
     if [ "$__HostOS" == "Linux" ]; then
-        if [ ! -e /etc/os-release ]; then
-            echo "WARNING: Can not determine runtime id for current distro."
-            __HostDistroRid=""
-        else
+        if [ -e /etc/os-release ]; then
             source /etc/os-release
             __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
+        elif [ -e /etc/redhat-release ]; then
+            local redhatRelease=$(</etc/redhat-release)
+            if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
+               __HostDistroRid="rhel.6-$__HostArch"
+            fi
         fi
     fi
+
+    if [ "$__HostDistroRid" == "" ]; then
+        echo "WARNING: Can not determine runtime id for current distro."
+    fi
 }
 
 initTargetDistroRid()
@@ -139,28 +148,31 @@ check_prereqs()
 
 restore_optdata()
 {
-    # if msbuild is not supported, then set __SkipRestoreOptData to 1
-    if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipRestoreOptData=1; fi
     # we only need optdata on a Release build
     if [[ "$__BuildType" != "Release" ]]; then __SkipRestoreOptData=1; fi
 
-    if [ $__SkipRestoreOptData == 0 ]; then
+    if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
         echo "Restoring the OptimizationData package"
         "$__ProjectRoot/run.sh" sync -optdata
         if [ $? != 0 ]; then
             echo "Failed to restore the optimization data package."
             exit 1
         fi
+    fi
 
+    if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
         # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
         local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
         if [ ! -f $DotNetCli ]; then
-            echo "Assertion failed: dotnet CLI not found at '$DotNetCli'"
-            exit 1
+            "$__ProjectRoot/init-tools.sh"
+            if [ $? != 0 ]; then
+                echo "Failed to restore buildtools."
+                exit 1
+            fi
         fi
         local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
-        __PgoOptDataVersion=$($DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
-        __IbcOptDataVersion=$($DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^\s*//')
+        __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
+        __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^\s*//')
     fi
 }
 
@@ -199,7 +211,7 @@ generate_event_logging_sources()
         __PythonWarningFlags="$__PythonWarningFlags -Werror"
     fi
 
-    
+
     if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
         echo "Laying out dynamically generated files consumed by the build system "
         echo "Laying out dynamically generated Event Logging Test files"
@@ -337,7 +349,7 @@ build_cross_arch_component()
     __SkipCrossArchBuild=1
     TARGET_ROOTFS=""
     # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
-    if [[ "$__BuildArch" == "arm" && "$__CrossArch" == "x86" ]]; then
+    if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && "$__CrossArch" == "x86" ]]; then
         export CROSSCOMPILE=0
         __SkipCrossArchBuild=0
 
@@ -348,8 +360,8 @@ build_cross_arch_component()
     else
         # not supported
         return
-    fi    
-    
+    fi
+
     export __CMakeBinDir="$__CrossComponentBinDir"
     export CROSSCOMPONENT=1
     __IncludeTests=
@@ -363,10 +375,10 @@ build_cross_arch_component()
         fi
     fi
 
-    __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"
+    __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"
     build_native $__SkipCrossArchBuild "$__CrossArch" "$__CrossCompIntermediatesDir" "$__ExtraCmakeArgs" "cross-architecture component"
-   
-    # restore ROOTFS_DIR, CROSSCOMPONENT, and CROSSCOMPILE 
+
+    # restore ROOTFS_DIR, CROSSCOMPONENT, and CROSSCOMPILE
     if [ -n "$TARGET_ROOTFS" ]; then
         export ROOTFS_DIR="$TARGET_ROOTFS"
     fi
@@ -385,10 +397,11 @@ isMSBuildOnNETCoreSupported()
     if [ "$__HostArch" == "x64" ]; then
         if [ "$__HostOS" == "Linux" ]; then
             __isMSBuildOnNETCoreSupported=1
-            UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
+            # note: the RIDs below can use globbing patterns
+            UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64" "alpine.3.6.*-x64")
             for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
             do
-                if [ "$__HostDistroRid" == "$UNSUPPORTED_RID" ]; then
+                if [[ $__HostDistroRid == $UNSUPPORTED_RID ]]; then
                     __isMSBuildOnNETCoreSupported=0
                     break
                 fi
@@ -402,8 +415,14 @@ isMSBuildOnNETCoreSupported()
 
 build_CoreLib_ni()
 {
+    if [ $__SkipCrossgen == 1 ]; then
+        echo "Skipping generating native image"
+        return
+    fi
+
     if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
         echo "Generating native image for System.Private.CoreLib."
+        echo "$__BinDir/crossgen /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
         $__BinDir/crossgen /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll
         if [ $? -ne 0 ]; then
             echo "Failed to generate native image for System.Private.CoreLib."
@@ -458,10 +477,10 @@ build_CoreLib()
            build_CoreLib_ni
        elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
            build_CoreLib_ni
-       else 
+       else
            exit 1
        fi
-    fi 
+    fi
 }
 
 generate_NugetPackages()
@@ -595,6 +614,7 @@ __MSBCleanBuildArgs=
 __UseNinja=0
 __VerboseBuild=0
 __PgoInstrument=0
+__PgoOptimize=1
 __IbcTuning=""
 __ConfigureOnly=0
 __SkipConfigure=0
@@ -603,6 +623,7 @@ __SkipNuget=0
 __SkipCoreCLR=0
 __SkipMSCorLib=0
 __SkipRestoreOptData=0
+__SkipCrossgen=0
 __CrossBuild=0
 __ClangMajorVersion=0
 __ClangMinorVersion=0
@@ -640,153 +661,162 @@ while :; do
             exit 1
             ;;
 
-        x86)
+        x86|-x86)
             __BuildArch=x86
             ;;
 
-        x64)
+        x64|-x64)
             __BuildArch=x64
             ;;
 
-        arm)
+        arm|-arm)
             __BuildArch=arm
             ;;
 
-        armel)
+        armel|-armel)
             __BuildArch=armel
             ;;
 
-        arm64)
+        arm64|-arm64)
             __BuildArch=arm64
             ;;
 
-        debug)
+        debug|-debug)
             __BuildType=Debug
             ;;
 
-        checked)
+        checked|-checked)
             __BuildType=Checked
             ;;
 
-        release)
+        release|-release)
             __BuildType=Release
             ;;
 
-        coverage)
+        coverage|-coverage)
             __CodeCoverage=Coverage
             ;;
 
-        cross)
+        cross|-cross)
             __CrossBuild=1
             ;;
-            
+
         -portablebuild=false)
             __PortableBuild=0
             ;;
 
-        verbose)
+        verbose|-verbose)
             __VerboseBuild=1
             ;;
 
-        stripsymbols)
+        stripsymbols|-stripsymbols)
             __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
             ;;
 
-        clang3.5)
+        clang3.5|-clang3.5)
             __ClangMajorVersion=3
             __ClangMinorVersion=5
             ;;
 
-        clang3.6)
+        clang3.6|-clang3.6)
             __ClangMajorVersion=3
             __ClangMinorVersion=6
             ;;
 
-        clang3.7)
+        clang3.7|-clang3.7)
             __ClangMajorVersion=3
             __ClangMinorVersion=7
             ;;
 
-        clang3.8)
+        clang3.8|-clang3.8)
             __ClangMajorVersion=3
             __ClangMinorVersion=8
             ;;
 
-        clang3.9)
+        clang3.9|-clang3.9)
             __ClangMajorVersion=3
             __ClangMinorVersion=9
             ;;
 
-        clang4.0)
+        clang4.0|-clang4.0)
             __ClangMajorVersion=4
             __ClangMinorVersion=0
             ;;
 
-        ninja)
+        ninja|-ninja)
             __UseNinja=1
             ;;
 
-        pgoinstrument)
+        pgoinstrument|-pgoinstrument)
             __PgoInstrument=1
             ;;
 
-        ibcinstrument)
+        nopgooptimize|-nopgooptimize)
+            __PgoOptimize=0
+            __SkipRestoreOptData=1
+            ;;
+
+        ibcinstrument|-ibcinstrument)
             __IbcTuning="/Tuning"
             ;;
 
-        configureonly)
+        configureonly|-configureonly)
             __ConfigureOnly=1
             __SkipMSCorLib=1
             __SkipNuget=1
             ;;
 
-        skipconfigure)
+        skipconfigure|-skipconfigure)
             __SkipConfigure=1
             ;;
 
-        skipnative)
+        skipnative|-skipnative)
             # Use "skipnative" to use the same option name as build.cmd.
             __SkipCoreCLR=1
             ;;
 
-        skipcoreclr)
+        skipcoreclr|-skipcoreclr)
             # Accept "skipcoreclr" for backwards-compatibility.
             __SkipCoreCLR=1
             ;;
 
-        crosscomponent)
+        crosscomponent|-crosscomponent)
             __DoCrossArchBuild=1
             ;;
 
-        skipmscorlib)
+        skipmscorlib|-skipmscorlib)
             __SkipMSCorLib=1
             ;;
 
-        skipgenerateversion)
+        skipgenerateversion|-skipgenerateversion)
             __SkipGenerateVersion=1
             ;;
 
-        skiprestoreoptdata)
+        skiprestoreoptdata|-skiprestoreoptdata)
             __SkipRestoreOptData=1
             ;;
 
-        includetests)
+        skipcrossgen|-skipcrossgen)
+            __SkipCrossgen=1
+            ;;
+
+        includetests|-includetests)
             ;;
 
-        skiptests)
+        skiptests|-skiptests)
             __IncludeTests=
             ;;
 
-        skipnuget)
+        skipnuget|-skipnuget)
             __SkipNuget=1
             ;;
 
-        ignorewarnings)
+        ignorewarnings|-ignorewarnings)
             __IgnoreWarnings=1
             __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
             ;;
 
-        cmakeargs)
+        cmakeargs|-cmakeargs)
             if [ -n "$2" ]; then
                 __cmakeargs="$__cmakeargs $2"
                 shift
@@ -796,7 +826,7 @@ while :; do
             fi
             ;;
 
-        bindir)
+        bindir|-bindir)
             if [ -n "$2" ]; then
                 __RootBinDir="$2"
                 if [ ! -d $__RootBinDir ]; then
@@ -811,13 +841,13 @@ while :; do
                 exit 1
             fi
             ;;
-        buildstandalonegc)
+        buildstandalonegc|-buildstandalonegc)
             __cmakeargs="$__cmakeargs -DFEATURE_STANDALONE_GC=1 -DFEATURE_STANDALONE_GC_ONLY=1"
             ;;
-        msbuildonunsupportedplatform)
+        msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
             __msbuildonunsupportedplatform=1
             ;;
-        numproc)
+        numproc|-numproc)
             if [ -n "$2" ]; then
               __NumProc="$2"
               shift
@@ -886,7 +916,7 @@ __CrossComponentBinDir="$__BinDir"
 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
 
 __CrossArch="$__HostArch"
-if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
+if [[ "$__HostArch" == "x64" && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
     __CrossArch="x86"
 fi
 if [ $__CrossBuild == 1 ]; then
@@ -936,7 +966,7 @@ restore_optdata
 generate_event_logging_sources
 
 # Build the coreclr (native) components.
-__ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_VERSION=$__PgoOptDataVersion"
+__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"
 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
 
 # Build cross-architecture components