Skip to content

Add hidden --ignore-lock escape hatch #7338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/CoreCommands/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public struct LocationOptions: ParsableArguments {
completion: .directory
)
public var pkgConfigDirectories: [AbsolutePath] = []

@Option(name: .customLong("ignore-lock"), help: .hidden)
public var ignoreLock: Bool = false
}

public struct CachingOptions: ParsableArguments {
Expand Down
15 changes: 10 additions & 5 deletions Sources/CoreCommands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -917,11 +917,16 @@ public final class SwiftTool {
try workspaceLock.lock(type: .exclusive, blocking: false)
} catch let ProcessLockError.unableToAquireLock(errno) {
if errno == EWOULDBLOCK {
self.outputStream.write("Another instance of SwiftPM is already running using '\(self.scratchDirectory)', waiting until that process has finished execution...".utf8)
self.outputStream.flush()

// Only if we fail because there's an existing lock we need to acquire again as blocking.
try workspaceLock.lock(type: .exclusive, blocking: true)
if self.options.locations.ignoreLock {
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)
self.outputStream.flush()
} else {
self.outputStream.write("Another instance of SwiftPM is already running using '\(self.scratchDirectory)', waiting until that process has finished execution...".utf8)
self.outputStream.flush()

// Only if we fail because there's an existing lock we need to acquire again as blocking.
try workspaceLock.lock(type: .exclusive, blocking: true)
}
}
}

Expand Down