@@ -102,6 +102,16 @@ public protocol SwiftCommand: ParsableCommand, _SwiftCommand {
102
102
extension SwiftCommand {
103
103
public static var _errorLabel : String { " error " }
104
104
105
+ private func acquireScratchDirectoryLockIfNeeded< T> ( swiftTool: SwiftTool , blocking: Bool = true , _ body: ( ) throws -> T ) throws {
106
+ let interactive = isatty ( STDOUT_FILENO) == 1
107
+ _ = try swiftTool. fileSystem. withLock (
108
+ on: swiftTool. scratchDirectory,
109
+ type: . exclusive,
110
+ blocking: interactive ? blocking : false ,
111
+ body
112
+ )
113
+ }
114
+
105
115
public func run( ) throws {
106
116
let swiftTool = try SwiftTool (
107
117
options: globalOptions,
@@ -113,7 +123,7 @@ extension SwiftCommand {
113
123
114
124
// Try a non-blocking lock first so that we can inform the user about an already running SwiftPM.
115
125
do {
116
- try swiftTool . fileSystem . withLock ( on : swiftTool. scratchDirectory , type : . exclusive , blocking: false ) { }
126
+ try acquireScratchDirectoryLockIfNeeded ( swiftTool: swiftTool , blocking: false ) { }
117
127
} catch let ProcessLockError . unableToAquireLock( errno) {
118
128
if errno == EWOULDBLOCK {
119
129
swiftTool. outputStream. write ( " Another instance of SwiftPM is already running using ' \( swiftTool. scratchDirectory) ', waiting until that process has finished execution... " . utf8)
@@ -122,7 +132,7 @@ extension SwiftCommand {
122
132
}
123
133
124
134
var toolError : Error ? = . none
125
- try swiftTool . fileSystem . withLock ( on : swiftTool. scratchDirectory , type : . exclusive ) {
135
+ try acquireScratchDirectoryLockIfNeeded ( swiftTool: swiftTool ) {
126
136
do {
127
137
try self . run ( swiftTool)
128
138
if swiftTool. observabilityScope. errorsReported || swiftTool. executionStatus == . failure {
0 commit comments