diff --git a/Documentation/DependencyFlowOnboardingWithoutArcade.md b/Documentation/DependencyFlowOnboardingWithoutArcade.md index e4cb564afb1..8cc5e83df23 100644 --- a/Documentation/DependencyFlowOnboardingWithoutArcade.md +++ b/Documentation/DependencyFlowOnboardingWithoutArcade.md @@ -80,8 +80,6 @@ If you only have one Azure DevOps job that publishes assets, then you can add th scriptLocation: scriptPath scriptPath: $(System.DefaultWorkingDirectory)/eng/common/sdk-task.ps1 arguments: -task PublishBuildAssets - -restore - -msbuildEngine dotnet /p:ManifestsPath='$(Build.StagingDirectory)/Download/AssetManifests' /p:MaestroApiEndpoint=https://maestro.dot.net" ``` diff --git a/eng/common/build.ps1 b/eng/common/build.ps1 index 2cbb725323e..62699a692d1 100644 --- a/eng/common/build.ps1 +++ b/eng/common/build.ps1 @@ -1,13 +1,13 @@ [CmdletBinding(PositionalBinding=$false)] Param( - [string][Alias('c')]$configuration = "Debug", - [string]$platform = $null, + [string][Alias('c')]$configuration, + [string]$platform, [string] $projects, - [string][Alias('v')]$verbosity = "minimal", - [string] $msbuildEngine = $null, - [bool] $warnAsError = $true, - [string] $warnNotAsError = '', - [bool] $nodeReuse = $true, + [string][Alias('v')]$verbosity, + [string] $msbuildEngine, + [bool] $warnAsError, + [string] $warnNotAsError, + [bool] $nodeReuse, [switch] $buildCheck = $false, [switch][Alias('r')]$restore, [switch] $deployDeps, @@ -28,8 +28,8 @@ Param( [switch][Alias('nobl')]$excludeCIBinarylog, [switch] $ci, [switch] $prepareMachine, - [string] $runtimeSourceFeed = '', - [string] $runtimeSourceFeedKey = '', + [string] $runtimeSourceFeed, + [string] $runtimeSourceFeedKey, [switch] $excludePrereleaseVS, [switch] $nativeToolsOnMachine, [switch] $help, @@ -86,6 +86,10 @@ function Print-Usage() { Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)." } +# Opt in to letting tools.ps1 own the CI/environment-aware defaults for the parameters it +# manages (e.g. binaryLog, nodeReuse, configuration); see tools.ps1 for details. +$importerBoundParameters = $PSBoundParameters + . $PSScriptRoot\tools.ps1 function InitializeCustomToolset { @@ -169,17 +173,6 @@ try { exit 0 } - if ($ci) { - if (-not $excludeCIBinarylog) { - $binaryLog = $true - } - # Disable node reuse on CI unless explicitly opted in via MSBUILD_NODEREUSE_ENABLED. - # Internal testing only; this env var will be replaced with a switch (https://github.com/dotnet/arcade/issues/17013) and must not be depended on. - if ($env:MSBUILD_NODEREUSE_ENABLED -ne "1") { - $nodeReuse = $false - } - } - if (-not [string]::IsNullOrEmpty($binaryLogName)) { $binaryLog = $true } diff --git a/eng/common/build.sh b/eng/common/build.sh index 3a9fdcfd0f5..e3f3f1b6dc8 100755 --- a/eng/common/build.sh +++ b/eng/common/build.sh @@ -67,7 +67,6 @@ restore=false build=false source_build=false product_build=false -from_vmr=false rebuild=false test=false integration_test=false @@ -76,23 +75,12 @@ pack=false publish=false sign=false public=false -ci=false clean=false -warn_as_error=true -warn_not_as_error='' -node_reuse=true build_check=false -binary_log=false binary_log_name='' -exclude_ci_binary_log=false projects='' -configuration='' -prepare_machine=false -verbosity='minimal' -runtime_source_feed='' -runtime_source_feed_key='' properties=() while [[ $# -gt 0 ]]; do @@ -208,21 +196,6 @@ while [[ $# -gt 0 ]]; do shift done -if [[ -z "$configuration" ]]; then - if [[ "$source_build" = true ]]; then configuration="Release"; else configuration="Debug"; fi -fi - -if [[ "$ci" == true ]]; then - # Disable node reuse on CI unless explicitly opted in via MSBUILD_NODEREUSE_ENABLED. - # Internal testing only; this env var will be replaced with a switch (https://github.com/dotnet/arcade/issues/17013) and must not be depended on. - if [[ "${MSBUILD_NODEREUSE_ENABLED:-}" != "1" ]]; then - node_reuse=false - fi - if [[ "$exclude_ci_binary_log" == false ]]; then - binary_log=true - fi -fi - . "$scriptroot/tools.sh" function InitializeCustomToolset { diff --git a/eng/common/core-templates/job/publish-build-assets.yml b/eng/common/core-templates/job/publish-build-assets.yml index 700f7711465..5324ab4eb55 100644 --- a/eng/common/core-templates/job/publish-build-assets.yml +++ b/eng/common/core-templates/job/publish-build-assets.yml @@ -135,7 +135,7 @@ jobs: scriptType: ps scriptLocation: scriptPath scriptPath: $(System.DefaultWorkingDirectory)/eng/common/sdk-task.ps1 - arguments: -task PublishBuildAssets -restore -msbuildEngine dotnet + arguments: -task PublishBuildAssets -msbuildEngine dotnet /p:ManifestsPath='$(Build.StagingDirectory)/AssetManifests' /p:IsAssetlessBuild=${{ parameters.isAssetlessBuild }} /p:MaestroApiEndpoint=https://maestro.dot.net diff --git a/eng/common/core-templates/post-build/post-build.yml b/eng/common/core-templates/post-build/post-build.yml index 8aa86e30491..62aa9c0e9de 100644 --- a/eng/common/core-templates/post-build/post-build.yml +++ b/eng/common/core-templates/post-build/post-build.yml @@ -225,7 +225,7 @@ stages: displayName: Validate inputs: filePath: eng\common\sdk-task.ps1 - arguments: -task SigningValidation -restore -msbuildEngine dotnet + arguments: -task SigningValidation -msbuildEngine dotnet /p:PackageBasePath='$(Build.ArtifactStagingDirectory)/PackageArtifacts' /p:SignCheckExclusionsFile='$(System.DefaultWorkingDirectory)/eng/SignCheckExclusionsFile.txt' ${{ parameters.signingValidationAdditionalParameters }} diff --git a/eng/common/darc-init.ps1 b/eng/common/darc-init.ps1 index a5be41db690..d317317f81c 100644 --- a/eng/common/darc-init.ps1 +++ b/eng/common/darc-init.ps1 @@ -1,10 +1,14 @@ param ( $darcVersion = $null, $versionEndpoint = 'https://maestro.dot.net/api/assets/darc-version?api-version=2020-02-20', - $verbosity = 'minimal', + $verbosity, $toolpath = $null ) +# Opt in to letting tools.ps1 own the CI/environment-aware defaults for the parameters it +# manages (e.g. verbosity); see tools.ps1 for details. +$importerBoundParameters = $PSBoundParameters + . $PSScriptRoot\tools.ps1 function InstallDarcCli ($darcVersion, $toolpath) { diff --git a/eng/common/darc-init.sh b/eng/common/darc-init.sh index b56d40e5706..31e57158922 100755 --- a/eng/common/darc-init.sh +++ b/eng/common/darc-init.sh @@ -3,7 +3,6 @@ source="${BASH_SOURCE[0]}" darcVersion='' versionEndpoint='https://maestro.dot.net/api/assets/darc-version?api-version=2020-02-20' -verbosity='minimal' while [[ $# -gt 0 ]]; do opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")" diff --git a/eng/common/dotnet-install.ps1 b/eng/common/dotnet-install.ps1 index 50ae6273768..e7b3b3b52f2 100644 --- a/eng/common/dotnet-install.ps1 +++ b/eng/common/dotnet-install.ps1 @@ -1,13 +1,17 @@ [CmdletBinding(PositionalBinding=$false)] Param( - [string] $verbosity = 'minimal', + [string] $verbosity, [string] $architecture = '', [string] $version = 'Latest', [string] $runtime = 'dotnet', - [string] $RuntimeSourceFeed = '', - [string] $RuntimeSourceFeedKey = '' + [string] $RuntimeSourceFeed, + [string] $RuntimeSourceFeedKey ) +# Opt in to letting tools.ps1 own the CI/environment-aware defaults for the parameters it +# manages (e.g. verbosity, runtimeSourceFeed); see tools.ps1 for details. +$importerBoundParameters = $PSBoundParameters + . $PSScriptRoot\tools.ps1 if (-not [string]::IsNullOrEmpty($env:DOTNET_GLOBAL_INSTALL_DIR)) { diff --git a/eng/common/msbuild.ps1 b/eng/common/msbuild.ps1 index 495d533a909..f2ecfbad295 100644 --- a/eng/common/msbuild.ps1 +++ b/eng/common/msbuild.ps1 @@ -1,26 +1,22 @@ [CmdletBinding(PositionalBinding=$false)] Param( - [string] $verbosity = 'minimal', - [bool] $warnAsError = $true, - [bool] $nodeReuse = $true, + [string] $verbosity, + [bool] $warnAsError, + [bool] $nodeReuse, [switch] $ci, [switch] $prepareMachine, [switch] $excludePrereleaseVS, - [string] $msbuildEngine = $null, + [string] $msbuildEngine, [Parameter(ValueFromRemainingArguments=$true)][String[]]$extraArgs ) +# Opt in to letting tools.ps1 own the CI/environment-aware defaults for the parameters it +# manages (e.g. nodeReuse, warnAsError, verbosity); see tools.ps1 for details. +$importerBoundParameters = $PSBoundParameters + . $PSScriptRoot\tools.ps1 try { - if ($ci) { - # Disable node reuse on CI unless explicitly opted in via MSBUILD_NODEREUSE_ENABLED. - # Internal testing only; this env var will be replaced with a switch (https://github.com/dotnet/arcade/issues/17013) and must not be depended on. - if ($env:MSBUILD_NODEREUSE_ENABLED -ne "1") { - $nodeReuse = $false - } - } - MSBuild @extraArgs } catch { diff --git a/eng/common/msbuild.sh b/eng/common/msbuild.sh index 333be3232fc..aaa75d8135b 100755 --- a/eng/common/msbuild.sh +++ b/eng/common/msbuild.sh @@ -12,10 +12,6 @@ while [[ -h "$source" ]]; do done scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" -verbosity='minimal' -warn_as_error=true -node_reuse=true -prepare_machine=false extra_args='' while (($# > 0)); do @@ -50,13 +46,5 @@ done . "$scriptroot/tools.sh" -if [[ "$ci" == true ]]; then - # Disable node reuse on CI unless explicitly opted in via MSBUILD_NODEREUSE_ENABLED. - # Internal testing only; this env var will be replaced with a switch (https://github.com/dotnet/arcade/issues/17013) and must not be depended on. - if [[ "${MSBUILD_NODEREUSE_ENABLED:-}" != "1" ]]; then - node_reuse=false - fi -fi - MSBuild $extra_args ExitWithExitCode 0 diff --git a/eng/common/sdk-task.ps1 b/eng/common/sdk-task.ps1 index 68119de603e..9bbd46d1404 100644 --- a/eng/common/sdk-task.ps1 +++ b/eng/common/sdk-task.ps1 @@ -1,29 +1,35 @@ [CmdletBinding(PositionalBinding=$false)] Param( - [string] $configuration = 'Debug', + [string] $configuration, [string] $task, - [string] $verbosity = 'minimal', - [string] $msbuildEngine = $null, - [switch] $restore, + [string] $verbosity, + [string] $msbuildEngine, + [switch] $noRestore, [switch] $prepareMachine, [switch][Alias('nobl')]$excludeCIBinaryLog, [switch]$noWarnAsError, [switch] $help, - [string] $runtimeSourceFeed = '', - [string] $runtimeSourceFeedKey = '', + [string] $runtimeSourceFeed, + [string] $runtimeSourceFeedKey, [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties ) $ci = $true $binaryLog = if ($excludeCIBinaryLog) { $false } else { $true } $warnAsError = if ($noWarnAsError) { $false } else { $true } +$restore = -not $noRestore + +# Opt in to letting tools.ps1 own the CI/environment-aware defaults for the parameters it +# manages (e.g. configuration, verbosity). The $binaryLog/$warnAsError values set above by +# assignment are preserved, because only declared-but-unpassed parameters are unbound. +$importerBoundParameters = $PSBoundParameters . $PSScriptRoot\tools.ps1 function Print-Usage() { Write-Host "Common settings:" Write-Host " -task Name of Arcade task (name of a project in toolset directory of the Arcade SDK package)" - Write-Host " -restore Restore dependencies" + Write-Host " -noRestore Skip restoring dependencies" Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]" Write-Host " -help Print help and exit" Write-Host "" @@ -36,22 +42,6 @@ function Print-Usage() { Write-Host "Command line arguments not listed above are passed thru to msbuild." } -function Build([string]$target) { - $logSuffix = if ($target -eq 'Execute') { '' } else { ".$target" } - $log = Join-Path $LogDir "$task$logSuffix.binlog" - $binaryLogArg = if ($binaryLog) { "/bl:$log" } else { "" } - $outputPath = Join-Path $ToolsetDir "$task\" - - MSBuild $taskProject ` - $binaryLogArg ` - /t:$target ` - /p:Configuration=$configuration ` - /p:RepoRoot=$RepoRoot ` - /p:BaseIntermediateOutputPath=$outputPath ` - /v:$verbosity ` - @properties -} - try { if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) { Print-Usage @@ -75,11 +65,20 @@ try { ExitWithExitCode 1 } - if ($restore) { - Build 'Restore' - } + $log = Join-Path $LogDir "$task.binlog" + $binaryLogArg = if ($binaryLog) { "/bl:$log" } else { "" } + $restoreArg = if ($restore) { "/restore" } else { "" } + $outputPath = Join-Path $ToolsetDir "$task\" - Build 'Execute' + MSBuild $taskProject ` + $binaryLogArg ` + $restoreArg ` + /t:Execute ` + /p:Configuration=$configuration ` + /p:RepoRoot=$RepoRoot ` + /p:BaseIntermediateOutputPath=$outputPath ` + /v:$verbosity ` + @properties } catch { Write-Host $_.ScriptStackTrace diff --git a/eng/common/sdk-task.sh b/eng/common/sdk-task.sh index 1cf71bb2aea..54a735f10a0 100755 --- a/eng/common/sdk-task.sh +++ b/eng/common/sdk-task.sh @@ -3,12 +3,13 @@ show_usage() { echo "Common settings:" echo " --task Name of Arcade task (name of a project in toolset directory of the Arcade SDK package)" - echo " --restore Restore dependencies" + echo " --no-restore Skip restoring dependencies" echo " --verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]" echo " --help Print help and exit" echo "" echo "Advanced settings:" + echo " --prepareMachine Prepare machine for CI run" echo " --excludeCIBinarylog Don't output binary log (short: -nobl)" echo " --noWarnAsError Do not warn as error" echo "" @@ -27,33 +28,9 @@ while [[ -h "$source" ]]; do done scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" -Build() { - local target=$1 - local log_suffix="" - [[ "$target" != "Execute" ]] && log_suffix=".$target" - local log="$log_dir/$task$log_suffix.binlog" - local binaryLogArg="" - [[ $binary_log == true ]] && binaryLogArg="/bl:$log" - local output_path="$toolset_dir/$task/" - - MSBuild "$taskProject" \ - $binaryLogArg \ - /t:"$target" \ - /p:Configuration="$configuration" \ - /p:RepoRoot="$repo_root" \ - /p:BaseIntermediateOutputPath="$output_path" \ - /v:"$verbosity" \ - $properties -} - binary_log=true -configuration="Debug" -verbosity="minimal" -exclude_ci_binary_log=false -restore=false help=false properties='' -warnAsError=true while (($# > 0)); do lowerI="$(echo $1 | tr "[:upper:]" "[:lower:]")" @@ -62,8 +39,8 @@ while (($# > 0)); do task=$2 shift 2 ;; - --restore) - restore=true + --no-restore) + restore=false shift 1 ;; --verbosity) @@ -75,8 +52,12 @@ while (($# > 0)); do exclude_ci_binary_log=true shift 1 ;; - --noWarnAsError) - warnAsError=false + --nowarnaserror) + warn_as_error=false + shift 1 + ;; + --preparemachine) + prepare_machine=true shift 1 ;; --help) @@ -111,11 +92,21 @@ if [[ ! -e "$taskProject" ]]; then ExitWithExitCode 1 fi -if $restore; then - Build "Restore" -fi - -Build "Execute" - +log="$log_dir/$task.binlog" +binaryLogArg="" +[[ $binary_log == true ]] && binaryLogArg="/bl:$log" +restoreArg="" +[[ $restore == true ]] && restoreArg="/restore" +output_path="$toolset_dir/$task/" + +MSBuild "$taskProject" \ + $binaryLogArg \ + $restoreArg \ + /t:Execute \ + /p:Configuration="$configuration" \ + /p:RepoRoot="$repo_root" \ + /p:BaseIntermediateOutputPath="$output_path" \ + /v:"$verbosity" \ + $properties ExitWithExitCode 0 diff --git a/eng/common/tools.ps1 b/eng/common/tools.ps1 index de32a6da377..e3f12d65f58 100644 --- a/eng/common/tools.ps1 +++ b/eng/common/tools.ps1 @@ -1,6 +1,26 @@ # Initialize variables if they aren't already defined. # These may be defined as parameters of the importing script, or set after importing this script. +# An importing script can opt in to letting tools.ps1 own the defaults for the variables below +# by assigning its bound parameters to $importerBoundParameters before dot-sourcing this file: +# $importerBoundParameters = $PSBoundParameters +# . $PSScriptRoot\tools.ps1 +# A declared-but-unbound [switch]/[bool]/[string] parameter is still "defined", which would +# otherwise mask the CI/environment-aware defaults computed below. For opted-in scripts, drop +# any of these variables that the importer declares as a parameter but did not explicitly pass, +# so the defaults below take effect. Values the importer passed explicitly, or set by assignment +# (the other supported pattern, e.g. sdk-task.ps1 computing $binaryLog/$warnAsError), are +# preserved because only declared-but-unpassed parameters are removed. The whole block is skipped +# for scripts that do not opt in, so external consumers keep their current behavior unchanged. +if (Test-Path variable:importerBoundParameters) { + $importerDeclaredParameters = (Get-PSCallStack)[1].InvocationInfo.MyCommand.Parameters.Keys + foreach ($toolsManagedDefault in @('binaryLog', 'nodeReuse', 'warnAsError', 'warnNotAsError', 'verbosity', 'configuration', 'msbuildEngine', 'runtimeSourceFeed', 'runtimeSourceFeedKey')) { + if (($importerDeclaredParameters -contains $toolsManagedDefault) -and -not $importerBoundParameters.ContainsKey($toolsManagedDefault)) { + Remove-Variable -Name $toolsManagedDefault -ErrorAction SilentlyContinue + } + } +} + # CI mode - set to true on CI server for PR validation build or official build. [bool]$ci = if (Test-Path variable:ci) { $ci } else { $false } @@ -23,7 +43,9 @@ [string]$verbosity = if (Test-Path variable:verbosity) { $verbosity } else { 'minimal' } # Set to true to reuse msbuild nodes. Recommended to not reuse on CI. -[bool]$nodeReuse = if (Test-Path variable:nodeReuse) { $nodeReuse } else { !$ci } +# On CI, node reuse is disabled by default; set MSBUILD_NODEREUSE_ENABLED=1 to opt back in. +# Internal testing only; this env var will be replaced with a switch (https://github.com/dotnet/arcade/issues/17013) and must not be depended on. +[bool]$nodeReuse = if (Test-Path variable:nodeReuse) { $nodeReuse } else { (!$ci) -or ($env:MSBUILD_NODEREUSE_ENABLED -eq '1') } # Configures warning treatment in msbuild. [bool]$warnAsError = if (Test-Path variable:warnAsError) { $warnAsError } else { $true } diff --git a/eng/common/tools.sh b/eng/common/tools.sh index 69ca926a6a8..c1a34a3560e 100755 --- a/eng/common/tools.sh +++ b/eng/common/tools.sh @@ -9,7 +9,12 @@ ci=${ci:-false} source_build=${source_build:-false} # Build configuration. Common values include 'Debug' and 'Release', but the repository may use other names. -configuration=${configuration:-'Debug'} +# When building from source, default to 'Release'; otherwise default to 'Debug'. +if [[ "$source_build" == true ]]; then + configuration=${configuration:-'Release'} +else + configuration=${configuration:-'Debug'} +fi # Set to true to opt out of outputting binary log while running in CI exclude_ci_binary_log=${exclude_ci_binary_log:-false} @@ -33,7 +38,9 @@ restore=${restore:-true} verbosity=${verbosity:-'minimal'} # Set to true to reuse msbuild nodes. Recommended to not reuse on CI. -if [[ "$ci" == true ]]; then +# On CI, node reuse is disabled by default; set MSBUILD_NODEREUSE_ENABLED=1 to opt back in. +# Internal testing only; this env var will be replaced with a switch (https://github.com/dotnet/arcade/issues/17013) and must not be depended on. +if [[ "$ci" == true && "${MSBUILD_NODEREUSE_ENABLED:-}" != "1" ]]; then node_reuse=${node_reuse:-false} else node_reuse=${node_reuse:-true} diff --git a/eng/publishing/v3/publish.yml b/eng/publishing/v3/publish.yml index 6a0907ff5a1..92a3a74ad17 100644 --- a/eng/publishing/v3/publish.yml +++ b/eng/publishing/v3/publish.yml @@ -138,7 +138,7 @@ stages: scriptLocation: scriptPath scriptPath: $(System.DefaultWorkingDirectory)/eng/common/sdk-task.ps1 arguments: > - -task PublishArtifactsInManifest -restore -msbuildEngine dotnet -noWarnAsError + -task PublishArtifactsInManifest -msbuildEngine dotnet -noWarnAsError /p:PublishingInfraVersion=3 /p:BARBuildId=${{ parameters.BARBuildId }} /p:TargetChannels='${{ parameters.PromoteToChannelIds }}'