From d952a9bd93abda148e75dceb5e2ae3ed93954a75 Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 1 Jun 2021 20:30:19 -0700 Subject: [PATCH] Add helper script for grabbing build config and artifact directory for local machine (#1650) * Add helper script for grabbing build config and artifact directory for local machine * Make script only a single purpose * Allow empty parameter * Don't pass a default for platform --- scripts/build.ps1 | 54 +++---------------- scripts/get-buildconfig.ps1 | 102 ++++++++++++++++++++++++++++++++++++ scripts/spin.ps1 | 29 ++-------- scripts/test.ps1 | 32 +++-------- 4 files changed, 120 insertions(+), 97 deletions(-) create mode 100644 scripts/get-buildconfig.ps1 diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 77a13dcebf..f82f37919b 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -179,25 +179,12 @@ param ( Set-StrictMode -Version 'Latest' $PSDefaultParameterValues['*:ErrorAction'] = 'Stop' -if ("" -eq $Arch) { - if ($IsMacOS) { - $RunningArch = uname -m - if ("x86_64" -eq $RunningArch) { - $IsTranslated = sysctl -in sysctl.proc_translated - if ($IsTranslated) { - $Arch = "arm64" - } else { - $Arch = "x64" - } - } elseif ("arm64" -eq $RunningArch) { - $Arch = "arm64" - } else { - Write-Error "Unknown architecture" - } - } else { - $Arch = "x64" - } -} +$BuildConfig = & (Join-Path $PSScriptRoot get-buildconfig.ps1) -Platform $Platform -Tls $Tls -Arch $Arch -ExtraArtifactDir $ExtraArtifactDir -Config $Config + +$Platform = $BuildConfig.Platform +$Tls = $BuildConfig.Tls +$Arch = $BuildConfig.Arch +$ArtifactsDir = $BuildConfig.ArtifactsDir if ($Generator -eq "") { if ($IsWindows) { @@ -207,27 +194,6 @@ if ($Generator -eq "") { } } -# Default TLS based on current platform. -if ("" -eq $Tls) { - if ($IsWindows) { - $Tls = "schannel" - } else { - $Tls = "openssl" - } -} - -if ("" -eq $Platform) { - if ($IsWindows) { - $Platform = "windows" - } elseif ($IsLinux) { - $Platform = "linux" - } elseif ($IsMacOS) { - $Platform = "macos" - } else { - Write-Error "Unsupported platform type!" - } -} - if (!$IsWindows -And $Platform -eq "uwp") { Write-Error "[$(Get-Date)] Cannot build uwp on non windows platforms" exit @@ -240,15 +206,7 @@ $RootDir = Split-Path $PSScriptRoot -Parent $BaseArtifactsDir = Join-Path $RootDir "artifacts" $BaseBuildDir = Join-Path $RootDir "build" -$ArtifactsDir = Join-Path $BaseArtifactsDir "bin" $Platform $BuildDir = Join-Path $BaseBuildDir $Platform - -if ("" -eq $ExtraArtifactDir) { - $ArtifactsDir = Join-Path $ArtifactsDir "$($Arch)_$($Config)_$($Tls)" -} else { - $ArtifactsDir = Join-Path $ArtifactsDir "$($Arch)_$($Config)_$($Tls)_$($ExtraArtifactDir)" -} - $BuildDir = Join-Path $BuildDir "$($Arch)_$($Tls)" if ($Clean) { diff --git a/scripts/get-buildconfig.ps1 b/scripts/get-buildconfig.ps1 new file mode 100644 index 0000000000..ca9752d5e6 --- /dev/null +++ b/scripts/get-buildconfig.ps1 @@ -0,0 +1,102 @@ +<# + +.SYNOPSIS +This script provides a build config helper used by multiple build scripts. + +.PARAMETER Config + The debug or release configuration to build for. + +.PARAMETER Arch + The CPU architecture to build for. + +.PARAMETER Platform + Specify which platform to build for + +.PARAMETER Tls + The TLS library to use. + +.PARAMETER ExtraArtifactDir + Add an extra classifier to the artifact directory to allow publishing alternate builds of same base library + +#> + +param ( + [Parameter(Mandatory = $false)] + [ValidateSet("Debug", "Release")] + [string]$Config = "Debug", + + [Parameter(Mandatory = $false)] + [ValidateSet("x86", "x64", "arm", "arm64")] + [string]$Arch = "", + + [Parameter(Mandatory = $false)] + [ValidateSet("uwp", "windows", "linux", "macos", "")] # For future expansion + [string]$Platform = "", + + [Parameter(Mandatory = $false)] + [ValidateSet("schannel", "openssl")] + [string]$Tls = "", + + [Parameter(Mandatory = $false)] + [string]$ExtraArtifactDir = "" +) + +Set-StrictMode -Version 'Latest' +$PSDefaultParameterValues['*:ErrorAction'] = 'Stop' + +if ("" -eq $Arch) { + if ($IsMacOS) { + $RunningArch = uname -m + if ("x86_64" -eq $RunningArch) { + $IsTranslated = sysctl -in sysctl.proc_translated + if ($IsTranslated) { + $Arch = "arm64" + } else { + $Arch = "x64" + } + } elseif ("arm64" -eq $RunningArch) { + $Arch = "arm64" + } else { + Write-Error "Unknown architecture" + } + } else { + $Arch = "x64" + } +} + +# Default TLS based on current platform. +if ("" -eq $Tls) { + if ($IsWindows) { + $Tls = "schannel" + } else { + $Tls = "openssl" + } +} + +if ("" -eq $Platform) { + if ($IsWindows) { + $Platform = "windows" + } elseif ($IsLinux) { + $Platform = "linux" + } elseif ($IsMacOS) { + $Platform = "macos" + } else { + Write-Error "Unsupported platform type!" + } +} + +$RootDir = Split-Path $PSScriptRoot -Parent +$BaseArtifactsDir = Join-Path $RootDir "artifacts" +$ArtifactsDir = Join-Path $BaseArtifactsDir "bin" $Platform +if ([string]::IsNullOrWhitespace($ExtraArtifactDir)) { + $ArtifactsDir = Join-Path $ArtifactsDir "$($Arch)_$($Config)_$($Tls)" +} else { + $ArtifactsDir = Join-Path $ArtifactsDir "$($Arch)_$($Config)_$($Tls)_$($ExtraArtifactDir)" +} + +return @{ + Platform = $Platform + Tls = $Tls + Arch = $Arch + ArtifactsDir = $ArtifactsDir +} diff --git a/scripts/spin.ps1 b/scripts/spin.ps1 index ffd211cc62..6c17ea59a7 100644 --- a/scripts/spin.ps1 +++ b/scripts/spin.ps1 @@ -48,7 +48,7 @@ param ( [Parameter(Mandatory = $false)] [ValidateSet("x86", "x64", "arm", "arm64")] - [string]$Arch = "x64", + [string]$Arch = "", [Parameter(Mandatory = $false)] [ValidateSet("schannel", "openssl")] @@ -95,24 +95,11 @@ param ( Set-StrictMode -Version 'Latest' $PSDefaultParameterValues['*:ErrorAction'] = 'Stop' -# Default TLS based on current platform. -if ("" -eq $Tls) { - if ($IsWindows) { - $Tls = "schannel" - } else { - $Tls = "openssl" - } -} +$BuildConfig = & (Join-Path $PSScriptRoot get-buildconfig.ps1) -Tls $Tls -Arch $Arch -ExtraArtifactDir $ExtraArtifactDir -Config $Config -if ($IsWindows) { - $Platform = "windows" -} elseif ($IsLinux) { - $Platform = "linux" -} elseif ($IsMacOS) { - $Platform = "macos" -} else { - Write-Error "Unsupported platform type!" -} +$Tls = $BuildConfig.Tls +$Arch = $BuildConfig.Arch +$RootArtifactDir = $BuildConfig.ArtifactsDir # Root directory of the project. $RootDir = Split-Path $PSScriptRoot -Parent @@ -133,12 +120,6 @@ if ($CodeCoverage) { } } -if ("" -eq $ExtraArtifactDir) { - $RootArtifactDir = Join-Path $RootDir "artifacts" "bin" $Platform "$($Arch)_$($Config)_$($Tls)" -} else { - $RootArtifactDir = Join-Path $RootDir "artifacts" "bin" $Platform "$($Arch)_$($Config)_$($Tls)_$($ExtraArtifactDir)" -} - # Path to the spinquic exectuable. $SpinQuic = $null if ($IsWindows) { diff --git a/scripts/test.ps1 b/scripts/test.ps1 index 5834235f9d..9cb3b3846b 100644 --- a/scripts/test.ps1 +++ b/scripts/test.ps1 @@ -88,7 +88,7 @@ param ( [Parameter(Mandatory = $false)] [ValidateSet("x86", "x64", "arm", "arm64")] - [string]$Arch = "x64", + [string]$Arch = "", [Parameter(Mandatory = $false)] [ValidateSet("schannel", "openssl")] @@ -182,24 +182,11 @@ if ($CodeCoverage) { } } -# Default TLS based on current platform. -if ("" -eq $Tls) { - if ($IsWindows) { - $Tls = "schannel" - } else { - $Tls = "openssl" - } -} +$BuildConfig = & (Join-Path $PSScriptRoot get-buildconfig.ps1) -Tls $Tls -Arch $Arch -ExtraArtifactDir $ExtraArtifactDir -Config $Config -if ($IsWindows) { - $Platform = "windows" -} elseif ($IsLinux) { - $Platform = "linux" -} elseif ($IsMacOS) { - $Platform = "macos" -} else { - Write-Error "Unsupported platform type!" -} +$Tls = $BuildConfig.Tls +$Arch = $BuildConfig.Arch +$RootArtifactDir = $BuildConfig.ArtifactsDir # Root directory of the project. $RootDir = Split-Path $PSScriptRoot -Parent @@ -217,13 +204,8 @@ if ($CodeCoverage) { # Path to the run-gtest Powershell script. $RunTest = Join-Path $RootDir "scripts/run-gtest.ps1" -if ("" -eq $ExtraArtifactDir) { - $RootArtifactDir = Join-Path $RootDir "artifacts" "bin" $Platform "$($Arch)_$($Config)_$($Tls)" -} else { - if ($Kernel) { - Write-Error "Kernel not supported with extra artifact dir" - } - $RootArtifactDir = Join-Path $RootDir "artifacts" "bin" $Platform "$($Arch)_$($Config)_$($Tls)_$($ExtraArtifactDir)" +if ("" -ne $ExtraArtifactDir -and $Kernel) { + Write-Error "Kernel not supported with extra artifact dir" } # Path to the msquictest exectuable.