Merge pull request #23366 from andy-ms/heap_hard_limit
[platform/upstream/coreclr.git] / init-distro-rid.sh
1 #!/usr/bin/env bash
2
3 # initNonPortableDistroRid
4 #
5 # Input:
6 #   buildOs: (str)
7 #   buildArch: (str)
8 #   isPortable: (int)
9 #   rootfsDir: (str)
10 #
11 # Return:
12 #   None
13 #
14 # Notes:
15 #
16 # initNonPortableDistroRid will attempt to initialize a non portable rid. These
17 # rids are specific to distros need to build the product/package and consume
18 # them on the same platform.
19 #
20 # If -portablebuild=false is passed a non-portable rid will be created for any
21 # distro.
22 #
23 # Below is the list of current non-portable platforms.
24 #
25 # Builds from the following *must* be non-portable:
26 #
27 #   |    OS     |           Expected RID            |
28 #   -------------------------------------------------
29 #   |   rhel6   |           rhel.6-x64              |
30 #   |  alpine*  |        linux-musl-(arch)          |
31 #   |  freeBSD  |        freebsd.(version)-x64      |
32 #
33 # It is important to note that the function does not return anything, but it 
34 # will set __DistroRid if there is a non-portable distro rid to be used.
35 #
36 initNonPortableDistroRid()
37 {
38     # Make sure out parameter is cleared.
39     __DistroRid=
40
41     local buildOs=$1
42     local buildArch=$2
43     local isPortable=$3
44     local rootfsDir=$4
45
46     if [ "$buildOs" = "Linux" ]; then
47         # RHEL 6 is the only distro we will check redHat release for.
48         if [ -e "${rootfsDir}/etc/os-release" ]; then
49             source "${rootfsDir}/etc/os-release"
50
51             # We have forced __PortableBuild=0. This is because -portablebuld
52             # has been passed as false.
53             if (( ${isPortable} == 0 )); then
54                 if [ "${ID}" == "rhel" ]; then
55                     # remove the last version digit     
56                     VERSION_ID=${VERSION_ID%.*}
57                 fi
58
59                 nonPortableBuildID="${ID}.${VERSION_ID}-${buildArch}"
60             fi
61             
62         elif [ -e "${rootfsDir}/etc/redhat-release" ]; then
63             local redhatRelease=$(<${rootfsDir}/etc/redhat-release)
64
65             if [[ "${redhatRelease}" == "CentOS release 6."* || "$redhatRelease" == "Red Hat Enterprise Linux Server release 6."* ]]; then
66                 nonPortableBuildID="rhel.6-${buildArch}"
67             fi
68         elif [ -e "${rootfsDir}/android_platform" ]; then
69             source $rootfsDir/android_platform
70             nonPortableBuildID="$RID"
71         fi
72     fi
73
74     if [ "$buildOs" = "FreeBSD" ]; then
75         __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
76         nonPortableBuildID="freebsd.$__freebsd_version-${buildArch}"
77     fi
78
79     if [ "${nonPortableBuildID}" != "" ]; then
80         export __DistroRid=${nonPortableBuildID}
81
82         # We are using a non-portable build rid. Force __PortableBuild to false.
83         export __PortableBuild=0
84     fi
85 }
86
87
88 # initDistroRidGlobal
89 #
90 # Input:
91 #   os: (str)
92 #   arch: (str)
93 #   isPortable: (int)
94 #   rootfsDir?: (nullable:string)
95 #
96 # Return:
97 #   None
98 #
99 # Notes:
100 #
101 # The following out parameters are returned
102 #
103 #   __DistroRid
104 #   __PortableBuild
105 #
106 initDistroRidGlobal()
107 {
108     # __DistroRid must be set at the end of the function.
109     # Previously we would create a variable __HostDistroRid and/or __DistroRid.
110     #
111     # __HostDistroRid was used in the case of a non-portable build, it has been
112     # deprecated. Now only __DistroRid is supported. It will be used for both
113     # portable and non-portable rids and will be used in build-packages.sh
114
115     local buildOs=$1
116     local buildArch=$2
117     local isPortable=$3
118     local rootfsDir=$4
119
120     # Setup whether this is a crossbuild. We can find this out if rootfsDir
121     # is set. 
122     local isCrossBuild=0
123
124     if [ -z "${rootfsDir}" ]; then
125         isCrossBuild=0
126     else
127         # We may have a cross build. Check for the existance of the rootfsDir
128         if [ -e ${rootfsDir} ]; then
129             isCrossBuild=1
130         else
131             echo "Error rootfsDir has been passed, but the location is not valid."
132             exit 1
133         fi
134     fi
135
136     initNonPortableDistroRid ${buildOs} ${buildArch} ${isPortable} ${rootfsDir}
137
138     if [ -z "${__DistroRid}" ]; then
139         # The non-portable build rid was not set. Set the portable rid.
140
141         export __PortableBuild=1
142         local distroRid=""
143
144         # Check for alpine. It is the only portable build that will will have
145         # its name in the portable build rid.
146         if [ -e "${rootfsDir}/etc/os-release" ]; then
147             source "${rootfsDir}/etc/os-release"
148             if [ "${ID}" = "alpine" ]; then
149                 distroRid="linux-musl-${buildArch}"
150             fi
151         fi
152
153         if [ "${distroRid}" == "" ]; then
154             if [ "$buildOs" = "Linux" ]; then
155                 distroRid="linux-$buildArch"
156             elif [ "$buildOs" = "OSX" ]; then
157                 distroRid="osx-$buildArch"
158             elif [ "$buildOs" = "FreeBSD" ]; then
159                 distroRid="freebsd-$buildArch"
160             fi
161         fi
162
163         export __DistroRid=${distroRid}
164     fi
165
166     if [ -z "$__DistroRid" ]; then
167         echo "DistroRid is not set. This is almost certainly an error"
168
169         exit 1
170     else
171         echo "__DistroRid: ${__DistroRid}"
172         echo "__RuntimeId: ${__DistroRid}"
173         
174         export __RuntimeId=${__DistroRid}
175     fi
176 }