From f2e306fe53a3a8d52be4b422a80a09e7c19974c8 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 10 Nov 2021 13:58:33 -0800 Subject: [PATCH 1/2] Fix build for Apple M1 when running PowerShell 7.2 (arm64) The previous fix assumed PowerShell was always running in an emulated mode (i.e. running PowerShell (x64) but on an Apple M1). Now that PowerShell 7.2 has a native build for Apple M1 (arm64) the check needs to handle both cases. We must also skip asking `dotnet-install` to install the 3.1 or 5.0 .NET Runtimes on an Apple M1 because they don't exist, but their installer tries to get them anyway. This was a non-breaking bug previously where the macOS x64 runtimes would be installed, but not used. --- PowerShellEditorServices.build.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index 9e98a1445..d2a2169d1 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -29,7 +29,9 @@ $script:dotnetTestArgs = @( ) $script:IsNix = $IsLinux -or $IsMacOS -$script:IsRosetta = $IsMacOS -and (sysctl -n sysctl.proc_translated) -eq 1 # Mac M1 +# For Apple M1, pwsh might be getting emulated, in which case we need to check +# for the proc_translated flag, otherwise we can check the architecture. +$script:IsAppleM1 = $IsMacOS -and ((sysctl -n sysctl.proc_translated) -eq 1 -or (uname -m) -eq "arm64") $script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Hosting", "BuildInfo.cs") $script:PsesCommonProps = [xml](Get-Content -Raw "$PSScriptRoot/PowerShellEditorServices.Common.props") @@ -110,8 +112,12 @@ task SetupDotNet -Before Clean, Build, TestServerWinPS, TestServerPS7, TestServe if (!(Test-Path $dotnetExePath)) { # TODO: Test .NET 5 with PowerShell 7.1 + # + # We use the .NET 6 SDK, so we always install it and its runtime. Install-Dotnet -Channel '6.0' # SDK and runtime - Install-Dotnet -Channel '3.1','5.0' -Runtime # Runtime only + # Anywhere other than on a Mac with an M1 processor, we additionally + # install the .NET 3.1 and 5.0 runtimes (but not their SDKs). + if (!$script:IsAppleM1) { Install-Dotnet -Channel '3.1','5.0' -Runtime } } # This variable is used internally by 'dotnet' to know where it's installed @@ -235,7 +241,7 @@ task TestServerWinPS -If (-not $script:IsNix) { exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.Desktop } } -task TestServerPS7 -If (-not $script:IsRosetta) { +task TestServerPS7 -If (-not $script:IsAppleM1) { Set-Location .\test\PowerShellEditorServices.Test\ exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.PS7 } } @@ -249,7 +255,7 @@ task TestE2E { Set-Location .\test\PowerShellEditorServices.Test.E2E\ $env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" } - $NetRuntime = if ($IsRosetta) { $script:NetRuntime.PS72 } else { $script:NetRuntime.PS7 } + $NetRuntime = if ($IsAppleM1) { $script:NetRuntime.PS72 } else { $script:NetRuntime.PS7 } exec { & $script:dotnetExe $script:dotnetTestArgs $NetRuntime } # Run E2E tests in ConstrainedLanguage mode. From d27c1563177e8a47524334a3d771111f024ec1bb Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 10 Nov 2021 14:12:34 -0800 Subject: [PATCH 2/2] Update tests' PowerShell SDK package dependencies Dependabot gets a bit confused here because we conditionally depend on both the 7.0 and 7.2 SDK packages. --- .../PowerShellEditorServices.Test.csproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj b/test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj index fce802137..956dc796e 100644 --- a/test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj +++ b/test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj @@ -17,12 +17,14 @@ + - + + - +