Skip to content

Commit 26f100e

Browse files
authored
Merge pull request #1639 from owenv/pr/ovoorhees/6-response-file-hashing
[6.0] Response files should be named using the hash of the command line arguments only
2 parents fec9216 + f45f324 commit 26f100e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Sources/SwiftDriver/Execution/ArgsResolver.swift

Lines changed: 3 additions & 1 deletion
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.SHA256
1819

1920
@_implementationOnly import Yams
2021

@@ -208,7 +209,8 @@ public final class ArgsResolver {
208209
assert(!forceResponseFiles || job.supportsResponseFiles,
209210
"Platform does not support response files for job: \(job)")
210211
// Match the integrated driver's behavior, which uses response file names of the form "arguments-[0-9a-zA-Z].resp".
211-
let responseFilePath = temporaryDirectory.appending(component: "arguments-\(abs(job.hashValue)).resp")
212+
let hash = SHA256().hash(resolvedArguments.joined(separator: " ")).hexadecimalRepresentation
213+
let responseFilePath = temporaryDirectory.appending(component: "arguments-\(hash).resp")
212214

213215
// FIXME: Need a way to support this for distributed build systems...
214216
if let absPath = responseFilePath.absolutePath {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,27 @@ final class SwiftDriverTests: XCTestCase {
17041704
XCTAssertFalse(resolvedArgs.contains { $0.hasPrefix("@") })
17051705
}
17061706
}
1707+
1708+
func testResponseFileDeterministicNaming() throws {
1709+
#if !os(macOS)
1710+
throw XCTSkip("Test assumes macOS response file quoting behavior")
1711+
#endif
1712+
do {
1713+
let testJob = Job(moduleName: "Foo",
1714+
kind: .compile,
1715+
tool: .init(path: try AbsolutePath(validating: "/swiftc"), supportsResponseFiles: true),
1716+
commandLine: (1...20000).map { .flag("-DTEST_\($0)") },
1717+
inputs: [],
1718+
primaryInputs: [],
1719+
outputs: [])
1720+
let resolver = try ArgsResolver(fileSystem: localFileSystem)
1721+
let resolvedArgs: [String] = try resolver.resolveArgumentList(for: testJob)
1722+
XCTAssertTrue(resolvedArgs.count == 3)
1723+
XCTAssertEqual(resolvedArgs[2].first, "@")
1724+
let responseFilePath = try AbsolutePath(validating: String(resolvedArgs[2].dropFirst()))
1725+
XCTAssertEqual(responseFilePath.basename, "arguments-847d15e70d97df7c18033735497ca8dcc4441f461d5a9c2b764b127004524e81.resp")
1726+
}
1727+
}
17071728

17081729
func testSpecificJobsResponseFiles() throws {
17091730
// The jobs below often take large command lines (e.g., when passing a large number of Clang

0 commit comments

Comments
 (0)