Skip to content

Commit 05c313e

Browse files
authored
Change symlink error to warning (#3490)
Motivation: Symlinking oldBuildPath is not a vital step of swift build, but emitting an error will depress the run and test commands. This largely troubled Windows users, since symlinking requires elevated privileges on Windows. Modifications: Codes of linking oldBuildPath is now wrapped with do-catch to capture the error and change it into a warning. Result: If linking oldBuildPath fails, SwiftPM will emit a warning instead of an error.
1 parent 9a52971 commit 05c313e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Sources/Build/BuildOperation.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,18 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
137137
component: buildParameters.configuration.dirname
138138
)
139139
if localFileSystem.exists(oldBuildPath) {
140-
try localFileSystem.removeFileTree(oldBuildPath)
140+
do { try localFileSystem.removeFileTree(oldBuildPath) }
141+
catch {
142+
diagnostics.emit(warning: "unable to delete \(oldBuildPath), skip creating symbolic link: \(error)")
143+
return
144+
}
145+
}
146+
147+
do {
148+
try localFileSystem.createSymbolicLink(oldBuildPath, pointingAt: buildParameters.buildPath, relative: true)
149+
} catch {
150+
diagnostics.emit(warning: "unable to create symbolic link at \(oldBuildPath): \(error)")
141151
}
142-
try localFileSystem.createSymbolicLink(oldBuildPath, pointingAt: buildParameters.buildPath, relative: true)
143152
}
144153

145154
/// Compute the llbuild target name using the given subset.

0 commit comments

Comments
 (0)