Skip to content

Commit c3f6aa1

Browse files
committed
utils: surface failures from -Clean
`Remove-Item -ErrorAction Ignore` silently swallows failures, which on Windows happens whenever any file in the target tree is held by another process (an in-flight build, an editor, virus scanning, etc.). The result is a partially-deleted build directory: subsequent `ninja` runs then treat the stale survivors as up-to-date, so a header API change produces objects that link against a signature no longer present in their dependent libraries. Wrap each removal in a small helper that: - skips paths that do not exist (so a first-time clean is not an error), - runs `Remove-Item` with `-ErrorAction Stop`, and - on failure throws a clear message naming the path and the likely cause. Also correct the parameter docstring; the previous text described a behavior that has not matched the implementation in some time.
1 parent b13e875 commit c3f6aa1

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

utils/build.ps1

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ An array of architectures for which the Windows Swift SDK should be built.
9595
Default: @("X64","X86","ARM64")
9696
9797
.PARAMETER Clean
98-
Clean non-compiler builds while building. Use this for a fresh build when
99-
experiencing issues.
98+
Wipe the per-triple build directories under `$BinaryCache` (host and target
99+
SDK builds, including all compiler stages) and the host install directory
100+
before building. Downloaded dependencies are preserved. Builds for
101+
platforms not selected by the current invocation are not removed.
100102
101103
.PARAMETER SkipBuild
102104
Skip the build phase entirely. Useful for testing packaging or other post-build
@@ -4828,21 +4830,35 @@ try {
48284830
Get-Dependencies
48294831

48304832
if ($Clean) {
4831-
Remove-Item -Force -Recurse -Path "$BinaryCache\$($BuildPlatform.Triple)\" -ErrorAction Ignore
4832-
Remove-Item -Force -Recurse -Path "$BinaryCache\$($HostPlatform.Triple)\" -ErrorAction Ignore
4833+
# Recursively delete a build directory, failing loudly if the tree cannot
4834+
# be fully removed. `Remove-Item -ErrorAction Ignore` silently leaves
4835+
# locked-file siblings behind, producing a partially-cleaned tree where
4836+
# ninja then treats stale objects as up-to-date. Surface the failure
4837+
# so the caller can close the offending process and retry.
4838+
function Clean-Path([string] $Path) {
4839+
if (-not (Test-Path -LiteralPath $Path)) { return }
4840+
try {
4841+
Remove-Item -Force -Recurse -LiteralPath $Path -ErrorAction Stop
4842+
} catch {
4843+
throw "Failed to clean '$Path'; a file is likely locked by a running process (build, editor, or virus scanner). Close it and retry. Inner error: $_"
4844+
}
4845+
}
4846+
4847+
Clean-Path "$BinaryCache\$($BuildPlatform.Triple)"
4848+
Clean-Path "$BinaryCache\$($HostPlatform.Triple)"
48334849
foreach ($Build in $WindowsSDKBuilds) {
4834-
Remove-Item -Force -Recurse -Path "$BinaryCache\$($Build.Triple)\" -ErrorAction Ignore
4850+
Clean-Path "$BinaryCache\$($Build.Triple)"
48354851
}
48364852
foreach ($Build in $AndroidSDKBuilds) {
4837-
Remove-Item -Force -Recurse -Path "$BinaryCache\$($Build.Triple)\" -ErrorAction Ignore
4853+
Clean-Path "$BinaryCache\$($Build.Triple)"
48384854
}
4839-
Remove-Item -Force -Recurse -Path "$BinaryCache\1" -ErrorAction Ignore
4840-
Remove-Item -Force -Recurse -Path "$BinaryCache\5" -ErrorAction Ignore
4841-
Remove-Item -Force -Recurse -Path (Get-InstallDir $HostPlatform) -ErrorAction Ignore
4855+
Clean-Path "$BinaryCache\1"
4856+
Clean-Path "$BinaryCache\5"
4857+
Clean-Path (Get-InstallDir $HostPlatform)
48424858

48434859
Get-SelectedSDKBuilds | ForEach-Object {
4844-
Remove-Item -Force -Recurse -Path (Get-ProjectBinaryCache $_ ClangBuiltins) -ErrorAction Ignore
4845-
Remove-Item -Force -Recurse -Path (Get-ProjectBinaryCache $_ ClangRuntime) -ErrorAction Ignore
4860+
Clean-Path (Get-ProjectBinaryCache $_ ClangBuiltins)
4861+
Clean-Path (Get-ProjectBinaryCache $_ ClangRuntime)
48464862
}
48474863
}
48484864

0 commit comments

Comments
 (0)