Skip to content

Commit

Permalink
Implement building the repo for multiple configurations and architect…
Browse files Browse the repository at this point in the history
…ures with a single command on Windows. (#33295)

* Implement building the repo for multiple configurations and architectures with a single command on Windows.

* Use -Command instead of -File to invoke pwsh build script.

* Run all builds and output which builds failed at the end (if any)

* Update help output.

* Prepend argument list with architecture args instead of appending so as to allow scripts to override them with MSBuild arguments.

* Fix typo.
  • Loading branch information
jkoritzinsky committed Mar 11, 2020
1 parent 514db28 commit 2b27323
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ setlocal
set _args=%*
if "%~1"=="-?" set _args=-help

powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0eng\build.ps1" %_args%
powershell -ExecutionPolicy ByPass -NoProfile -Command "%~dp0eng\build.ps1" %_args%
exit /b %ERRORLEVEL%
38 changes: 29 additions & 9 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Param(
[switch][Alias('b')]$build,
[switch][Alias('t')]$test,
[switch]$buildtests,
[string][Alias('c')]$configuration = "Debug",
[string[]][Alias('c')]$configuration = @("Debug"),
[string][Alias('f')]$framework,
[string]$vs,
[string]$os,
[switch]$allconfigurations,
[switch]$coverage,
[string]$testscope,
[string]$arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant(),
[string[]][Alias('a')]$arch = @([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant()),
[string]$subsetCategory,
[string]$subset,
[ValidateSet("Debug","Release","Checked")][string]$runtimeConfiguration = "Debug",
Expand All @@ -25,8 +25,8 @@ function Get-Help() {
Write-Host " -subsetCategory Build a subsetCategory, print available subsetCategories with -subset help"
Write-Host " -vs Open the solution with VS for Test Explorer support. Path or solution name (ie -vs Microsoft.CSharp)"
Write-Host " -os Build operating system: Windows_NT or Unix"
Write-Host " -arch Build platform: x86, x64, arm or arm64"
Write-Host " -configuration Build configuration: Debug, Release or [CoreCLR]Checked (short: -c)"
Write-Host " -arch Build platform: x86, x64, arm or arm64 (short: -a). Pass a comma-separated list to build for multiple architectures."
Write-Host " -configuration Build configuration: Debug, Release or [CoreCLR]Checked (short: -c). Pass a comma-separated list to build for multiple configurations"
Write-Host " -runtimeConfiguration Runtime build configuration: Debug, Release or [CoreCLR]Checked"
Write-Host " -librariesConfiguration Libraries build configuration: Debug or Release"
Write-Host " -verbosity MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
Expand Down Expand Up @@ -144,18 +144,38 @@ foreach ($argument in $PSBoundParameters.Keys)
"build" { $arguments += " -build" }
"buildtests" { if ($build -eq $true) { $arguments += " /p:BuildTests=true" } else { $arguments += " -build /p:BuildTests=only" } }
"test" { $arguments += " -test" }
"configuration" { $arguments += " -configuration $((Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])))" }
"runtimeConfiguration" { $arguments += " /p:RuntimeConfiguration=$((Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])))" }
"framework" { $arguments += " /p:BuildTargetFramework=$($PSBoundParameters[$argument].ToLowerInvariant())" }
"os" { $arguments += " /p:TargetOS=$($PSBoundParameters[$argument])" }
"allconfigurations" { $arguments += " /p:BuildAllConfigurations=true" }
"arch" { $arch = $PSBoundParameters[$argument]; $arguments += " /p:ArchGroup=$arch /p:TargetArchitecture=$arch" }
"properties" { $arguments += " " + $properties }
# configuration and arch can be specified multiple times, so they should be no-ops here
"configuration" {}
"arch" {}
default { $arguments += " /p:$argument=$($PSBoundParameters[$argument])" }
}
}

$env:__DistroRid="win-$arch"
$failedBuilds = @()

Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $arguments"
exit $lastExitCode
foreach ($config in $configuration) {
$argumentsWithConfig = $arguments + " -configuration $((Get-Culture).TextInfo.ToTitleCase($config))";
foreach ($singleArch in $arch) {
$argumentsWithArch = "/p:ArchGroup=$singleArch /p:TargetArchitecture=$singleArch " + $argumentsWithConfig
$env:__DistroRid="win-$singleArch"
Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $argumentsWithArch"
if ($lastExitCode -ne 0) {
$failedBuilds += "Configuration: $config, Architecture: $singleArch"
}
}
}

if ($failedBuilds.Count -ne 0) {
Write-Host "Some builds failed:"
foreach ($failedBuild in $failedBuilds) {
Write-Host "`t$failedBuild"
}
exit 1
}

exit 0

0 comments on commit 2b27323

Please sign in to comment.