Skip to content

Commit 8950962

Browse files
dkaszewsdaxian-dbw
andauthored
Detect default runtime using dotnet --info in build.psm1 (PowerShell#17818)
* Detect runtime using dotnet --info * Fix path joined with backslash in Start-DevPowerShell * Rename variable to not collide with automatic one * Fix platform on Windows * Fix platform on OSX * Review: separate detection per-platform * Revert else split to minimize diff * Update build.psm1 Co-authored-by: Dongbo Wang <[email protected]>
1 parent 38ebdb2 commit 8950962

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

build.psm1

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ param(
88

99
. "$PSScriptRoot\tools\buildCommon\startNativeExecution.ps1"
1010

11+
# CI runs with PowerShell 5.0, so don't use features like ?: && ||
1112
Set-StrictMode -Version 3.0
1213

1314
# On Unix paths is separated by colon
@@ -861,26 +862,29 @@ function New-PSOptions {
861862
Write-Verbose "Using framework '$Framework'"
862863

863864
if (-not $Runtime) {
864-
if ($environment.IsLinux) {
865-
$Runtime = "linux-x64"
866-
} elseif ($environment.IsMacOS) {
867-
if ($PSVersionTable.OS.Contains('ARM64')) {
868-
$Runtime = "osx-arm64"
869-
}
870-
else {
871-
$Runtime = "osx-x64"
865+
$Info = dotnet --info
866+
Write-Verbose "dotnet --info:`n${Info}"
867+
868+
$Platform, $Architecture = $info |
869+
Select-String '^\s*OS Platform:\s+(\w+)$', '^\s*Architecture:\s+(\w+)$' |
870+
Select-Object -First 2 |
871+
ForEach-Object { $_.Matches.Groups[1].Value }
872+
873+
switch ($Platform) {
874+
'Windows' {
875+
# For x86 and x64 architectures, we use win7-x64 and win7-x86 RIDs.
876+
# For arm and arm64 architectures, we use win-arm and win-arm64 RIDs.
877+
$Platform = if ($Architecture[0] -eq 'x') { 'win7' } else { 'win' }
878+
$Runtime = "${Platform}-${Architecture}"
872879
}
873-
} else {
874-
$RID = dotnet --info | ForEach-Object {
875-
if ($_ -match "RID") {
876-
$_ -split "\s+" | Select-Object -Last 1
877-
}
880+
881+
'Linux' {
882+
$Runtime = "linux-${Architecture}"
878883
}
879884

880-
# We plan to release packages targeting win7-x64 and win7-x86 RIDs,
881-
# which supports all supported windows platforms.
882-
# So we, will change the RID to win7-<arch>
883-
$Runtime = $RID -replace "win\d+", "win7"
885+
'Darwin' {
886+
$Runtime = "osx-${Architecture}"
887+
}
884888
}
885889

886890
if (-not $Runtime) {
@@ -2272,7 +2276,7 @@ function Start-DevPowerShell {
22722276

22732277
# splatting for the win
22742278
$startProcessArgs = @{
2275-
FilePath = "$BinDir\pwsh"
2279+
FilePath = Join-Path $BinDir 'pwsh'
22762280
}
22772281

22782282
if ($ArgumentList) {

0 commit comments

Comments
 (0)