Skip to content

Commit 43acef4

Browse files
committed
Add BuildIfChanged Task and Dev Instructions
1 parent 7e39f1d commit 43acef4

File tree

2 files changed

+56
-37
lines changed

2 files changed

+56
-37
lines changed

PowerShellEditorServices.build.ps1

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,20 @@ task RestorePsesModules -If (-not (Test-Path "module/PSReadLine") -or -not (Test
125125
}
126126

127127
Task Build FindDotNet, CreateBuildInfo, RestorePsesModules, {
128-
Write-Build DarkGreen "Building PowerShellEditorServices"
128+
Write-Build DarkGreen 'Building PowerShellEditorServices'
129129
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices/PowerShellEditorServices.csproj -f $script:NetFramework.Standard }
130130
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS74 }
131131

132132
if (-not $script:IsNix) {
133133
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS51 }
134134
}
135+
} -If {
136+
$Null -eq $script:ChangesDetected -or $true -eq $script:ChangesDetected
135137
}
136138

137139
Task AssembleModule -After Build {
138-
Write-Build DarkGreen "Assembling PowerShellEditorServices module"
139-
$psesOutputPath = "./module/PowerShellEditorServices"
140+
Write-Build DarkGreen 'Assembling PowerShellEditorServices module'
141+
$psesOutputPath = './module/PowerShellEditorServices'
140142
$psesBinOutputPath = "$psesOutputPath/bin"
141143
$psesDepsPath = "$psesBinOutputPath/Common"
142144
$psesCoreHostPath = "$psesBinOutputPath/Core"
@@ -147,8 +149,8 @@ Task AssembleModule -After Build {
147149
}
148150

149151
# Copy documents to module root
150-
foreach ($document in @("LICENSE", "NOTICE.txt", "README.md", "SECURITY.md")) {
151-
Copy-Item -Force -Path $document -Destination "./module"
152+
foreach ($document in @('LICENSE', 'NOTICE.txt', 'README.md', 'SECURITY.md')) {
153+
Copy-Item -Force -Path $document -Destination './module'
152154
}
153155

154156
# Assemble PSES module
@@ -186,13 +188,13 @@ Task AssembleModule -After Build {
186188
}
187189

188190
Task BuildCmdletHelp -After AssembleModule {
189-
Write-Build DarkGreen "Building cmdlet help"
191+
Write-Build DarkGreen 'Building cmdlet help'
190192
New-ExternalHelp -Path ./module/docs -OutputPath ./module/PowerShellEditorServices/Commands/en-US -Force
191193
}
192194

193195
Task SetupHelpForTests {
194-
Write-Build DarkMagenta "Updating help (for tests)"
195-
Update-Help -Module Microsoft.PowerShell.Management,Microsoft.PowerShell.Utility -Force -Scope CurrentUser -UICulture en-US
196+
Write-Build DarkMagenta 'Updating help (for tests)'
197+
Update-Help -Module Microsoft.PowerShell.Management, Microsoft.PowerShell.Utility -Force -Scope CurrentUser -UICulture en-US
196198
}
197199

198200
Task TestPS74 Build, SetupHelpForTests, {
@@ -210,7 +212,7 @@ Task TestPS51 -If (-not $script:IsNix) Build, SetupHelpForTests, {
210212
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
211213
# Inheriting the module path for powershell.exe breaks things!
212214
$originalModulePath = $env:PSModulePath
213-
$env:PSModulePath = ""
215+
$env:PSModulePath = ''
214216
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS51 }
215217
} finally {
216218
$env:PSModulePath = $originalModulePath
@@ -221,7 +223,7 @@ Task TestPS51 -If (-not $script:IsNix) Build, SetupHelpForTests, {
221223
# should just be the latest supported framework.
222224
Task TestE2EPwsh Build, SetupHelpForTests, {
223225
Set-Location ./test/PowerShellEditorServices.Test.E2E/
224-
$env:PWSH_EXE_NAME = "pwsh"
226+
$env:PWSH_EXE_NAME = 'pwsh'
225227
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
226228
}
227229

@@ -240,12 +242,12 @@ Task TestE2EDaily -If (Test-Path $PwshDaily) Build, SetupHelpForTests, {
240242

241243
Task TestE2EPowerShell -If (-not $script:IsNix) Build, SetupHelpForTests, {
242244
Set-Location ./test/PowerShellEditorServices.Test.E2E/
243-
$env:PWSH_EXE_NAME = "powershell"
245+
$env:PWSH_EXE_NAME = 'powershell'
244246
try {
245247
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
246248
# Inheriting the module path for powershell.exe breaks things!
247249
$originalModulePath = $env:PSModulePath
248-
$env:PSModulePath = ""
250+
$env:PSModulePath = ''
249251
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
250252
} finally {
251253
$env:PSModulePath = $originalModulePath
@@ -254,45 +256,62 @@ Task TestE2EPowerShell -If (-not $script:IsNix) Build, SetupHelpForTests, {
254256

255257
Task TestE2EPwshCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
256258
Set-Location ./test/PowerShellEditorServices.Test.E2E/
257-
$env:PWSH_EXE_NAME = "pwsh"
259+
$env:PWSH_EXE_NAME = 'pwsh'
258260

259-
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
260-
Write-Build DarkRed "Skipping Constrained Language Mode tests as they must be ran in an elevated process"
261+
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown('BuiltInAdministratorsSid')) {
262+
Write-Build DarkRed 'Skipping Constrained Language Mode tests as they must be ran in an elevated process'
261263
return
262264
}
263265

264266
try {
265-
Write-Build DarkGreen "Running end-to-end tests in Constrained Language Mode"
266-
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
267+
Write-Build DarkGreen 'Running end-to-end tests in Constrained Language Mode'
268+
[System.Environment]::SetEnvironmentVariable('__PSLockdownPolicy', '0x80000007', [System.EnvironmentVariableTarget]::Machine)
267269
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
268270
} finally {
269-
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
271+
[System.Environment]::SetEnvironmentVariable('__PSLockdownPolicy', $null, [System.EnvironmentVariableTarget]::Machine)
270272
}
271273
}
272274

273275
Task TestE2EPowerShellCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
274276
Set-Location ./test/PowerShellEditorServices.Test.E2E/
275-
$env:PWSH_EXE_NAME = "powershell"
277+
$env:PWSH_EXE_NAME = 'powershell'
276278

277-
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
278-
Write-Build DarkRed "Skipping Constrained Language Mode tests as they must be ran in an elevated process"
279+
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown('BuiltInAdministratorsSid')) {
280+
Write-Build DarkRed 'Skipping Constrained Language Mode tests as they must be ran in an elevated process'
279281
return
280282
}
281283

282284
try {
283-
Write-Build DarkGreen "Running end-to-end tests in Constrained Language Mode"
284-
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
285+
Write-Build DarkGreen 'Running end-to-end tests in Constrained Language Mode'
286+
[System.Environment]::SetEnvironmentVariable('__PSLockdownPolicy', '0x80000007', [System.EnvironmentVariableTarget]::Machine)
285287
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
286288
# Inheriting the module path for powershell.exe breaks things!
287289
$originalModulePath = $env:PSModulePath
288-
$env:PSModulePath = ""
290+
$env:PSModulePath = ''
289291
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
290292
} finally {
291-
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
293+
[System.Environment]::SetEnvironmentVariable('__PSLockdownPolicy', $null, [System.EnvironmentVariableTarget]::Machine)
292294
$env:PSModulePath = $originalModulePath
293295
}
294296
}
295297

298+
Task BuildIfChanged.Init -Before BuildIfChanged {
299+
[bool]$SCRIPT:ChangesDetected = $false
300+
}
301+
302+
Task BuildIfChanged -Inputs {
303+
$slash = [IO.Path]::DirectorySeparatorChar
304+
Get-ChildItem ./src -Filter '*.cs' -Recurse
305+
| Where-Object FullName -NotLike ('*' + $slash + 'obj' + $slash + '*')
306+
| Where-Object FullName -NotLike ('*' + $slash + 'bin' + $slash + '*')
307+
} -Outputs {
308+
'./src/PowerShellEditorServices/bin/Debug/netstandard2.0/Microsoft.PowerShell.EditorServices.dll'
309+
'./src/PowerShellEditorServices.Hosting/bin/Debug/net8.0/Microsoft.PowerShell.EditorServices.Hosting.dll'
310+
} -Jobs {
311+
Write-Build DarkMagenta 'Changes detected, rebuilding'
312+
$SCRIPT:ChangesDetected = $true
313+
}, Build
314+
296315
Task Test TestPS74, TestE2EPwsh, TestPS51, TestE2EPowerShell
297316

298317
Task TestFull Test, TestE2EDaily, TestE2EPwshCLM, TestE2EPowerShellCLM

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Please note that we only consider the following as stable APIs that can be relie
144144

145145
The types of PowerShell Editor Services can change at any moment and should not be linked against in a production environment.
146146

147-
## Development
147+
## Development Environment
148148

149149
> NOTE: The easiest way to manually test changes you've made in PowerShellEditorServices is to follow the [vscode-powershell development doc](https://github.com/PowerShell/vscode-powershell/blob/main/docs/development.md) to get a local build of the VS Code extension to use your local build of PowerShellEditorServices.
150150
@@ -165,31 +165,31 @@ Install-Module InvokeBuild -Scope CurrentUser
165165
Install-Module platyPS -Scope CurrentUser
166166
```
167167

168-
### 4. Delete `NuGet.Config`
168+
### 4. Adjust `Nuget.Config` if necessary
169169

170-
Our NuGet configuration points to a private feed necessary for secure builds,
171-
and it must be committed to the repo as it is.
172-
The easiest way to build without access to that private feed is to delete the file:
170+
Our NuGet configuration uses a secure feed with whitelisted third party dependency packages. If your contribution requires any changes to the included NuGet packages, you must disable this secure feed.
171+
172+
First, run this command to prevent accidentally commiting changes to this file
173173

174174
```powershell
175-
Remove-Item NuGet.Config
175+
git update-index --skip-worktree nuget.config
176176
```
177177

178-
Please be careful not to commit this change in a PR.
178+
Then, either delete the file or remove the `packagesources` section to use nuget.org again. Your PR _will_ fail automated build checks and you _must_ inform us at the top of your PR so the appropriate packages can be added if approved.
179179

180-
Now you're ready to build the code.
181-
You can do so in one of two ways:
180+
## Build PowerShell Editor Services
181+
Now you're ready to build the code. You can do so in one of two ways:
182182

183-
### Building the code from PowerShell
183+
### PowerShell
184184

185185
```powershell
186186
PS C:\path\to\PowerShellEditorServices> Invoke-Build Build
187187
```
188188

189-
### Building the code from Visual Studio Code
189+
### Visual Studio Code
190190

191191
Open the PowerShellEditorServices folder that you cloned locally and press <kbd>Ctrl+Shift+B</kbd>
192-
(or <kbd>Cmd+Shift+B</kbd> on macOS).
192+
(or <kbd>Cmd+Shift+B</kbd> on macOS) which will run the default build task.
193193

194194
## Code of Conduct
195195

0 commit comments

Comments
 (0)