summaryrefslogtreecommitdiff
path: root/eng/common/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'eng/common/build.sh')
-rwxr-xr-xeng/common/build.sh235
1 files changed, 134 insertions, 101 deletions
diff --git a/eng/common/build.sh b/eng/common/build.sh
index 941db3bd57..03b4436e1b 100755
--- a/eng/common/build.sh
+++ b/eng/common/build.sh
@@ -1,5 +1,35 @@
#!/usr/bin/env bash
+# Stop script if unbound variable found (use ${var:-} if intentional)
+set -u
+
+usage()
+{
+ echo "Common settings:"
+ echo " --configuration <value> Build configuration: 'Debug' or 'Release' (short: --c)"
+ echo " --verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
+ echo " --binaryLog Create MSBuild binary log (short: -bl)"
+ echo ""
+ echo "Actions:"
+ echo " --restore Restore dependencies (short: -r)"
+ echo " --build Build all projects (short: -b)"
+ echo " --rebuild Rebuild all projects"
+ echo " --test Run all unit tests (short: -t)"
+ echo " --sign Sign build outputs"
+ echo " --publish Publish artifacts (e.g. symbols)"
+ echo " --pack Package build outputs into NuGet packages and Willow components"
+ echo " --help Print help and exit (short: -h)"
+ echo ""
+ echo "Advanced settings:"
+ echo " --projects <value> Project or solution file(s) to build"
+ echo " --ci Set when running on CI server"
+ echo " --prepareMachine Prepare machine for CI run, clean up processes after build"
+ echo " --nodeReuse <value> Sets nodereuse msbuild parameter ('true' or 'false')"
+ echo " --warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')"
+ echo ""
+ echo "Command line arguments starting with '/p:' are passed through to MSBuild."
+}
+
source="${BASH_SOURCE[0]}"
# resolve $source until the file is no longer a symlink
@@ -12,7 +42,6 @@ while [[ -h "$source" ]]; do
done
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
-help=false
restore=false
build=false
rebuild=false
@@ -25,8 +54,9 @@ sign=false
public=false
ci=false
-warnaserror=true
-nodereuse=true
+warn_as_error=true
+node_reuse=true
+binary_log=false
projects=''
configuration='Debug'
@@ -34,138 +64,141 @@ prepare_machine=false
verbosity='minimal'
properties=''
-while (($# > 0)); do
- lowerI="$(echo $1 | awk '{print tolower($0)}')"
- case $lowerI in
- --build)
- build=true
- shift 1
- ;;
- --ci)
- ci=true
- shift 1
- ;;
- --configuration)
- configuration=$2
- shift 2
- ;;
- --help)
- echo "Common settings:"
- echo " --configuration <value> Build configuration Debug, Release"
- echo " --verbosity <value> Msbuild verbosity (q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic])"
- echo " --help Print help and exit"
- echo ""
- echo "Actions:"
- echo " --restore Restore dependencies"
- echo " --build Build solution"
- echo " --rebuild Rebuild solution"
- echo " --test Run all unit tests in the solution"
- echo " --sign Sign build outputs"
- echo " --publish Publish artifacts (e.g. symbols)"
- echo " --pack Package build outputs into NuGet packages and Willow components"
- echo ""
- echo "Advanced settings:"
- echo " --solution <value> Path to solution to build"
- echo " --ci Set when running on CI server"
- echo " --prepareMachine Prepare machine for CI run"
- echo ""
- echo "Command line arguments not listed above are passed through to MSBuild."
+while [[ $# > 0 ]]; do
+ opt="$(echo "$1" | awk '{print tolower($0)}')"
+ case "$opt" in
+ --help|-h)
+ usage
exit 0
;;
- --pack)
- pack=true
- shift 1
+ --configuration|-c)
+ configuration=$2
+ shift
;;
- --preparemachine)
- prepare_machine=true
- shift 1
+ --verbosity|-v)
+ verbosity=$2
+ shift
;;
- --rebuild)
- rebuild=true
- shift 1
+ --binarylog|-bl)
+ binary_log=true
;;
- --restore)
+ --restore|-r)
restore=true
- shift 1
;;
- --sign)
- sign=true
- shift 1
+ --build|-b)
+ build=true
;;
- --solution)
- solution=$2
- shift 2
+ --rebuild)
+ rebuild=true
;;
- --projects)
- projects=$2
- shift 2
+ --pack)
+ pack=true
;;
- --test)
+ --test|-t)
test=true
- shift 1
;;
--integrationtest)
integration_test=true
- shift 1
;;
--performancetest)
performance_test=true
- shift 1
+ ;;
+ --sign)
+ sign=true
;;
--publish)
publish=true
- shift 1
;;
- --verbosity)
- verbosity=$2
- shift 2
+ --preparemachine)
+ prepare_machine=true
+ ;;
+ --projects)
+ projects=$2
+ shift
+ ;;
+ --ci)
+ ci=true
;;
--warnaserror)
- warnaserror=$2
- shift 2
+ warn_as_error=$2
+ shift
;;
--nodereuse)
- nodereuse=$2
- shift 2
+ node_reuse=$2
+ shift
;;
- *)
+ /p:*)
properties="$properties $1"
- shift 1
+ ;;
+ *)
+ echo "Invalid argument: $1"
+ usage
+ exit 1
;;
esac
+
+ shift
done
+if [[ "$ci" == true ]]; then
+ binary_log=true
+ node_reuse=false
+fi
+
. "$scriptroot/tools.sh"
-if [[ -z $projects ]]; then
- projects="$repo_root/*.sln"
+function InitializeCustomToolset {
+ local script="$eng_root/restore-toolset.sh"
+
+ if [[ -a "$script" ]]; then
+ . "$script"
+ fi
+}
+
+function Build {
+ InitializeToolset
+ InitializeCustomToolset
+
+ if [[ -z $projects ]]; then
+ projects="$repo_root/*.sln"
+ fi
+
+ local bl=""
+ if [[ "$binary_log" == true ]]; then
+ bl="/bl:\"$log_dir/Build.binlog\""
+ fi
+
+ MSBuild $_InitializeToolset \
+ $bl \
+ /p:Configuration=$configuration \
+ /p:Projects="$projects" \
+ /p:RepoRoot="$repo_root" \
+ /p:Restore=$restore \
+ /p:Build=$build \
+ /p:Rebuild=$rebuild \
+ /p:Test=$test \
+ /p:Pack=$pack \
+ /p:IntegrationTest=$integration_test \
+ /p:PerformanceTest=$performance_test \
+ /p:Sign=$sign \
+ /p:Publish=$publish \
+ /p:ContinuousIntegrationBuild=$ci \
+ $properties
+
+ ExitWithExitCode 0
+}
+
+# Import custom tools configuration, if present in the repo.
+configure_toolset_script="$eng_root/configure-toolset.sh"
+if [[ -a "$configure_toolset_script" ]]; then
+ . "$configure_toolset_script"
fi
-InitializeTools
-
-build_log="$log_dir/Build.binlog"
-
-MSBuild "$toolset_build_proj" \
- /bl:"$build_log" \
- /p:Configuration=$configuration \
- /p:Projects="$projects" \
- /p:RepoRoot="$repo_root" \
- /p:Restore=$restore \
- /p:Build=$build \
- /p:Rebuild=$rebuild \
- /p:Test=$test \
- /p:Pack=$pack \
- /p:IntegrationTest=$integration_test \
- /p:PerformanceTest=$performance_test \
- /p:Sign=$sign \
- /p:Publish=$publish \
- /p:ContinuousIntegrationBuild=$ci \
- $properties
-
-lastexitcode=$?
-
-if [[ $lastexitcode != 0 ]]; then
- echo "Build failed (exit code '$lastexitcode'). See log: $build_log"
+# TODO: https://github.com/dotnet/arcade/issues/1468
+# Temporary workaround to avoid breaking change.
+# Remove once repos are updated.
+if [[ -n "${useInstalledDotNetCli:-}" ]]; then
+ use_installed_dotnet_cli="$useInstalledDotNetCli"
fi
-ExitWithExitCode $lastexitcode
+Build