Merge pull request #5032 from kspawa/r2rngen
[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 [arch] [configuration]"
7     echo "arch can be x64, x86, arm, arm64 (default is x64)"
8     echo "configuration can be release, checked, debug (default is debug)"
9     echo
10     exit 1
11 }
12
13 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14 build_packages_log=$__ProjectRoot/build-packages.log
15 binclashlog=$__ProjectRoot/binclash.log
16 binclashloggerdll=$__ProjectRoot/Tools/Microsoft.DotNet.Build.Tasks.dll
17 RuntimeOS=ubuntu.$VERSION_ID
18
19 __MSBuildPath=$__ProjectRoot/Tools/MSBuild.exe
20
21 # Parse arguments
22 __BuildArch=x64
23 __BuildType=Debug
24
25 allargs="$@"
26
27 echo -e "Running build-packages.sh $allargs" > $build_packages_log
28
29 if [ "$allargs" == "-h" ] || [ "$allargs" == "--help" ]; then
30     usage
31 fi
32
33 while :; do
34     if [ $# -le 0 ]; then
35         break
36     fi
37
38     lowerI="$(echo $1 | awk '{print tolower($0)}')"
39     case $lowerI in
40         -\?|-h|--help)
41             usage
42             exit 1
43             ;;
44
45         x86)
46             __BuildArch=x86
47             ;;
48
49         x64)
50             __BuildArch=x64
51             ;;
52
53         arm)
54             __BuildArch=arm
55             ;;
56
57         arm64)
58             __BuildArch=arm64
59             ;;
60         debug)
61             __BuildType=Debug
62             ;;
63         release)
64             __BuildType=Release
65             ;;
66         checked)
67             __BuildType=Checked
68     esac
69     shift
70 done
71
72 # Use uname to determine what the OS is.
73 OSName=$(uname -s)
74 case $OSName in
75     Linux)
76         __BuildOS=Linux
77         ;;
78
79     Darwin)
80         __BuildOS=OSX
81         ;;
82
83     FreeBSD)
84         __BuildOS=FreeBSD
85         ;;
86
87     OpenBSD)
88         __BuildOS=OpenBSD
89         ;;
90
91     NetBSD)
92         __BuildOS=NetBSD
93         ;;
94
95     SunOS)
96         __BuildOS=SunOS
97         ;;
98
99     *)
100         echo "Unsupported OS $OSName detected, configuring as if for Linux"
101         __BuildOS=Linux
102         ;;
103 esac
104
105 if [ "$__BuildOS" == "Linux" ]; then
106         # Detect Distro
107         if [ "$(cat /etc/*-release | grep -cim1 ubuntu)" -eq 1 ]; then
108             export __DistroName=ubuntu
109         elif [ "$(cat /etc/*-release | grep -cim1 centos)" -eq 1 ]; then
110             export __DistroName=rhel
111         elif [ "$(cat /etc/*-release | grep -cim1 rhel)" -eq 1 ]; then
112             export __DistroName=rhel
113         elif [ "$(cat /etc/*-release | grep -cim1 debian)" -eq 1 ]; then
114             export __DistroName=debian
115         else
116             export __DistroName=""
117         fi
118 fi
119
120 __IntermediatesDir="$__ProjectRoot/bin/obj/$__BuildOS.$__BuildArch.$__BuildType"
121
122 # Ensure that MSBuild is available
123 echo "Running init-tools.sh"
124 $__ProjectRoot/init-tools.sh
125
126     echo "Generating nuget packages for "$__BuildOS
127
128     # Invoke MSBuild
129     $__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/src/.nuget/Microsoft.NETCore.Runtime.CoreCLR/Microsoft.NETCore.Runtime.CoreCLR.builds" /verbosity:minimal "/fileloggerparameters:Verbosity=normal;LogFile=$binclashlog" /t:Build /p:__BuildOS=$__BuildOS /p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__IntermediatesDir=$__IntermediatesDir /p:BuildNugetPackage=false /p:UseSharedCompilation=false
130
131 if [ $? -ne 0 ]; then
132     echo -e "\nAn error occurred. Aborting build-packages.sh ." >> $build_packages_log
133     echo "ERROR: An error occurred while building packages, see $build_packages_log for more details."
134     exit 1
135 fi
136
137     # Build the JIT packages
138     $__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/src/.nuget/Microsoft.NETCore.Jit/Microsoft.NETCore.Jit.builds" /verbosity:minimal "/fileloggerparameters:Verbosity=normal;LogFile=$binclashlog" /t:Build /p:__BuildOS=$__BuildOS /p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__IntermediatesDir=$__IntermediatesDir /p:BuildNugetPackage=false /p:UseSharedCompilation=false
139
140 if [ $? -ne 0 ]; then
141     echo -e "\nAn error occurred. Aborting build-packages.sh ." >> $build_packages_log
142     echo "ERROR: An error occurred while building packages, see $build_packages_log for more details."
143     exit 1
144 fi
145
146 echo "Done building packages."
147 echo -e "\nDone building packages." >> $build_packages_log
148 exit 0