Skip to content

Commit 4f235c5

Browse files
committed
Add net8.0 to build script, clean up test tasks and fix PSModulePath bug
We've known inheriting that environment variable breaks stuff, but now it breaks tests too.
1 parent 31e1249 commit 4f235c5

File tree

1 file changed

+77
-30
lines changed

1 file changed

+77
-30
lines changed

PowerShellEditorServices.build.ps1

+77-30
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ $script:IsArm64 = -not $script:IsNix -and @("ARM64") -contains $env:PROCESSOR_AR
4848
$script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Hosting", "BuildInfo.cs")
4949
$script:PsesCommonProps = [xml](Get-Content -Raw "$PSScriptRoot/PowerShellEditorServices.Common.props")
5050

51-
$script:NetRuntime = @{
51+
$script:NetFramework = @{
52+
PS51 = 'net462'
5253
PS72 = 'net6.0'
5354
PS73 = 'net7.0'
54-
Desktop = 'net462'
55+
PS74 = 'net8.0'
5556
Standard = 'netstandard2.0'
5657
}
5758

58-
$script:HostCoreOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.PS72)/publish"
59-
$script:HostDeskOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.Desktop)/publish"
60-
$script:PsesOutput = "$PSScriptRoot/src/PowerShellEditorServices/bin/$Configuration/$($script:NetRuntime.Standard)/publish"
61-
$script:VSCodeOutput = "$PSScriptRoot/src/PowerShellEditorServices.VSCode/bin/$Configuration/$($script:NetRuntime.Standard)/publish"
59+
$script:HostCoreOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetFramework.PS72)/publish"
60+
$script:HostDeskOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetFramework.PS51)/publish"
61+
$script:PsesOutput = "$PSScriptRoot/src/PowerShellEditorServices/bin/$Configuration/$($script:NetFramework.Standard)/publish"
62+
$script:VSCodeOutput = "$PSScriptRoot/src/PowerShellEditorServices.VSCode/bin/$Configuration/$($script:NetFramework.Standard)/publish"
6263

6364
if (Get-Command git -ErrorAction SilentlyContinue) {
6465
# ignore changes to this file
@@ -157,63 +158,105 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
157158
}
158159

159160
Task SetupHelpForTests {
160-
if (-not (Get-Help Microsoft.PowerShell.Management\Get-Process).Description) {
161+
# Checks if the description is filled out (otherwise it just shows the syntax).
162+
if (((Get-Help Microsoft.PowerShell.Management\Get-Process).Description.Text | Select-Object -First 1) -notmatch "cmdlet") {
161163
Write-Host "Updating help for tests."
162164
Update-Help -Module Microsoft.PowerShell.Management,Microsoft.PowerShell.Utility -Force -Scope CurrentUser
163165
}
164166
}
165167

166168
Task Build FindDotNet, CreateBuildInfo, {
167-
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard }
168-
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.PS72 }
169+
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetFramework.Standard }
170+
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS72 }
169171

170172
if (-not $script:IsNix) {
171-
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop }
173+
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS51 }
172174
}
173175

174176
# Build PowerShellEditorServices.VSCode module
175-
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetRuntime.Standard }
177+
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetFramework.Standard }
176178
}
177179

178-
Task Test TestServer, TestE2E, TestConstrainedLanguageMode
180+
# The concise set of tests (for pull requests)
181+
Task Test TestPS74, TestE2EPwsh, TestPS51, TestE2EPowerShell
179182

180-
Task TestServer SetupHelpForTests, TestServerWinPS, TestServerPS72, TestServerPS73
183+
# Every combination of tests (for main branch)
184+
Task TestFull Test, TestPS73, TestPS72, TestE2EPwshCLM, TestE2EPowerShellCLM
181185

182-
Task TestE2E SetupHelpForTests, TestE2EPwsh, TestE2EWinPS
186+
Task TestPS74 Build, SetupHelpForTests, {
187+
Set-Location .\test\PowerShellEditorServices.Test\
188+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
189+
}
183190

