1818
1919# Requires -Modules @ {ModuleName = " InvokeBuild" ;ModuleVersion = " 3.2.1" }
2020
21- $script :IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq " Core" -and ! $IsWindows
21+ $script :IsNix = $IsLinux -or $IsMacOS
22+ $script :IsRosetta = $IsMacOS -and (sysctl - n sysctl.proc_translated) -eq 1 # Mac M1
2223$script :BuildInfoPath = [System.IO.Path ]::Combine($PSScriptRoot , " src" , " PowerShellEditorServices.Hosting" , " BuildInfo.cs" )
2324$script :PsesCommonProps = [xml ](Get-Content - Raw " $PSScriptRoot /PowerShellEditorServices.Common.props" )
2425$script :IsPreview = [bool ]($script :PsesCommonProps.Project.PropertyGroup.VersionSuffix )
@@ -62,7 +63,7 @@ function Install-Dotnet {
6263 Write-Host " Installing .NET channels $Channel " - ForegroundColor Green
6364
6465 # The install script is platform-specific
65- $installScriptExt = if ($script :IsUnix ) { " sh" } else { " ps1" }
66+ $installScriptExt = if ($script :IsNix ) { " sh" } else { " ps1" }
6667 $installScript = " dotnet-install.$installScriptExt "
6768
6869 # Download the official installation script and run it
@@ -74,11 +75,11 @@ function Install-Dotnet {
7475 {
7576 Write-Host " `n ### Installing .NET CLI $Version ...`n "
7677
77- if ($script :IsUnix ) {
78+ if ($script :IsNix ) {
7879 chmod + x $installScriptPath
7980 }
8081
81- $params = if ($script :IsUnix )
82+ $params = if ($script :IsNix )
8283 {
8384 @ (' -Channel' , $dotnetChannel , ' -InstallDir' , $env: DOTNET_INSTALL_DIR , ' -NoPath' , ' -Verbose' )
8485 }
@@ -105,7 +106,7 @@ function Install-Dotnet {
105106task SetupDotNet - Before Clean , Build, TestServerWinPS, TestServerPS7, TestServerPS72, TestE2E {
106107
107108 $dotnetPath = " $PSScriptRoot /.dotnet"
108- $dotnetExePath = if ($script :IsUnix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet.exe" }
109+ $dotnetExePath = if ($script :IsNix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet.exe" }
109110
110111 if (! (Test-Path $dotnetExePath )) {
111112 # TODO: Test .NET 5 with PowerShell 7.1, and add that channel here.
@@ -238,7 +239,7 @@ task SetupHelpForTests {
238239task Build BinClean, {
239240 exec { & $script :dotnetExe publish - c $Configuration .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script :NetRuntime.Standard }
240241 exec { & $script :dotnetExe publish - c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script :NetRuntime.PS7 }
241- if (-not $script :IsUnix )
242+ if (-not $script :IsNix )
242243 {
243244 exec { & $script :dotnetExe publish - c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script :NetRuntime.Desktop }
244245 }
@@ -256,12 +257,12 @@ task Test SetupHelpForTests,TestServer,TestE2E
256257
257258task TestServer TestServerWinPS, TestServerPS7, TestServerPS72
258259
259- task TestServerWinPS - If (-not $script :IsUnix ) {
260+ task TestServerWinPS - If (-not $script :IsNix ) {
260261 Set-Location .\test\PowerShellEditorServices.Test\
261262 exec { & $script :dotnetExe test -- logger trx -f $script :NetRuntime.Desktop (DotNetTestFilter) }
262263}
263264
264- task TestServerPS7 {
265+ task TestServerPS7 - If ( -not $ script :IsRosetta ) {
265266 Set-Location .\test\PowerShellEditorServices.Test\
266267 Invoke-WithCreateDefaultHook - NewModulePath $script :PSCoreModulePath {
267268 exec { & $script :dotnetExe test -- logger trx -f $script :NetRuntime.PS7 (DotNetTestFilter) }
@@ -279,10 +280,11 @@ task TestE2E {
279280 Set-Location .\test\PowerShellEditorServices.Test.E2E\
280281
281282 $env: PWSH_EXE_NAME = if ($IsCoreCLR ) { " pwsh" } else { " powershell" }
282- exec { & $script :dotnetExe test -- logger trx -f $script :NetRuntime.PS7 (DotNetTestFilter) }
283+ $NetRuntime = if ($IsRosetta ) { $script :NetRuntime.PS72 } else { $script :NetRuntime.PS7 }
284+ exec { & $script :dotnetExe test -- logger trx -f $NetRuntime (DotNetTestFilter) }
283285
284286 # Run E2E tests in ConstrainedLanguage mode.
285- if (! $script :IsUnix ) {
287+ if (! $script :IsNix ) {
286288 try {
287289 [System.Environment ]::SetEnvironmentVariable(" __PSLockdownPolicy" , " 0x80000007" , [System.EnvironmentVariableTarget ]::Machine);
288290 exec { & $script :dotnetExe test -- logger trx -f $script :NetRuntime.PS7 (DotNetTestFilter) }
@@ -340,7 +342,7 @@ task LayoutModule -After Build {
340342 }
341343
342344 # PSES/bin/Desktop
343- if (-not $script :IsUnix )
345+ if (-not $script :IsNix )
344346 {
345347 foreach ($hostComponent in Get-ChildItem $script :HostDeskOutput )
346348 {
0 commit comments