Fix build error for mscoree coreclr.exports (#24547)
[platform/upstream/coreclr.git] / build-packages.sh
index 382e24d..8dfab68 100755 (executable)
@@ -3,16 +3,30 @@
 usage()
 {
     echo "Builds the NuGet packages from the binaries that were built in the Build product binaries step."
-    echo "Usage: build-packages -BuildArch -BuildType [-portable]"
+    echo "Usage: build-packages -BuildArch -BuildType"
     echo "BuildArch can be x64, x86, arm, arm64 (default is x64)"
     echo "BuildType can be release, checked, debug (default is debug)"
-    echo "-portable - build for Portable Distribution"
     echo
     exit 1
 }
 
+initDistroRid()
+{
+    source init-distro-rid.sh
+
+    local passedRootfsDir=""
+
+    # Only pass ROOTFS_DIR if __DoCrossArchBuild is specified.
+    if (( ${__CrossBuild} == 1 )); then
+        passedRootfsDir=${ROOTFS_DIR}
+    fi
+
+    initDistroRidGlobal ${__BuildOS} ${__BuildArch} ${__IsPortableBuild} ${passedRootfsDir}
+}
+
 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-__PortableBuild=0
+__IsPortableBuild=1
+__CrossBuild=0
 
 # Use uname to determine what the OS is.
 OSName=$(uname -s)
@@ -54,8 +68,11 @@ case $OSName in
         ;;
 esac
 
+buildArgs=
 unprocessedBuildArgs=
 
+# TODO: get rid of argument processing entirely once we remove the
+# uses of -Arg=Value style in buildpipeline.
 while :; do
     if [ $# -le 0 ]; then
         break
@@ -63,35 +80,57 @@ while :; do
 
     case "$1" in
         -\?|-h|--help)
-        usage
-        exit 1
-        ;;
+            usage
+            exit 1
+            ;;
         -BuildArch=*)
-        unprocessedBuildArgs="$unprocessedBuildArgs $1"
-        __Arch=$(echo $1| cut -d'=' -f 2)
-        ;;
-
-        -portableBuild)
-            __PortableBuild=1
+            __BuildArch=$(echo $1| cut -d'=' -f 2)
+            buildArgs="$buildArgs /p:__BuildArch=$__BuildArch"
+            ;;
+        -BuildType=*)
+            __Type=$(echo $1| cut -d'=' -f 2)
+            buildArgs="$buildArgs /p:__BuildType=$__Type"
+            ;;
+        -OfficialBuildId=*)
+            __Id=$(echo $1| cut -d'=' -f 2)
+            buildArgs="$buildArgs /p:OfficialBuildId=$__Id"
+            ;;
+        -__DoCrossArchBuild=*)
+            __CrossBuild=$(echo $1| cut -d'=' -f 2)
+            buildArgs="$buildArgs /p:__DoCrossArchBuild=$__CrossBuild"
+            ;;
+        -portablebuild=false)
+            buildArgs="$buildArgs /p:PortableBuild=false"
+            __IsPortableBuild=0
+            ;;
+        --)
             ;;
         *)
-        unprocessedBuildArgs="$unprocessedBuildArgs $1"
+            unprocessedBuildArgs="$unprocessedBuildArgs $1"
     esac
     shift
 done
 
-# Portable builds target the base RID
-if [ $__PortableBuild == 1 ]; then
-    if [ "$__BuildOS" == "Linux" ]; then
-        export __DistroRid="linux-$__Arch"
-    elif [ "$__BuildOS" == "OSX" ]; then
-        export __DistroRid="osx-$__Arch"
-    fi
-else
-    export __DistroRid="\${OSRid}-$__Arch"
+initDistroRid
+
+if [ "${__DistroRid}" = "linux-musl-arm64" ]; then
+    # ArchGroup is generally determined from parsing {}-{}; however, linux-musl-arm64
+    # will break this logic. To work around this, pass ArchGroup explicitely.
+
+    export ArchGroup=arm64
+
+    # Currently the decision tree in src/.nuget/dirs.props will incorrectly
+    # reparse the already calculated __DistroRid. For linux-musl-arm64 use
+    # the hack/hook to specifically bypass this logic.
+    export OutputRID=${__DistroRid}
 fi
 
-$__ProjectRoot/run.sh build-packages -Project=$__ProjectRoot/src/.nuget/packages.builds -DistroRid=$__DistroRid -UseSharedCompilation=false -BuildNugetPackage=false $unprocessedBuildArgs
+$__ProjectRoot/dotnet.sh msbuild /nologo /verbosity:minimal /clp:Summary \
+                         /p:__BuildOS=$__BuildOS /flp:v=detailed\;Append\;LogFile=build-packages.log \
+                         /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
+                         /p:PortableBuild=true src/.nuget/packages.builds \
+                         /p:__DistroRid=$__DistroRid /p:BuildNugetPackage=false \
+                         $buildArgs $unprocessedBuildArgs
 if [ $? -ne 0 ]
 then
     echo "ERROR: An error occurred while building packages; See build-packages.log for more details."