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