Skip to content

Commit 7681b09

Browse files
committed
Fixes from reviews
1 parent f14a7c6 commit 7681b09

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
@@ -224,7 +224,16 @@ function Enter-WorktreeLock {
224224
}
225225
}
226226
catch {
227-
if (-not $hasHandle -and $mutex) {
227+
if ($mutex) {
228+
if ($hasHandle) {
229+
try {
230+
$mutex.ReleaseMutex()
231+
}
232+
catch {
233+
# Ignore release failures on the error path.
234+
}
235+
}
236+
228237
$mutex.Dispose()
229238
}
230239
throw

build.ps1

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

207-
$worktreeLock = Enter-WorktreeLock -RepoRoot $PSScriptRoot -Context "FieldWorks build" -StartedBy $StartedBy
208-
209-
# Worktree-aware cleanup: only stop conflicting processes related to this repo root.
210-
Stop-ConflictingProcesses -IncludeOmniSharp -RepoRoot $PSScriptRoot
211-
212-
$fwTasksSourcePath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
213-
$fwTasksDropPath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
214-
215207
# =============================================================================
216208
# Environment Setup
217209
# =============================================================================
218210

211+
$worktreeLock = $null
219212
$cleanupArgs = @{
220213
IncludeOmniSharp = $true
221214
RepoRoot = $PSScriptRoot
@@ -285,6 +278,14 @@ function Get-BuildStampPath {
285278
}
286279

287280
try {
281+
$worktreeLock = Enter-WorktreeLock -RepoRoot $PSScriptRoot -Context "FieldWorks build" -StartedBy $StartedBy
282+
283+
# Worktree-aware cleanup: only stop conflicting processes related to this repo root.
284+
Stop-ConflictingProcesses -IncludeOmniSharp -RepoRoot $PSScriptRoot
285+
286+
$fwTasksSourcePath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
287+
$fwTasksDropPath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
288+
288289
Invoke-WithFileLockRetry -Context "FieldWorks build" -IncludeOmniSharp -RepoRoot $PSScriptRoot -Action {
289290
# Initialize Visual Studio Developer environment
290291
Initialize-VsDevEnvironment
@@ -561,7 +562,9 @@ try {
561562
finally {
562563
# Kill any lingering build processes that might hold file locks
563564
Stop-ConflictingProcesses @cleanupArgs
564-
Exit-WorktreeLock -LockHandle $worktreeLock
565+
if ($worktreeLock) {
566+
Exit-WorktreeLock -LockHandle $worktreeLock
567+
}
565568
}
566569

567570
if ($testExitCode -ne 0) {

test.ps1

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

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

95+
$worktreeLock = $null
10396
$cleanupArgs = @{
10497
IncludeOmniSharp = $true
10598
RepoRoot = $PSScriptRoot
@@ -108,6 +101,13 @@ $cleanupArgs = @{
108101
$testExitCode = 0
109102

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

0 commit comments

Comments
 (0)