Skip to content

Commit 9131d8d

Browse files
authored
Add hidden --ignore-lock escape hatch (#7338)
This is obviously dangerous, but arguably has been the default behavior of SwiftPM for many years, so offering an escape hatch seems appropriate.
1 parent 78f858a commit 9131d8d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Sources/CoreCommands/Options.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ public struct LocationOptions: ParsableArguments {
121121
completion: .directory
122122
)
123123
public var pkgConfigDirectories: [AbsolutePath] = []
124+
125+
@Option(name: .customLong("ignore-lock"), help: .hidden)
126+
public var ignoreLock: Bool = false
124127
}
125128

126129
public struct CachingOptions: ParsableArguments {

Sources/CoreCommands/SwiftTool.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,16 @@ public final class SwiftTool {
913913
try workspaceLock.lock(type: .exclusive, blocking: false)
914914
} catch let ProcessLockError.unableToAquireLock(errno) {
915915
if errno == EWOULDBLOCK {
916-
self.outputStream.write("Another instance of SwiftPM is already running using '\(self.scratchDirectory)', waiting until that process has finished execution...".utf8)
917-
self.outputStream.flush()
918-
919-
// Only if we fail because there's an existing lock we need to acquire again as blocking.
920-
try workspaceLock.lock(type: .exclusive, blocking: true)
916+
if self.options.locations.ignoreLock {
917+
self.outputStream.write("Another instance of SwiftPM is already running using '\(self.scratchDirectory)', but this will be ignored since `--ignore-lock` has been passed".utf8)
918+
self.outputStream.flush()
919+
} else {
920+
self.outputStream.write("Another instance of SwiftPM is already running using '\(self.scratchDirectory)', waiting until that process has finished execution...".utf8)
921+
self.outputStream.flush()
922+
923+
// Only if we fail because there's an existing lock we need to acquire again as blocking.
924+
try workspaceLock.lock(type: .exclusive, blocking: true)
925+
}
921926
}
922927
}
923928

0 commit comments

Comments
 (0)