Merge pull request #3484 from Dmitry-Me/fixBrokenCondition
[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     if [ ! -e /etc/os-release ]; then
107         echo "WARNING: Can not determine runtime id for current distro."
108         export __DistroRid=""
109     else
110         source /etc/os-release
111         export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
112     fi
113 fi
114
115 __IntermediatesDir="$__ProjectRoot/bin/obj/$__BuildOS.$__BuildArch.$__BuildType"
116
117 # Ensure that MSBuild is available
118 echo "Running init-tools.sh"
119 $__ProjectRoot/init-tools.sh
120
121     echo "Generating nuget packages for "$__BuildOS
122
123     # Invoke MSBuild
124     $__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
125
126 if [ $? -ne 0 ]; then
127     echo -e "\nAn error occurred. Aborting build-packages.sh ." >> $build_packages_log
128     echo "ERROR: An error occurred while building packages, see $build_packages_log for more details."
129     exit 1
130 fi
131
132     # Build the JIT packages
133     $__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
134
135 if [ $? -ne 0 ]; then
136     echo -e "\nAn error occurred. Aborting build-packages.sh ." >> $build_packages_log
137     echo "ERROR: An error occurred while building packages, see $build_packages_log for more details."
138     exit 1
139 fi
140
141     # Build the ILAsm package
142     $__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/src/.nuget/Microsoft.NETCore.ILAsm/Microsoft.NETCore.ILAsm.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
143
144 if [ $? -ne 0 ]; then
145     echo -e "\nAn error occurred. Aborting build-packages.sh ." >> $build_packages_log
146     echo "ERROR: An error occurred while building packages, see $build_packages_log for more details."
147     exit 1
148 fi
149
150     # Build the ILDAsm package
151     $__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/src/.nuget/Microsoft.NETCore.ILDAsm/Microsoft.NETCore.ILDAsm.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
152
153 if [ $? -ne 0 ]; then
154     echo -e "\nAn error occurred. Aborting build-packages.sh ." >> $build_packages_log
155     echo "ERROR: An error occurred while building packages, see $build_packages_log for more details."
156     exit 1
157 fi
158
159 echo "Done building packages."
160 echo -e "\nDone building packages." >> $build_packages_log
161 exit 0