Skip to content

Commit

Permalink
Add helper script for grabbing build config and artifact directory fo…
Browse files Browse the repository at this point in the history
…r local machine (microsoft#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
  • Loading branch information
ThadHouse authored Jun 2, 2021
1 parent 6d38c06 commit d952a9b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 97 deletions.
54 changes: 6 additions & 48 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand Down
102 changes: 102 additions & 0 deletions scripts/get-buildconfig.ps1
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 5 additions & 24 deletions scripts/spin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ param (

[Parameter(Mandatory = $false)]
[ValidateSet("x86", "x64", "arm", "arm64")]
[string]$Arch = "x64",
[string]$Arch = "",

[Parameter(Mandatory = $false)]
[ValidateSet("schannel", "openssl")]
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
32 changes: 7 additions & 25 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ param (

[Parameter(Mandatory = $false)]
[ValidateSet("x86", "x64", "arm", "arm64")]
[string]$Arch = "x64",
[string]$Arch = "",

[Parameter(Mandatory = $false)]
[ValidateSet("schannel", "openssl")]
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit d952a9b

Please sign in to comment.