Merge pull request #14193 from wtgodbe/SigningInfra
[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             __HostDistroRid="$ID.$VERSION_ID-$__Arch"
20         elif [ -e /etc/redhat-release ]; then
21             local redhatRelease=$(</etc/redhat-release)
22             if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
23                __HostDistroRid="rhel.6-$__Arch"
24             fi
25         fi
26     fi
27
28     if [ "$__HostDistroRid" == "" ]; then
29         echo "WARNING: Can not determine runtime id for current distro."
30     fi
31 }
32
33 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
34 __IsPortableBuild=1
35
36 # Use uname to determine what the OS is.
37 OSName=$(uname -s)
38 case $OSName in
39     Linux)
40         __BuildOS=Linux
41         __HostOS=Linux
42         ;;
43
44     Darwin)
45         __BuildOS=OSX
46         __HostOS=OSX
47         ;;
48
49     FreeBSD)
50         __BuildOS=FreeBSD
51         __HostOS=FreeBSD
52         ;;
53
54     OpenBSD)
55         __BuildOS=OpenBSD
56         __HostOS=OpenBSD
57         ;;
58
59     NetBSD)
60         __BuildOS=NetBSD
61         __HostOS=NetBSD
62         ;;
63
64     SunOS)
65         __BuildOS=SunOS
66         __HostOS=SunOS
67         ;;
68
69     *)
70         echo "Unsupported OS $OSName detected, configuring as if for Linux"
71         __BuildOS=Linux
72         __HostOS=Linux
73         ;;
74 esac
75
76 unprocessedBuildArgs=
77
78 while :; do
79     if [ $# -le 0 ]; then
80         break
81     fi
82
83     case "$1" in
84         -\?|-h|--help)
85         usage
86         exit 1
87         ;;
88         -BuildArch=*)
89         unprocessedBuildArgs="$unprocessedBuildArgs $1"
90         __Arch=$(echo $1| cut -d'=' -f 2)
91         ;;
92
93         -portablebuild=false)
94             unprocessedBuildArgs="$unprocessedBuildArgs $1"
95             __IsPortableBuild=0
96             ;;
97         *)
98         unprocessedBuildArgs="$unprocessedBuildArgs $1"
99     esac
100     shift
101 done
102
103 # Portable builds target the base RID
104 if [ $__IsPortableBuild == 1 ]; then
105     if [ "$__BuildOS" == "Linux" ]; then
106         export __DistroRid="linux-$__Arch"
107     elif [ "$__BuildOS" == "OSX" ]; then
108         export __DistroRid="osx-$__Arch"
109     fi
110 else
111     # init the host distro name
112     initHostDistroRid
113     export __DistroRid="$__HostDistroRid"
114 fi
115
116 $__ProjectRoot/run.sh build-packages -Project=$__ProjectRoot/src/.nuget/packages.builds -DistroRid=$__DistroRid -UseSharedCompilation=false -BuildNugetPackage=false $unprocessedBuildArgs
117 if [ $? -ne 0 ]
118 then
119     echo "ERROR: An error occurred while building packages; See build-packages.log for more details."
120     exit 1
121 fi
122
123 echo "Done building packages."
124 exit 0