2019-03-29 01:14:25 +03:00
#!/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 = ( )
2022-12-03 04:22:16 +03:00
# stores user-specified args that are not used by this script; added to the end of command line
declare arg_UserProvidedBxlArguments = ( )
2019-03-29 01:14:25 +03:00
declare arg_DeployDev = ""
2019-11-10 02:44:29 +03:00
declare arg_UseDev = ""
2019-03-29 01:14:25 +03:00
declare arg_Minimal = ""
declare arg_Internal = ""
2023-03-10 04:44:21 +03:00
# default configuration is debug
declare configuration = "Debug"
2019-03-29 01:14:25 +03:00
2020-04-21 21:21:00 +03:00
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
2022-04-05 22:44:47 +03:00
$MONO_HOME /mono Shared/Tools/NuGet.exe " $@ "
2020-04-21 21:21:00 +03:00
elif [ [ " ${ OSTYPE } " = = "darwin" * ] ] ; then
$MONO_HOME /mono Shared/Tools/NuGet.exe " $@ "
else
print_error " Operating system not supported: ${ OSTYPE } "
return 1
fi
}
2019-03-29 01:14:25 +03:00
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( ) {
2019-03-30 03:34:03 +03:00
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' )
2020-04-21 21:21:00 +03:00
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' )
2019-03-30 03:34:03 +03:00
local BUILDXL_LKG_FEED_1 = $( grep "BUILDXL_LKG_FEED_1" " $MY_DIR /Shared/Scripts/ $LKG_FILE " | cut -d= -f2 | tr -d '\r' )
2019-03-29 01:14:25 +03:00
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 "
2020-04-21 21:21:00 +03:00
callNuget install -OutputDirectory " $_BUILDXL_BOOTSTRAP_OUT " -Source $BUILDXL_LKG_FEED_1 $BUILDXL_LKG_NAME -Version $BUILDXL_LKG_VERSION
2019-03-29 01:14:25 +03:00
export BUILDXL_BIN = " $_BUILDXL_BOOTSTRAP_OUT / $BUILDXL_LKG_NAME . $BUILDXL_LKG_VERSION "
}
function setMinimal( ) {
2023-03-10 04:44:21 +03:00
arg_Positional += ( /q:${ configuration } ${ HostQualifier } " /f:output=' $MY_DIR /Out/Bin/ ${ outputConfiguration } / ${ DeploymentFolder } /*' " )
2019-03-29 01:14:25 +03:00
}
function setInternal( ) {
2019-08-22 21:17:10 +03:00
arg_Positional += ( "/p:[Sdk.BuildXL]microsoftInternal=1" )
2019-10-28 20:20:31 +03:00
arg_Positional += ( "/remoteTelemetry+" )
2019-12-24 05:12:31 +03:00
for arg in " $@ "
2019-08-22 21:17:10 +03:00
do
to_lower = ` printf '%s\n' " $arg " | awk '{ print tolower($0) }' `
if [ [ " $to_lower " = = *"endpointsecurity" * ] ] ; then
return
fi
done
2019-03-29 01:14:25 +03:00
}
function compileWithBxl( ) {
local args = (
2019-12-24 05:12:31 +03:00
--config " $MY_DIR /config.dsc "
2019-03-29 01:14:25 +03:00
/fancyConsoleMaxStatusPips:10
2023-02-18 02:24:32 +03:00
# LazySODeletion is disabled as it is flaky on linux
# /exp:LazySODeletion
2019-03-29 01:14:25 +03:00
/nowarn:11319 # DX11319: nuget version mismatch
2022-11-21 22:28:18 +03:00
/logsToRetain:20
2023-02-18 02:24:32 +03:00
/cachemiss
2023-02-18 02:53:42 +03:00
/generateCgManifestForNugets:cg/nuget/cgmanifest.json
2019-03-29 01:14:25 +03:00
" $@ "
)
if [ [ -z " ${ VSTS_BUILDXL_BIN } " ] ] ; then
2022-04-06 22:51:25 +03:00
bash " $BUILDXL_BIN /bxl.sh " " ${ args [@] } "
2019-03-29 01:14:25 +03:00
else
# Currently only used on VSTS CI to allow for custom BuildXL binary execution
2022-04-06 22:51:25 +03:00
bash " $VSTS_BUILDXL_BIN /bxl.sh " " ${ args [@] } "
2019-03-29 01:14:25 +03:00
fi
}
function printHelp( ) {
2023-04-14 20:15:20 +03:00
echo " ${ BASH_SOURCE [0] } [--deploy-dev] [--use-dev] [--minimal] [--internal] [--release] [--shared-comp] [--vs] [--test-method <full-test-method-name>] [--test-class <full-test-class-name>] <other-arguments> "
2019-03-29 01:14:25 +03:00
}
function parseArgs( ) {
arg_Positional = ( )
2022-12-03 04:22:16 +03:00
arg_UserProvidedBxlArguments = ( )
2019-03-29 01:14:25 +03:00
while [ [ $# -gt 0 ] ] ; do
cmd = " $1 "
case $cmd in
--help | -h)
printHelp
shift
return 1
; ;
--deploy-dev)
arg_DeployDev = "1"
shift
; ;
--use-dev)
arg_UseDev = "1"
shift
; ;
--minimal)
arg_Minimal = "1"
shift
; ;
2023-03-10 04:44:21 +03:00
--release)
configuration = "Release"
shift
; ;
2019-03-29 01:14:25 +03:00
--internal)
arg_Internal = "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
; ;
2020-01-14 01:57:16 +03:00
--shared-comp)
arg_Positional += ( "/p:[Sdk.BuildXL]useManagedSharedCompilation=1" )
shift
; ;
2022-09-16 22:04:33 +03:00
--use-adobuildrunner)
arg_Positional += ( "--use-adobuildrunner" )
shift
; ;
2020-01-16 20:52:48 +03:00
--vs)
arg_Positional += (
"/vs"
"/vsTargetFramework:netcoreapp3.0"
"/vsTargetFramework:netcoreapp3.1"
"/vsTargetFramework:netstandard2.0"
"/vsTargetFramework:netstandard2.1" )
shift
; ;
2022-09-21 02:50:32 +03:00
--disable-xunitretry)
arg_DisableXunitRetry = "1"
shift
; ;
2019-03-29 01:14:25 +03:00
*)
2022-12-03 04:22:16 +03:00
# "Script" flags (and the settings associated with them) might conflict with BuildXL arguments set by a user.
# In such a case, user-provided bxl arguments will override any arguments set by this script.
arg_UserProvidedBxlArguments += ( " $1 " )
2019-03-29 01:14:25 +03:00
shift
; ;
esac
done
}
function deployBxl { # (fromDir, toDir)
local fromDir = " $1 "
local toDir = " $2 "
mkdir -p " $toDir "
/usr/bin/rsync -arhq " $fromDir / " " $toDir " --delete
2019-11-10 02:44:29 +03:00
print_info " Successfully deployed developer build from $fromDir to: $toDir ; use it with the '--use-dev' flag now. "
2019-03-29 01:14:25 +03:00
}
2022-06-03 20:23:46 +03:00
function installCredProvider( ) {
local dotnetLocation = " $( which dotnet) "
if [ [ -z $dotnetLocation ] ] ; then
print_error "Did not find dotnet. Please ensure dotnet is installed per: https://docs.microsoft.com/en-us/dotnet/core/install/linux and is accessable in your PATH"
return 1
fi
local destinationFolder = " $HOME /.nuget "
local credentialProvider = " $destinationFolder /plugins/netcore/CredentialProvider.Microsoft/ "
local credentialProviderExe = " $credentialProvider /CredentialProvider.Microsoft.exe "
export NUGET_CREDENTIALPROVIDERS_PATH = " $credentialProvider "
2022-09-21 02:21:31 +03:00
# If not on ADO, do not install the cred provider if it is already installed.
# On ADO, just make sure we have the right thing, the download time is not significant for a lab build
if [ [ ( ! -n " $ADOBuild " ) && -f " $credentialProviderExe " ] ] ;
2022-06-03 20:23:46 +03:00
then
print_info " Credential provider already installed under $destinationFolder "
return ;
fi
# Download the artifacts credential provider
2022-08-02 22:49:04 +03:00
mkdir -p " $destinationFolder "
wget -q -c https://github.com/microsoft/artifacts-credprovider/releases/download/v1.0.0/Microsoft.NuGet.CredentialProvider.tar.gz -O - | tar -xz -C " $destinationFolder "
2022-06-03 20:23:46 +03:00
# Remove the .exe, since we want to replace it with a script that runs on Mac/Linux
rm " $credentialProviderExe "
# Create a new .exe with the shape of a script that calls dotnet against the dotnetcore dll
echo "#!/bin/bash" > " $credentialProviderExe "
echo " exec $dotnetLocation $credentialProvider /CredentialProvider.Microsoft.dll \"\$@\" " >> " $credentialProviderExe "
chmod u+x " $credentialProviderExe "
}
function launchCredProvider( ) {
local credProviderPath = $( find " $NUGET_CREDENTIALPROVIDERS_PATH " -name "CredentialProvider*.exe" -type f | head -n 1)
if [ [ -z $credProviderPath ] ] ; then
print_error " Did not find a credential provider under $NUGET_CREDENTIALPROVIDERS_PATH "
exit 1
fi
# CODESYNC: config.dsc. The URI needs to match the (single) feed used for the internal build
$credProviderPath -U https://pkgs.dev.azure.com/cloudbuild/_packaging/BuildXL.Selfhost/nuget/v3/index.json -V Information -C -R
}
2020-01-12 23:05:04 +03:00
# 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 "
2019-03-29 01:14:25 +03:00
parseArgs " $@ "
2023-03-10 04:44:21 +03:00
outputConfiguration = ` printf '%s' " $configuration " | awk '{ print tolower($0) }' `
2022-09-14 20:42:32 +03:00
if [ [ -n " $arg_Internal " && -n " $TF_BUILD " ] ] ; then
readonly ADOBuild = "1"
fi
2019-03-29 01:14:25 +03:00
findMono
2019-03-30 03:34:03 +03:00
if [ [ -n " $arg_DeployDev " || -n " $arg_Minimal " ] ] ; then
setMinimal
fi
if [ [ -n " $arg_Internal " ] ] ; then
2019-08-22 21:17:10 +03:00
setInternal $@
2019-03-30 03:34:03 +03:00
fi
2022-06-03 20:23:46 +03:00
# if the nuget credential provider is not configured (and the build is an internal one, which is where it is needed)
# download and install the artifacts credential provider
2022-06-15 03:02:24 +03:00
if [ [ -n " $arg_Internal " ] ] && [ [ ! -d " ${ NUGET_CREDENTIALPROVIDERS_PATH :- } " ] ] ; then
2022-06-03 20:23:46 +03:00
installCredProvider
fi
# The internal build needs authentication. When not running on ADO use the configured cred provider
# to prompt for credentials as a way to guarantee the auth token will be cached for the subsequent build.
# This may prompt an interactive pop-up/console. ADO pipelines already configure the corresponding env vars
# so there is no need to do this on that case. Once the token is cached, launching the provider shouldn't need
# any user interaction
# TF_BUILD is an environment variable that is always present on ADO builds. So we use it to detect that case.
if [ [ -n " $arg_Internal " && ! -n " $TF_BUILD " ] ] ; then
launchCredProvider
fi
# Make sure we pass the credential provider as an env var to bxl invocation
2022-06-10 01:42:51 +03:00
if [ [ -n $NUGET_CREDENTIALPROVIDERS_PATH ] ] ; then
2022-06-03 20:23:46 +03:00
arg_Positional += ( " /p:NUGET_CREDENTIALPROVIDERS_PATH= $NUGET_CREDENTIALPROVIDERS_PATH " )
fi
2022-06-10 01:42:51 +03:00
# If this is an internal build running on ADO, the nuget authentication is non-interactive and therefore we need to setup
# VSS_NUGET_EXTERNAL_FEED_ENDPOINTS if not configured, so the Microsoft credential provider can pick that up. The script assumes the corresponding
# secrets to be exposed in the environment
2023-05-31 02:31:39 +03:00
if [ [ -n " $arg_Internal " && -n " $ADOBuild " && ( ! -n $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS ) ] ] ; then
2022-06-10 01:42:51 +03:00
if [ [ ( ! -n $PAT1esSharedAssets ) ] ] ; then
print_error "Environment variable PAT1esSharedAssets is not set."
exit 1
fi
if [ [ ( ! -n $PATCloudBuild ) ] ] ; then
print_error "Environment variable PATCloudBuild is not set."
exit 1
fi
export VSS_NUGET_EXTERNAL_FEED_ENDPOINTS = " {\"endpointCredentials\":[{\"endpoint\":\"https://pkgs.dev.azure.com/1essharedassets/_packaging/BuildXL/nuget/v3/index.json\",\"password\":\" $PAT1esSharedAssets \"},{\"endpoint\":\"https://pkgs.dev.azure.com/cloudbuild/_packaging/BuildXL.Selfhost/nuget/v3/index.json\",\"password\":\" $PATCloudBuild \"}]} "
fi
2022-07-27 01:35:48 +03:00
# For local builds we want to use the in-build Linux runtime (as opposed to the runtime.linux-x64.BuildXL package)
if [ [ -z " $TF_BUILD " ] ] ; then
arg_Positional += ( "/p:[Sdk.BuildXL]validateLinuxRuntime=0" )
fi
2022-09-21 02:50:32 +03:00
# Indicates that XUnit tests should be retried due to flakiness with certain tests
if [ [ ! -n " $arg_DisableXunitRetry " ] ] ; then
2022-09-14 20:42:32 +03:00
# RetryXunitTests will specify a retry exit code of 1 for all xunit pips, and NumXunitRetries will specify the number of times to retry the xunit pip
arg_Positional += ( "/p:RetryXunitTests=1" )
arg_Positional += ( "/p:NumXunitRetries=2" )
fi
2022-08-02 22:49:04 +03:00
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
elif [ [ -z " $BUILDXL_BIN " ] ] ; then
getLkg
fi
2023-10-03 05:09:45 +03:00
# Forcing a salt here to avoid problems faced in Linux validation pipeline related to cache.
# This is related to Bug 2104538 where the cache may or may not be setting the execute bit for some executables.
2023-08-28 23:46:44 +03:00
if [ [ $arg_UserProvidedBxlArguments != *"/p:BUILDXL_FINGERPRINT_SALT" * ] ] ; then
2023-10-03 05:09:45 +03:00
arg_Positional += ( "/p:BUILDXL_FINGERPRINT_SALT=forceSaltForLinuxBugFixPR" )
2023-08-28 23:46:44 +03:00
fi
2022-12-03 04:22:16 +03:00
compileWithBxl ${ arg_Positional [@] } ${ arg_UserProvidedBxlArguments [@] }
2019-03-29 01:14:25 +03:00
if [ [ -n " $arg_DeployDev " ] ] ; then
2023-03-10 04:44:21 +03:00
deployBxl " $MY_DIR /Out/Bin/ ${ outputConfiguration } / ${ DeploymentFolder } " " $MY_DIR /Out/Selfhost/Dev "
2019-11-10 02:44:29 +03:00
fi
2022-09-16 22:04:33 +03:00
popd