Skip to content

Commit 4ce9d95

Browse files
committed
Fixes from reviews
1 parent 6f106a5 commit 4ce9d95

3 files changed

Lines changed: 30 additions & 18 deletions

File tree

Build/Agent/FwBuildHelpers.psm1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,16 @@ function Enter-WorktreeLock {
229229
}
230230
}
231231
catch {
232-
if (-not $hasHandle -and $mutex) {
232+
if ($mutex) {
233+
if ($hasHandle) {
234+
try {
235+
$mutex.ReleaseMutex()
236+
}
237+
catch {
238+
# Ignore release failures on the error path.
239+
}
240+
}
241+
233242
$mutex.Dispose()
234243
}
235244
throw

build.ps1

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,11 @@ if (-not (Test-Path $helpersPath)) {
229229
}
230230
Import-Module $helpersPath -Force
231231

232-
$worktreeLock = Enter-WorktreeLock -RepoRoot $PSScriptRoot -Context "FieldWorks build" -StartedBy $StartedBy
233-
234-
# Worktree-aware cleanup: only stop conflicting processes related to this repo root.
235-
Stop-ConflictingProcesses -IncludeOmniSharp -RepoRoot $PSScriptRoot
236-
237-
$fwTasksSourcePath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
238-
$fwTasksDropPath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
239-
240232
# =============================================================================
241233
# Environment Setup
242234
# =============================================================================
243235

236+
$worktreeLock = $null
244237
$cleanupArgs = @{
245238
IncludeOmniSharp = $true
246239
RepoRoot = $PSScriptRoot
@@ -310,6 +303,14 @@ function Get-BuildStampPath {
310303
}
311304

312305
try {
306+
$worktreeLock = Enter-WorktreeLock -RepoRoot $PSScriptRoot -Context "FieldWorks build" -StartedBy $StartedBy
307+
308+
# Worktree-aware cleanup: only stop conflicting processes related to this repo root.
309+
Stop-ConflictingProcesses -IncludeOmniSharp -RepoRoot $PSScriptRoot
310+
311+
$fwTasksSourcePath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
312+
$fwTasksDropPath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
313+
313314
Invoke-WithFileLockRetry -Context "FieldWorks build" -IncludeOmniSharp -RepoRoot $PSScriptRoot -Action {
314315
# Initialize Visual Studio Developer environment
315316
Initialize-VsDevEnvironment
@@ -635,7 +636,9 @@ try {
635636
finally {
636637
# Kill any lingering build processes that might hold file locks
637638
Stop-ConflictingProcesses @cleanupArgs
638-
Exit-WorktreeLock -LockHandle $worktreeLock
639+
if ($worktreeLock) {
640+
Exit-WorktreeLock -LockHandle $worktreeLock
641+
}
639642
}
640643

641644
if ($testExitCode -ne 0) {

test.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,11 @@ if (-not (Test-Path $helpersPath)) {
8989
}
9090
Import-Module $helpersPath -Force
9191

92-
$worktreeLock = $null
93-
if (-not $SkipWorktreeLock) {
94-
$worktreeLock = Enter-WorktreeLock -RepoRoot $PSScriptRoot -Context "FieldWorks test run" -StartedBy $StartedBy
95-
}
96-
97-
# Worktree-aware cleanup: only stop conflicting processes related to this repo root.
98-
Stop-ConflictingProcesses -IncludeOmniSharp -RepoRoot $PSScriptRoot
99-
10092
# =============================================================================
10193
# Environment Setup
10294
# =============================================================================
10395

96+
$worktreeLock = $null
10497
$cleanupArgs = @{
10598
IncludeOmniSharp = $true
10699
RepoRoot = $PSScriptRoot
@@ -109,6 +102,13 @@ $cleanupArgs = @{
109102
$testExitCode = 0
110103

111104
try {
105+
if (-not $SkipWorktreeLock) {
106+
$worktreeLock = Enter-WorktreeLock -RepoRoot $PSScriptRoot -Context "FieldWorks test run" -StartedBy $StartedBy
107+
}
108+
109+
# Worktree-aware cleanup: only stop conflicting processes related to this repo root.
110+
Stop-ConflictingProcesses -IncludeOmniSharp -RepoRoot $PSScriptRoot
111+
112112
Invoke-WithFileLockRetry -Context "FieldWorks test run" -IncludeOmniSharp -RepoRoot $PSScriptRoot -Action {
113113
# Initialize VS environment
114114
Initialize-VsDevEnvironment

0 commit comments

Comments
 (0)