dotnet-installer/eng/common/build.sh

214 lines
4.9 KiB
Bash
Raw Normal View History

2018-10-22 05:07:26 +00:00
#!/usr/bin/env bash
2018-12-19 20:55:42 +00:00
# Stop script if unbound variable found (use ${var:-} if intentional)
set -u
# Stop script if command returns non-zero exit code.
# Prevents hidden errors caused by missing error code propagation.
set -e
2018-12-19 20:55:42 +00:00
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."
}
2018-10-22 05:07:26 +00:00
source="${BASH_SOURCE[0]}"
# resolve $source until the file is no longer a symlink
while [[ -h "$source" ]]; do
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
source="$(readlink "$source")"
# if $source was a relative symlink, we need to resolve it relative to the path where the
# symlink file was located
[[ $source != /* ]] && source="$scriptroot/$source"
done
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
restore=false
build=false
rebuild=false
test=false
pack=false
publish=false
integration_test=false
performance_test=false
sign=false
public=false
ci=false
2018-12-19 20:55:42 +00:00
warn_as_error=true
node_reuse=true
binary_log=false
2018-10-22 05:07:26 +00:00
projects=''
configuration='Debug'
prepare_machine=false
verbosity='minimal'
properties=''
2018-12-19 20:55:42 +00:00
while [[ $# > 0 ]]; do
opt="$(echo "$1" | awk '{print tolower($0)}')"
case "$opt" in
--help|-h)
usage
2018-10-22 05:07:26 +00:00
exit 0
;;
2018-12-19 20:55:42 +00:00
--configuration|-c)
configuration=$2
shift
2018-10-22 05:07:26 +00:00
;;
2018-12-19 20:55:42 +00:00
--verbosity|-v)
verbosity=$2
shift
2018-10-22 05:07:26 +00:00
;;
2018-12-19 20:55:42 +00:00
--binarylog|-bl)
binary_log=true
2018-10-22 05:07:26 +00:00
;;
2018-12-19 20:55:42 +00:00
--restore|-r)
2018-10-22 05:07:26 +00:00
restore=true
;;
2018-12-19 20:55:42 +00:00
--build|-b)
build=true
2018-10-22 05:07:26 +00:00
;;
2018-12-19 20:55:42 +00:00
--rebuild)
rebuild=true
2018-10-22 05:07:26 +00:00
;;
2018-12-19 20:55:42 +00:00
--pack)
pack=true
2018-10-22 05:07:26 +00:00
;;
2018-12-19 20:55:42 +00:00
--test|-t)
2018-10-22 05:07:26 +00:00
test=true
;;
--integrationtest)
integration_test=true
;;
--performancetest)
performance_test=true
2018-12-19 20:55:42 +00:00
;;
--sign)
sign=true
2018-10-22 05:07:26 +00:00
;;
--publish)
publish=true
;;
2018-12-19 20:55:42 +00:00
--preparemachine)
prepare_machine=true
;;
--projects)
projects=$2
shift
;;
--ci)
ci=true
2018-10-22 05:07:26 +00:00
;;
--warnaserror)
2018-12-19 20:55:42 +00:00
warn_as_error=$2
shift
2018-10-22 05:07:26 +00:00
;;
--nodereuse)
2018-12-19 20:55:42 +00:00
node_reuse=$2
shift
2018-10-22 05:07:26 +00:00
;;
2018-12-19 20:55:42 +00:00
/p:*)
2018-10-22 05:07:26 +00:00
properties="$properties $1"
2018-12-19 20:55:42 +00:00
;;
/m:*)
properties="$properties $1"
;;
/bl:*)
properties="$properties $1"
;;
2018-12-19 20:55:42 +00:00
*)
echo "Invalid argument: $1"
usage
exit 1
2018-10-22 05:07:26 +00:00
;;
esac
2018-12-19 20:55:42 +00:00
shift
2018-10-22 05:07:26 +00:00
done
2018-12-19 20:55:42 +00:00
if [[ "$ci" == true ]]; then
binary_log=true
node_reuse=false
fi
2018-10-22 05:07:26 +00:00
. "$scriptroot/tools.sh"
2018-12-19 20:55:42 +00:00
function InitializeCustomToolset {
local script="$eng_root/restore-toolset.sh"
if [[ -a "$script" ]]; then
. "$script"
fi
}
function Build {
InitializeToolset
InitializeCustomToolset
if [[ ! -z "$projects" ]]; then
properties="$properties /p:Projects=$projects"
fi
local bl=""
if [[ "$binary_log" == true ]]; then
bl="/bl:\"$log_dir/Build.binlog\""
fi
MSBuild $_InitializeToolset \
$bl \
/p:Configuration=$configuration \
/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"
2018-10-22 05:07:26 +00:00
fi
2018-12-19 20:55:42 +00:00
# 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"
2018-10-22 05:07:26 +00:00
fi
2018-12-19 20:55:42 +00:00
Build