184-
Task TestServerWinPS -If (-not $script:IsNix) Build, {
191+
Task TestPS73 Build, SetupHelpForTests, {
185192
Set-Location .\test\PowerShellEditorServices.Test\
186-
# TODO: See https://github.com/dotnet/sdk/issues/18353 for x64 test host
187-
# that is debuggable! If architecture is added, the assembly path gets an
188-
# additional folder, necesstiating fixes to find the commands definition
189-
# file and test files.
190-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.Desktop }
193+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS73 }
191194
}
192195

193-
Task TestServerPS72 Build, {
196+
Task TestPS72 Build, SetupHelpForTests, {
194197
Set-Location .\test\PowerShellEditorServices.Test\
195-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS72 }
198+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS72 }
196199
}
197200

198-
Task TestServerPS73 Build, {
201+
Task TestPS51 -If (-not $script:IsNix) Build, SetupHelpForTests, {
199202
Set-Location .\test\PowerShellEditorServices.Test\
200-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
203+
# TODO: See https://github.com/dotnet/sdk/issues/18353 for x64 test host
204+
# that is debuggable! If architecture is added, the assembly path gets an
205+
# additional folder, necessitating fixes to find the commands definition
206+
# file and test files.
207+
try {
208+
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
209+
# Inheriting the module path for powershell.exe breaks things!
210+
$originalModulePath = $env:PSModulePath
211+
$env:PSModulePath = ""
212+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS51 }
213+
} finally {
214+
$env:PSModulePath = $originalModulePath
215+
}
201216
}
202217

203-
Task TestE2EPwsh Build, {
218+
# NOTE: The framework for the E2E tests applies to the mock client, and so
219+
# should just be the latest supported framework.
220+
Task TestE2EPwsh Build, SetupHelpForTests, {
204221
Set-Location .\test\PowerShellEditorServices.Test.E2E\
205222
$env:PWSH_EXE_NAME = "pwsh"
206-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
223+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
207224
}
208225

209-
Task TestE2EWinPS -If (-not $script:IsNix) Build, {
226+
Task TestE2EPowerShell Build, SetupHelpForTests, {
210227
Set-Location .\test\PowerShellEditorServices.Test.E2E\
211228
$env:PWSH_EXE_NAME = "powershell"
212-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
229+
try {
230+
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
231+
# Inheriting the module path for powershell.exe breaks things!
232+
$originalModulePath = $env:PSModulePath
233+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
234+
} finally {
235+
$env:PSModulePath = $originalModulePath
236+
}
213237
}
214238

215-
Task TestConstrainedLanguageMode -If (-not $script:IsNix) Build, {
239+
Task TestE2EPwshCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
216240
Set-Location .\test\PowerShellEditorServices.Test.E2E\
241+
$env:PWSH_EXE_NAME = "pwsh"
242+
243+
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
244+
Write-Warning "Skipping Constrained Language Mode tests as they must be ran in an elevated process."
245+
return
246+
}
247+
248+
try {
249+
Write-Host "Running end-to-end tests in Constrained Language Mode."
250+
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
251+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
252+
} finally {
253+
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
254+
}
255+
}
256+
257+
Task TestE2EPowerShellCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
258+
Set-Location .\test\PowerShellEditorServices.Test.E2E\
259+
$env:PWSH_EXE_NAME = "powershell"
217260

218261
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
219262
Write-Warning "Skipping Constrained Language Mode tests as they must be ran in an elevated process."
@@ -223,9 +266,13 @@ Task TestConstrainedLanguageMode -If (-not $script:IsNix) Build, {
223266
try {
224267
Write-Host "Running end-to-end tests in Constrained Language Mode."
225268
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
226-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
269+
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
270+
# Inheriting the module path for powershell.exe breaks things!
271+
$originalModulePath = $env:PSModulePath
272+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
227273
} finally {
228274
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
275+
$env:PSModulePath = $originalModulePath
229276
}
230277
}
231278

0 commit comments

Comments
 (0)