[Tizen] Add CoreCLR tests build dependencies v3.1.3 for armel, arm64
[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                 if [ -z ${VERSION_ID+x} ]; then
60                         # Rolling release distros do not set VERSION_ID, so omit
61                         # it here to be consistent with everything else.
62                         nonPortableBuildID="${ID}-${buildArch}"
63                 else
64                         nonPortableBuildID="${ID}.${VERSION_ID}-${buildArch}"
65                 fi
66             fi
67             
68         elif [ -e "${rootfsDir}/etc/redhat-release" ]; then
69             local redhatRelease=$(<${rootfsDir}/etc/redhat-release)
70
71             if [[ "${redhatRelease}" == "CentOS release 6."* || "$redhatRelease" == "Red Hat Enterprise Linux Server release 6."* ]]; then
72                 nonPortableBuildID="rhel.6-${buildArch}"
73             fi
74         elif [ -e "${rootfsDir}/android_platform" ]; then
75             source $rootfsDir/android_platform
76             nonPortableBuildID="$RID"
77         fi
78     fi
79
80     if [ "$buildOs" = "FreeBSD" ]; then
81         __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
82         nonPortableBuildID="freebsd.$__freebsd_version-${buildArch}"
83     fi
84
85     if [ "${nonPortableBuildID}" != "" ]; then
86         export __DistroRid=${nonPortableBuildID}
87
88         # We are using a non-portable build rid. Force __PortableBuild to false.
89         export __PortableBuild=0
90     fi
91 }
92
93
94 # initDistroRidGlobal
95 #
96 # Input:
97 #   os: (str)
98 #   arch: (str)
99 #   isPortable: (int)
100 #   rootfsDir?: (nullable:string)
101 #
102 # Return:
103 #   None
104 #
105 # Notes:
106 #
107 # The following out parameters are returned
108 #
109 #   __DistroRid
110 #   __PortableBuild
111 #
112 initDistroRidGlobal()
113 {
114     # __DistroRid must be set at the end of the function.
115     # Previously we would create a variable __HostDistroRid and/or __DistroRid.
116     #
117     # __HostDistroRid was used in the case of a non-portable build, it has been
118     # deprecated. Now only __DistroRid is supported. It will be used for both
119     # portable and non-portable rids and will be used in build-packages.sh
120
121     local buildOs=$1
122     local buildArch=$2
123     local isPortable=$3
124     local rootfsDir=$4
125
126     # Setup whether this is a crossbuild. We can find this out if rootfsDir
127     # is set. 
128     local isCrossBuild=0
129
130     if [ -z "${rootfsDir}" ]; then
131         isCrossBuild=0
132     else
133         # We may have a cross build. Check for the existance of the rootfsDir
134         if [ -e ${rootfsDir} ]; then
135             isCrossBuild=1
136         else
137             echo "Error rootfsDir has been passed, but the location is not valid."
138             exit 1
139         fi
140     fi
141
142     if [ "$buildArch" = "armel" ]; then
143         # Armel cross build is Tizen specific and does not support Portable RID build
144         export __PortableBuild=0
145         isPortable=0
146     fi
147
148     initNonPortableDistroRid ${buildOs} ${buildArch} ${isPortable} ${rootfsDir}
149
150     if [ -z "${__DistroRid}" ]; then
151         # The non-portable build rid was not set. Set the portable rid.
152
153         export __PortableBuild=1
154         local distroRid=""
155
156         # Check for alpine. It is the only portable build that will will have
157         # its name in the portable build rid.
158         if [ -e "${rootfsDir}/etc/os-release" ]; then
159             source "${rootfsDir}/etc/os-release"
160             if [ "${ID}" = "alpine" ]; then
161                 distroRid="linux-musl-${buildArch}"
162             fi
163         fi
164
165         if [ "${distroRid}" == "" ]; then
166             if [ "$buildOs" = "Linux" ]; then
167                 distroRid="linux-$buildArch"
168             elif [ "$buildOs" = "OSX" ]; then
169                 distroRid="osx-$buildArch"
170             elif [ "$buildOs" = "FreeBSD" ]; then
171                 distroRid="freebsd-$buildArch"
172             fi
173         fi
174
175         export __DistroRid=${distroRid}
176     fi
177
178     if [ -z "$__DistroRid" ]; then
179         echo "DistroRid is not set. This is almost certainly an error"
180
181         exit 1
182     else
183         echo "__DistroRid: ${__DistroRid}"
184         echo "__RuntimeId: ${__DistroRid}"
185         
186         export __RuntimeId=${__DistroRid}
187     fi
188 }