[2019-12] Bump msbuild to track mono-2019-10 (#18413)
[mono-project.git] / netcore / build.sh
blobfe73413082f6a9f5664b37abbedcbb3e900fdcf7
1 #!/usr/bin/env bash
3 # Stop script if unbound variable found (use ${var:-} if intentional)
4 set -u
6 # Stop script if command returns non-zero exit code.
7 # Prevents hidden errors caused by missing error code propagation.
8 set -e
10 # Handle being in the "wrong" directory
11 cd "${BASH_SOURCE%/*}/"
13 # Include VSTS logging helpers
14 . ../eng/common/pipeline-logging-functions.sh
16 usage()
18 echo "Common settings:"
19 echo " --configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
20 echo " --help Print help and exit (short: -h)"
21 echo ""
23 echo "Actions:"
24 echo " --pack Package build outputs into NuGet packages"
25 echo " --test Run all unit tests in the solution (short: -t)"
26 echo " --rebuild Run ../.autogen.sh"
27 echo " --llvm Enable LLVM support"
28 echo " --skipnative Do not build runtime"
29 echo " --skipmscorlib Do not build System.Private.CoreLib"
30 echo " --ci Enable Azure DevOps telemetry decoration"
31 echo ""
33 echo "Command line arguments starting with '/p:' are passed through to MSBuild."
34 echo "Arguments can also be passed in with a single hyphen."
37 pack=false
38 configuration='Debug'
39 properties=''
40 force_rebuild=false
41 test=false
42 skipmscorlib=false
43 skipnative=false
44 llvm=false
45 autogen_params=''
46 ci=false
48 while [[ $# > 0 ]]; do
49 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
50 case "$opt" in
51 -help|-h)
52 usage
53 exit 0
55 -configuration|-c)
56 properties="$properties $1 $2"
57 configuration=$2
58 shift
60 -pack)
61 pack=true
63 -test|-t)
64 test=true
66 -rebuild)
67 force_rebuild=true
69 -skipmscorlib)
70 skipmscorlib=true
72 -skipnative)
73 skipnative=true
75 -llvm)
76 llvm=true
78 -ci)
79 ci=true
81 -p:*|/p:*)
82 properties="$properties $1"
84 -m:*|/m:*)
85 properties="$properties $1"
87 -bl:*|/bl:*)
88 properties="$properties $1"
90 -dl:*|/dl:*)
91 properties="$properties $1"
94 echo "Invalid argument: $1"
95 usage
96 exit 1
98 esac
100 shift
101 done
103 CPU_COUNT=$(getconf _NPROCESSORS_ONLN || echo 4)
105 if [[ "$configuration" == "Debug" ]]; then
106 EXTRA_CFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
107 EXTRA_CXXFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
108 elif [[ "$configuration" == "Release" ]]; then
109 EXTRA_CFLAGS="-O2 -g"
110 EXTRA_CXXFLAGS="-O2 -g"
113 if [ "$llvm" = "true" ]; then
114 git submodule update --init -- ../external/llvm-project || (Write-PipelineTelemetryError -c "git" -e 1 "Error fetching LLVM submodule" && exit 1)
115 autogen_params="$autogen_params --enable-llvm"
118 # run .././autogen.sh only once or if "--rebuild" argument is provided
119 if [[ "$force_rebuild" == "true" || ! -f .configured ]]; then
120 (cd .. && ./autogen.sh --with-core=only $autogen_params CFLAGS="$EXTRA_CFLAGS" CXXFLAGS="$EXTRA_CXXFLAGS") || (Write-PipelineTelemetryError -c "configure" -e 1 "Error running autogen" && exit 1)
121 touch .configured
124 # build mono runtime
125 if [ "$skipnative" = "false" ]; then
126 make runtime -j$CPU_COUNT || (Write-PipelineTelemetryError -c "runtime" -e 1 "Error building unmanaged runtime" && exit 1)
129 # build System.Private.CoreLib (../mcs/class/System.Private.CoreLib)
130 if [ "$skipmscorlib" = "false" ]; then
131 make bcl CORLIB_BUILD_FLAGS="$properties" || (Write-PipelineTelemetryError -c "bcl" -e 1 "Error building System.Private.CoreLib" && exit 1)
134 # create a nupkg with runtime and System.Private.CoreLib
135 if [ "$pack" = "true" ]; then
136 if [ "$llvm" = "true" ]; then
137 make nupkg-llvm || (Write-PipelineTelemetryError -c "nupkg" -e 1 "Error packing NuGet package" && exit 1)
138 else
139 make nupkg || (Write-PipelineTelemetryError -c "nupkg" -e 1 "Error packing NuGet package" && exit 1)
143 # run all xunit tests
144 if [ "$test" = "true" ]; then
145 make update-tests-corefx || (Write-PipelineTelemetryError -c "tests-download" -e 1 "Error downloading tests" && exit 1)
146 if [ "$ci" = "true" ]; then
147 make run-tests-corefx USE_TIMEOUT=1 || (Write-PipelineTelemetryError -c "tests" -e 1 "Error running tests" && exit 1)
148 else
149 make run-tests-corefx