Normalize the alpine and rhel RIDs
[platform/upstream/coreclr.git] / build-packages.sh
1 #!/usr/bin/env bash
2
3 usage()
4 {
5     echo "Builds the NuGet packages from the binaries that were built in the Build product binaries step."
6     echo "Usage: build-packages -BuildArch -BuildType"
7     echo "BuildArch can be x64, x86, arm, arm64 (default is x64)"
8     echo "BuildType can be release, checked, debug (default is debug)"
9     echo
10     exit 1
11 }
12
13 initHostDistroRid()
14 {
15     __HostDistroRid=""
16     if [ "$__HostOS" == "Linux" ]; then
17         if [ -e /etc/os-release ]; then
18             source /etc/os-release
19             if [[ $ID == "alpine" || $ID == "rhel"]]; then
20                 # remove the last version digit
21                 VERSION_ID=${VERSION_ID%.*}
22             fi
23             __HostDistroRid="$ID.$VERSION_ID-$__Arch"
24         elif [ -e /etc/redhat-release ]; then
25             local redhatRelease=$(</etc/redhat-release)
26             if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
27                __HostDistroRid="rhel.6-$__Arch"
28             fi
29         fi
30     fi
31     if [ "$__HostOS" == "FreeBSD" ]; then
32         __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
33         __HostDistroRid="freebsd.$__freebsd_version-$__Arch"
34     fi
35
36     if [ "$__HostDistroRid" == "" ]; then
37         echo "WARNING: Cannot determine runtime id for current distro."
38     fi
39 }
40
41 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
42 __IsPortableBuild=1
43
44 # Use uname to determine what the OS is.
45 OSName=$(uname -s)
46 case $OSName in
47     Linux)
48         __BuildOS=Linux
49         __HostOS=Linux
50         ;;
51
52     Darwin)
53         __BuildOS=OSX
54         __HostOS=OSX
55         ;;
56
57     FreeBSD)
58         __BuildOS=FreeBSD
59         __HostOS=FreeBSD
60         ;;
61
62     OpenBSD)
63         __BuildOS=OpenBSD
64         __HostOS=OpenBSD
65         ;;
66
67     NetBSD)
68         __BuildOS=NetBSD
69         __HostOS=NetBSD
70         ;;
71
72     SunOS)
73         __BuildOS=SunOS
74         __HostOS=SunOS
75         ;;
76
77     *)
78         echo "Unsupported OS $OSName detected, configuring as if for Linux"
79         __BuildOS=Linux
80         __HostOS=Linux
81         ;;
82 esac
83
84 unprocessedBuildArgs=
85
86 while :; do
87     if [ $# -le 0 ]; then
88         break
89     fi
90
91     case "$1" in
92         -\?|-h|--help)
93         usage
94         exit 1
95         ;;
96         -BuildArch=*)
97         unprocessedBuildArgs="$unprocessedBuildArgs $1"
98         __Arch=$(echo $1| cut -d'=' -f 2)
99         ;;
100
101         -portablebuild=false)
102             unprocessedBuildArgs="$unprocessedBuildArgs $1"
103             __IsPortableBuild=0
104             ;;
105         *)
106         unprocessedBuildArgs="$unprocessedBuildArgs $1"
107     esac
108     shift
109 done
110
111 # Portable builds target the base RID
112 if [ $__IsPortableBuild == 1 ]; then
113     if [ "$__BuildOS" == "Linux" ]; then
114         export __DistroRid="linux-$__Arch"
115     elif [ "$__BuildOS" == "OSX" ]; then
116         export __DistroRid="osx-$__Arch"
117     fi
118 else
119     # init the host distro name
120     initHostDistroRid
121     export __DistroRid="$__HostDistroRid"
122 fi
123
124 $__ProjectRoot/run.sh build-packages -Project=$__ProjectRoot/src/.nuget/packages.builds -DistroRid=$__DistroRid -UseSharedCompilation=false -BuildNugetPackage=false $unprocessedBuildArgs
125 if [ $? -ne 0 ]
126 then
127     echo "ERROR: An error occurred while building packages; See build-packages.log for more details."
128     exit 1
129 fi
130
131 echo "Done building packages."
132 exit 0