Skip to content

Commit 396aa30

Browse files
committed
Perform response file write atomically
Switch over to using 'FileSystem.writeFileContents(_ path:, bytes:, atomically:)'. Otherwise we may encounter a race when multiple driver invocations attempt to write a response file for an identical task, such as a shared module dependency pre-compilation job.
1 parent a7f32bd commit 396aa30

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/SwiftDriver/Execution/ArgsResolver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import class Foundation.NSLock
1515
import func TSCBasic.withTemporaryDirectory
1616
import protocol TSCBasic.FileSystem
1717
import struct TSCBasic.AbsolutePath
18+
import struct TSCBasic.ByteString
1819
import struct TSCBasic.SHA256
1920

2021
/// How the resolver is to handle usage of response files
@@ -190,9 +191,8 @@ public final class ArgsResolver {
190191

191192
// FIXME: Need a way to support this for distributed build systems...
192193
if let absPath = responseFilePath.absolutePath {
193-
try fileSystem.writeFileContents(absPath) {
194-
$0.send(resolvedArguments[2...].map { $0.spm_shellEscaped() }.joined(separator: "\n"))
195-
}
194+
let argumentBytes = ByteString(resolvedArguments[2...].map { $0.spm_shellEscaped() }.joined(separator: "\n").utf8)
195+
try fileSystem.writeFileContents(absPath, bytes: argumentBytes, atomically: true)
196196
resolvedArguments = [resolvedArguments[0], resolvedArguments[1], "@\(absPath.pathString)"]
197197
}
198198

0 commit comments

Comments
 (0)