|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Stop script if unbound variable found (use ${var:-} if intentional) |
| 4 | +set -u |
| 5 | + |
| 6 | +# Stop script if command returns non-zero exit code. |
| 7 | +# Prevents hidden errors caused by missing error code propagation. |
| 8 | +set -e |
| 9 | + |
| 10 | +usage() |
| 11 | +{ |
| 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 "" |
| 18 | + |
| 19 | + echo "Actions:" |
| 20 | + echo " --restore Restore dependencies (short: -r)" |
| 21 | + echo " --build Build solution (short: -b)" |
| 22 | + echo " --sourceBuild Source-build the solution (short: -sb)" |
| 23 | + echo " Will additionally trigger the following actions: --restore, --build, --pack" |
| 24 | + echo " If --configuration is not set explicitly, will also set it to 'Release'" |
| 25 | + echo " --productBuild Build the solution in the way it will be built in the full .NET product (VMR) build (short: -pb)" |
| 26 | + echo " Will additionally trigger the following actions: --restore, --build, --pack" |
| 27 | + echo " If --configuration is not set explicitly, will also set it to 'Release'" |
| 28 | + echo " --rebuild Rebuild solution" |
| 29 | + echo " --test Run all unit tests in the solution (short: -t)" |
| 30 | + echo " --integrationTest Run all integration tests in the solution" |
| 31 | + echo " --performanceTest Run all performance tests in the solution" |
| 32 | + echo " --pack Package build outputs into NuGet packages and Willow components" |
| 33 | + echo " --sign Sign build outputs" |
| 34 | + echo " --publish Publish artifacts (e.g. symbols)" |
| 35 | + echo " --clean Clean the solution" |
| 36 | + echo "" |
| 37 | + |
| 38 | + echo "Advanced settings:" |
| 39 | + echo " --projects <value> Project or solution file(s) to build" |
| 40 | + echo " --ci Set when running on CI server" |
| 41 | + echo " --excludeCIBinarylog Don't output binary log (short: -nobl)" |
| 42 | + echo " --prepareMachine Prepare machine for CI run, clean up processes after build" |
| 43 | + echo " --nodeReuse <value> Sets nodereuse msbuild parameter ('true' or 'false')" |
| 44 | + echo " --warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')" |
| 45 | + echo " --buildCheck <value> Sets /check msbuild parameter" |
| 46 | + echo "" |
| 47 | + echo "Command line arguments not listed above are passed thru to msbuild." |
| 48 | + echo "Arguments can also be passed in with a single hyphen." |
| 49 | +} |
| 50 | + |
| 51 | +source="${BASH_SOURCE[0]}" |
| 52 | + |
| 53 | +# resolve $source until the file is no longer a symlink |
| 54 | +while [[ -h "$source" ]]; do |
| 55 | + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" |
| 56 | + source="$(readlink "$source")" |
| 57 | + # if $source was a relative symlink, we need to resolve it relative to the path where the |
| 58 | + # symlink file was located |
| 59 | + [[ $source != /* ]] && source="$scriptroot/$source" |
| 60 | +done |
| 61 | +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" |
| 62 | + |
| 63 | +restore=false |
| 64 | +build=false |
| 65 | +source_build=false |
| 66 | +product_build=false |
| 67 | +rebuild=false |
| 68 | +test=false |
| 69 | +integration_test=false |
| 70 | +performance_test=false |
| 71 | +pack=false |
| 72 | +publish=false |
| 73 | +sign=false |
| 74 | +public=false |
| 75 | +ci=false |
| 76 | +clean=false |
| 77 | + |
| 78 | +warn_as_error=true |
| 79 | +node_reuse=true |
| 80 | +build_check=false |
| 81 | +binary_log=false |
| 82 | +exclude_ci_binary_log=false |
| 83 | +pipelines_log=false |
| 84 | + |
| 85 | +projects='' |
| 86 | +configuration='' |
| 87 | +prepare_machine=false |
| 88 | +verbosity='minimal' |
| 89 | +runtime_source_feed='' |
| 90 | +runtime_source_feed_key='' |
| 91 | + |
| 92 | +properties='' |
| 93 | +while [[ $# > 0 ]]; do |
| 94 | + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" |
| 95 | + case "$opt" in |
| 96 | + -help|-h) |
| 97 | + usage |
| 98 | + exit 0 |
| 99 | + ;; |
| 100 | + -clean) |
| 101 | + clean=true |
| 102 | + ;; |
| 103 | + -configuration|-c) |
| 104 | + configuration=$2 |
| 105 | + shift |
| 106 | + ;; |
| 107 | + -verbosity|-v) |
| 108 | + verbosity=$2 |
| 109 | + shift |
| 110 | + ;; |
| 111 | + -binarylog|-bl) |
| 112 | + binary_log=true |
| 113 | + ;; |
| 114 | + -excludecibinarylog|-nobl) |
| 115 | + exclude_ci_binary_log=true |
| 116 | + ;; |
| 117 | + -pipelineslog|-pl) |
| 118 | + pipelines_log=true |
| 119 | + ;; |
| 120 | + -restore|-r) |
| 121 | + restore=true |
| 122 | + ;; |
| 123 | + -build|-b) |
| 124 | + build=true |
| 125 | + ;; |
| 126 | + -rebuild) |
| 127 | + rebuild=true |
| 128 | + ;; |
| 129 | + -pack) |
| 130 | + pack=true |
| 131 | + ;; |
| 132 | + -sourcebuild|-sb) |
| 133 | + build=true |
| 134 | + source_build=true |
| 135 | + product_build=true |
| 136 | + restore=true |
| 137 | + pack=true |
| 138 | + ;; |
| 139 | + -productbuild|-pb) |
| 140 | + build=true |
| 141 | + product_build=true |
| 142 | + restore=true |
| 143 | + pack=true |
| 144 | + ;; |
| 145 | + -test|-t) |
| 146 | + test=true |
| 147 | + ;; |
| 148 | + -integrationtest) |
| 149 | + integration_test=true |
| 150 | + ;; |
| 151 | + -performancetest) |
| 152 | + performance_test=true |
| 153 | + ;; |
| 154 | + -sign) |
| 155 | + sign=true |
| 156 | + ;; |
| 157 | + -publish) |
| 158 | + publish=true |
| 159 | + ;; |
| 160 | + -preparemachine) |
| 161 | + prepare_machine=true |
| 162 | + ;; |
| 163 | + -projects) |
| 164 | + projects=$2 |
| 165 | + shift |
| 166 | + ;; |
| 167 | + -ci) |
| 168 | + ci=true |
| 169 | + ;; |
| 170 | + -warnaserror) |
| 171 | + warn_as_error=$2 |
| 172 | + shift |
| 173 | + ;; |
| 174 | + -nodereuse) |
| 175 | + node_reuse=$2 |
| 176 | + shift |
| 177 | + ;; |
| 178 | + -buildcheck) |
| 179 | + build_check=true |
| 180 | + ;; |
| 181 | + -runtimesourcefeed) |
| 182 | + runtime_source_feed=$2 |
| 183 | + shift |
| 184 | + ;; |
| 185 | + -runtimesourcefeedkey) |
| 186 | + runtime_source_feed_key=$2 |
| 187 | + shift |
| 188 | + ;; |
| 189 | + *) |
| 190 | + properties="$properties $1" |
| 191 | + ;; |
| 192 | + esac |
| 193 | + |
| 194 | + shift |
| 195 | +done |
| 196 | + |
| 197 | +if [[ -z "$configuration" ]]; then |
| 198 | + if [[ "$source_build" = true ]]; then configuration="Release"; else configuration="Debug"; fi |
| 199 | +fi |
| 200 | + |
| 201 | +if [[ "$ci" == true ]]; then |
| 202 | + pipelines_log=true |
| 203 | + node_reuse=false |
| 204 | + if [[ "$exclude_ci_binary_log" == false ]]; then |
| 205 | + binary_log=true |
| 206 | + fi |
| 207 | +fi |
| 208 | + |
| 209 | +. "$scriptroot/tools.sh" |
| 210 | + |
| 211 | +function InitializeCustomToolset { |
| 212 | + local script="$eng_root/restore-toolset.sh" |
| 213 | + |
| 214 | + if [[ -a "$script" ]]; then |
| 215 | + . "$script" |
| 216 | + fi |
| 217 | +} |
| 218 | + |
| 219 | +function Build { |
| 220 | + InitializeToolset |
| 221 | + InitializeCustomToolset |
| 222 | + |
| 223 | + if [[ ! -z "$projects" ]]; then |
| 224 | + properties="$properties /p:Projects=$projects" |
| 225 | + fi |
| 226 | + |
| 227 | + local bl="" |
| 228 | + if [[ "$binary_log" == true ]]; then |
| 229 | + bl="/bl:\"$log_dir/Build.binlog\"" |
| 230 | + fi |
| 231 | + |
| 232 | + local check="" |
| 233 | + if [[ "$build_check" == true ]]; then |
| 234 | + check="/check" |
| 235 | + fi |
| 236 | + |
| 237 | + MSBuild $_InitializeToolset \ |
| 238 | + $bl \ |
| 239 | + $check \ |
| 240 | + /p:Configuration=$configuration \ |
| 241 | + /p:RepoRoot="$repo_root" \ |
| 242 | + /p:Restore=$restore \ |
| 243 | + /p:Build=$build \ |
| 244 | + /p:DotNetBuildRepo=$product_build \ |
| 245 | + /p:DotNetBuildSourceOnly=$source_build \ |
| 246 | + /p:Rebuild=$rebuild \ |
| 247 | + /p:Test=$test \ |
| 248 | + /p:Pack=$pack \ |
| 249 | + /p:IntegrationTest=$integration_test \ |
| 250 | + /p:PerformanceTest=$performance_test \ |
| 251 | + /p:Sign=$sign \ |
| 252 | + /p:Publish=$publish \ |
| 253 | + /p:RestoreStaticGraphEnableBinaryLogger=$binary_log \ |
| 254 | + $properties |
| 255 | + |
| 256 | + ExitWithExitCode 0 |
| 257 | +} |
| 258 | + |
| 259 | +if [[ "$clean" == true ]]; then |
| 260 | + if [ -d "$artifacts_dir" ]; then |
| 261 | + rm -rf $artifacts_dir |
| 262 | + echo "Artifacts directory deleted." |
| 263 | + fi |
| 264 | + exit 0 |
| 265 | +fi |
| 266 | + |
| 267 | +if [[ "$restore" == true ]]; then |
| 268 | + InitializeNativeTools |
| 269 | +fi |
| 270 | + |
| 271 | +Build |
0 commit comments