[2020-02] Bump msbuild to track mono-2019-12 (#19661)
[mono-project.git] / eng / common / build.sh
blob36f9aa0462ee17e604a194b39b8fd9ed2dde52a8
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 usage()
12 echo "Common settings:"
13 echo " --configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
14 echo " --verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
15 echo " --binaryLog Create MSBuild binary log (short: -bl)"
16 echo " --help Print help and exit (short: -h)"
17 echo ""
19 echo "Actions:"
20 echo " --restore Restore dependencies (short: -r)"
21 echo " --build Build solution (short: -b)"
22 echo " --rebuild Rebuild solution"
23 echo " --test Run all unit tests in the solution (short: -t)"
24 echo " --integrationTest Run all integration tests in the solution"
25 echo " --performanceTest Run all performance tests in the solution"
26 echo " --pack Package build outputs into NuGet packages and Willow components"
27 echo " --sign Sign build outputs"
28 echo " --publish Publish artifacts (e.g. symbols)"
29 echo " --clean Clean the solution"
30 echo ""
32 echo "Advanced settings:"
33 echo " --projects <value> Project or solution file(s) to build"
34 echo " --ci Set when running on CI server"
35 echo " --prepareMachine Prepare machine for CI run, clean up processes after build"
36 echo " --nodeReuse <value> Sets nodereuse msbuild parameter ('true' or 'false')"
37 echo " --warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')"
38 echo ""
39 echo "Command line arguments not listed above are passed thru to msbuild."
40 echo "Arguments can also be passed in with a single hyphen."
43 source="${BASH_SOURCE[0]}"
45 # resolve $source until the file is no longer a symlink
46 while [[ -h "$source" ]]; do
47 scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
48 source="$(readlink "$source")"
49 # if $source was a relative symlink, we need to resolve it relative to the path where the
50 # symlink file was located
51 [[ $source != /* ]] && source="$scriptroot/$source"
52 done
53 scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
55 restore=false
56 build=false
57 rebuild=false
58 test=false
59 integration_test=false
60 performance_test=false
61 pack=false
62 publish=false
63 sign=false
64 public=false
65 ci=false
66 clean=false
68 warn_as_error=true
69 node_reuse=true
70 binary_log=false
71 pipelines_log=false
73 projects=''
74 configuration='Debug'
75 prepare_machine=false
76 verbosity='minimal'
78 properties=''
80 while [[ $# > 0 ]]; do
81 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
82 case "$opt" in
83 -help|-h)
84 usage
85 exit 0
87 -clean)
88 clean=true
90 -configuration|-c)
91 configuration=$2
92 shift
94 -verbosity|-v)
95 verbosity=$2
96 shift
98 -binarylog|-bl)
99 binary_log=true
101 -pipelineslog|-pl)
102 pipelines_log=true
104 -restore|-r)
105 restore=true
107 -build|-b)
108 build=true
110 -rebuild)
111 rebuild=true
113 -pack)
114 pack=true
116 -test|-t)
117 test=true
119 -integrationtest)
120 integration_test=true
122 -performancetest)
123 performance_test=true
125 -sign)
126 sign=true
128 -publish)
129 publish=true
131 -preparemachine)
132 prepare_machine=true
134 -projects)
135 projects=$2
136 shift
138 -ci)
139 ci=true
141 -warnaserror)
142 warn_as_error=$2
143 shift
145 -nodereuse)
146 node_reuse=$2
147 shift
150 properties="$properties $1"
152 esac
154 shift
155 done
157 if [[ "$ci" == true ]]; then
158 pipelines_log=true
159 binary_log=true
160 node_reuse=false
163 . "$scriptroot/tools.sh"
165 function InitializeCustomToolset {
166 local script="$eng_root/restore-toolset.sh"
168 if [[ -a "$script" ]]; then
169 . "$script"
173 function Build {
174 InitializeToolset
175 InitializeCustomToolset
177 if [[ ! -z "$projects" ]]; then
178 properties="$properties /p:Projects=$projects"
181 local bl=""
182 if [[ "$binary_log" == true ]]; then
183 bl="/bl:\"$log_dir/Build.binlog\""
186 MSBuild $_InitializeToolset \
187 $bl \
188 /p:Configuration=$configuration \
189 /p:RepoRoot="$repo_root" \
190 /p:Restore=$restore \
191 /p:Build=$build \
192 /p:Rebuild=$rebuild \
193 /p:Test=$test \
194 /p:Pack=$pack \
195 /p:IntegrationTest=$integration_test \
196 /p:PerformanceTest=$performance_test \
197 /p:Sign=$sign \
198 /p:Publish=$publish \
199 $properties
201 ExitWithExitCode 0
204 if [[ "$clean" == true ]]; then
205 if [ -d "$artifacts_dir" ]; then
206 rm -rf $artifacts_dir
207 echo "Artifacts directory deleted."
209 exit 0
212 if [[ "$restore" == true ]]; then
213 InitializeNativeTools
216 Build