BuildXL/bxl.sh

228 строки
6.3 KiB
Bash
Исходник Обычный вид История

#!/bin/bash
set -e
MY_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
source "$MY_DIR/Public/Src/Sandbox/MacOs/scripts/env.sh"
declare arg_Positional=()
declare arg_DeployDev=""
declare arg_DeployDevRelease=""
declare arg_UseDev=""
declare arg_Minimal=""
declare arg_Internal=""
declare arg_Cgmanifest=""
if [[ "${OSTYPE}" == "linux-gnu" ]]; then
readonly HostQualifier=Linux
readonly DeploymentFolder=linux-x64
elif [[ "${OSTYPE}" == "darwin"* ]]; then
readonly HostQualifier=DotNetCoreMac
readonly DeploymentFolder=osx-x64
else
print_error "Operating system not supported: ${OSTYPE}"
exit 1
fi
function callNuget() {
if [[ "${OSTYPE}" == "linux-gnu" ]]; then
nuget "$@"
elif [[ "${OSTYPE}" == "darwin"* ]]; then
$MONO_HOME/mono Shared/Tools/NuGet.exe "$@"
else
print_error "Operating system not supported: ${OSTYPE}"
return 1
fi
}
function findMono() {
local monoLocation=$(which mono)
if [[ -z $monoLocation ]]; then
print_error "Did not find Mono. Please ensure mono is installed per: https://www.mono-project.com/docs/getting-started/install/ and is accessable in your PATH"
return 1
else
export MONO_HOME="$(dirname "$monoLocation")"
fi
}
function getLkg() {
local LKG_FILE="BuildXLLkgVersionPublic.cmd"
if [[ -n "$arg_Internal" ]]; then
local LKG_FILE="BuildXLLkgVersion.cmd"
fi
local BUILDXL_LKG_VERSION=$(grep "BUILDXL_LKG_VERSION" "$MY_DIR/Shared/Scripts/$LKG_FILE" | cut -d= -f2 | tr -d '\r')
local BUILDXL_LKG_NAME=$(grep "BUILDXL_LKG_NAME" "$MY_DIR/Shared/Scripts/$LKG_FILE" | cut -d= -f2 | perl -pe 's/(net472|win-x64)/'${DeploymentFolder}'/g' | tr -d '\r')
local BUILDXL_LKG_FEED_1=$(grep "BUILDXL_LKG_FEED_1" "$MY_DIR/Shared/Scripts/$LKG_FILE" | cut -d= -f2 | tr -d '\r')
print_info "Nuget Feed: $BUILDXL_LKG_FEED_1"
print_info "Getting package: $BUILDXL_LKG_NAME.$BUILDXL_LKG_VERSION"
local _BUILDXL_BOOTSTRAP_OUT="$MY_DIR/Out/BootStrap"
callNuget install -OutputDirectory "$_BUILDXL_BOOTSTRAP_OUT" -Source $BUILDXL_LKG_FEED_1 $BUILDXL_LKG_NAME -Version $BUILDXL_LKG_VERSION
export BUILDXL_BIN="$_BUILDXL_BOOTSTRAP_OUT/$BUILDXL_LKG_NAME.$BUILDXL_LKG_VERSION"
}
function setMinimal() {
arg_Positional+=(/q:Debug${HostQualifier} "/f:output='$MY_DIR/Out/bin/debug/${DeploymentFolder}/*'")
}
function setInternal() {
arg_Positional+=("/p:[Sdk.BuildXL]microsoftInternal=1")
arg_Positional+=("/remoteTelemetry+")
for arg in "$@"
do
to_lower=`printf '%s\n' "$arg" | awk '{ print tolower($0) }'`
if [[ " $to_lower " == *"endpointsecurity"* ]]; then
return
fi
done
}
function compileWithBxl() {
local args=(
--config "$MY_DIR/config.dsc"
/fancyConsoleMaxStatusPips:10
/exp:LazySODeletion
/nowarn:11319 # DX11319: nuget version mismatch
"$@"
)
if [[ -z "${VSTS_BUILDXL_BIN}" ]]; then
"$BUILDXL_BIN/bxl.sh" "${args[@]}"
else
# Currently only used on VSTS CI to allow for custom BuildXL binary execution
"$VSTS_BUILDXL_BIN/bxl.sh" "${args[@]}"
fi
}
function printHelp() {
echo "${BASH_SOURCE[0]} [--deploy-dev[-release]] [--use-dev] [--minimal] [--internal] [--shared-comp] [--cgmanifest] [--vs] [--test-method <full-test-method-name>] [--test-class <full-test-class-name>] <other-arguments>"
}
function parseArgs() {
arg_Positional=()
while [[ $# -gt 0 ]]; do
cmd="$1"
case $cmd in
--help | -h)
printHelp
shift
return 1
;;
--deploy-dev)
arg_DeployDev="1"
shift
;;
--deploy-dev-release)
arg_DeployDevRelease="1"
shift
;;
--use-dev)
arg_UseDev="1"
shift
;;
--minimal)
arg_Minimal="1"
shift
;;
--internal)
arg_Internal="1"
shift
;;
--cgmanifest)
arg_Cgmanifest="1"
shift
;;
[Mac Selfhost] run tests together with the main build As of now, to run tests on Mac one must sequentially do the following: 1. run a BuildXL build that only compiles all test assemblies and creates a *standalone* test deployment 1. run another BuildXL build from the previously created standalone test deployment that actually executes the tests Some drawbacks of this approach: 1. have to run 2 steps in sequence 1. tests that are executed on Mac must be explicitly opted-in (see [tests.osx.dsc](https://dev.azure.com/mseng/Domino/_git/BuildXL.Internal?path=%2FPublic%2FSrc%2FDeployment%2FTests.Osx%2Ftests.osx.dsc&version=GBmaster&line=15&lineEnd=15&lineStartColumn=14&lineEndColumn=27&lineStyle=plain)) - this makes it easy to forget to opt in any newly added test assemblies 1. impossible to execute just a single test class or test method at once 1. some SDKs (e.g., `xunit.dsc`) are duplicated between the main build and the build used for executing standalone test deployments. The main reason for this setup was the fact that the main build and the unit tests themselves might require different versions of the MacSandbox kext to be loaded. This PR makes it possible to compile and execute tests in a single build, matching the experience on Windows. For example, running ```bash ./bxl.sh --internal ``` on a Mac will execute the full selfhost build, including executing all the tests. Individual tests can still opt out of Mac (by using the existing mechanisms like `[(Class|Theory|Fact)IfSupported[requiresWindowsBasedOperatingSystem: true]`). We already have different IDs for the release and debug configurations of the MacSandbox kext, which means we can already have different versions of the kext loaded as long as one is a 'release' and the other is 'debug'. That makes it sufficient for the most common scenario of using a 'release' version of BuildXL to run a build in which tests are executed in 'debug' configuration. It is also possible to execute both 'release' and 'debug' tests in a single build, but for that, a dev version of BuildXL must be built first and then used for subsequent test execution. **Important Note**: the user is still responsible for ensuring that the necessary kexts are loaded (this needs to be done only when the kext changes; once loaded, the kexts don't need to be touched/reloaded between builds/test executions). To load the debug version of the kext: ```bash ./bxl.sh --minimal # produces out/bin/debug/osx-x64/* out/bin/debug/osx-x64/bxl.sh --load-kext ``` Main changes: - annotate Windows-only tests as such (so that they are skipped over when running on Mac) - fix various small platform-dependent issues (like using an appropriate directory separator char) - fix DScript SDK tests - add `--test-method` and `--test-class` switches to `bxl.sh` to correspond to `-TestMethod` and `-TestClass` in `bxl.ps1` Once this change is merged, I'll update the PR validation pipelines and remove the code for producing the standalone test deployment. Merged PR 526181
2019-12-27 18:52:12 +03:00
--test-class)
arg_Positional+=("/p:[UnitTest]Filter.testClass=$2")
shift
shift
;;
--test-method)
arg_Positional+=("/p:[UnitTest]Filter.testMethod=$2")
shift
shift
;;
--shared-comp)
arg_Positional+=("/p:[Sdk.BuildXL]useManagedSharedCompilation=1")
shift
;;
--vs)
arg_Positional+=(
"/vs"
"/vsTargetFramework:netcoreapp3.0"
"/vsTargetFramework:netcoreapp3.1"
"/vsTargetFramework:netstandard2.0"
"/vsTargetFramework:netstandard2.1")
shift
;;
*)
arg_Positional+=("$1")
shift
;;
esac
done
}
function deployBxl { # (fromDir, toDir)
local fromDir="$1"
local toDir="$2"
mkdir -p "$toDir"
/usr/bin/rsync -arhq "$fromDir/" "$toDir" --delete
print_info "Successfully deployed developer build from $fromDir to: $toDir; use it with the '--use-dev' flag now."
}
# allow this script to be sourced, in which case we shouldn't execute anything
if [[ "$0" != "${BASH_SOURCE[0]}" ]]; then
return 0
fi
# Make sure we are running in our own working directory
pushd "$MY_DIR"
parseArgs "$@"
findMono
if [[ -n "$arg_DeployDev" || -n "$arg_Minimal" ]]; then
setMinimal
fi
if [[ -n "$arg_DeployDevRelease" ]]; then
arg_Positional+=(/q:Release${HostQualifier} "/f:output='$MY_DIR/Out/bin/release/${DeploymentFolder}/*'")
fi
if [[ -n "$arg_Internal" ]]; then
setInternal $@
fi
if [[ -n "$arg_Cgmanifest" ]]; then
arg_Positional+=(/generateCgManifestForNugets:"${MY_DIR}/cg/nuget/cgmanifest.json")
fi
if [[ -n "$arg_UseDev" ]]; then
if [[ ! -f $MY_DIR/Out/Selfhost/Dev/bxl ]]; then
print_error "Error: Could not find the dev deployment. Make sure you build with --deploy-dev first."
exit 1
fi
export BUILDXL_BIN=$MY_DIR/Out/Selfhost/Dev
else
getLkg
fi
compileWithBxl ${arg_Positional[@]}
if [[ -n "$arg_DeployDev" ]]; then
deployBxl "$MY_DIR/Out/Bin/debug/${DeploymentFolder}" "$MY_DIR/Out/Selfhost/Dev"
fi
if [[ -n "$arg_DeployDevRelease" ]]; then
deployBxl "$MY_DIR/Out/Bin/release/${DeploymentFolder}" "$MY_DIR/Out/Selfhost/Dev"
fi
popd