File tree 2 files changed +24
-1
lines changed
Sources/SwiftDriver/Execution
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import class Foundation.NSLock
15
15
import func TSCBasic. withTemporaryDirectory
16
16
import protocol TSCBasic. FileSystem
17
17
import struct TSCBasic. AbsolutePath
18
+ import struct TSCBasic. SHA256
18
19
19
20
@_implementationOnly import Yams
20
21
@@ -208,7 +209,8 @@ public final class ArgsResolver {
208
209
assert ( !forceResponseFiles || job. supportsResponseFiles,
209
210
" Platform does not support response files for job: \( job) " )
210
211
// 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 " )
212
214
213
215
// FIXME: Need a way to support this for distributed build systems...
214
216
if let absPath = responseFilePath. absolutePath {
Original file line number Diff line number Diff line change @@ -1712,6 +1712,27 @@ final class SwiftDriverTests: XCTestCase {
1712
1712
XCTAssertFalse ( resolvedArgs. contains { $0. hasPrefix ( " @ " ) } )
1713
1713
}
1714
1714
}
1715
+
1716
+ func testResponseFileDeterministicNaming( ) throws {
1717
+ #if !os(macOS)
1718
+ throw XCTSkip ( " Test assumes macOS response file quoting behavior " )
1719
+ #endif
1720
+ do {
1721
+ let testJob = Job ( moduleName: " Foo " ,
1722
+ kind: . compile,
1723
+ tool: . init( path: try AbsolutePath ( validating: " /swiftc " ) , supportsResponseFiles: true ) ,
1724
+ commandLine: ( 1 ... 20000 ) . map { . flag( " -DTEST_ \( $0) " ) } ,
1725
+ inputs: [ ] ,
1726
+ primaryInputs: [ ] ,
1727
+ outputs: [ ] )
1728
+ let resolver = try ArgsResolver ( fileSystem: localFileSystem)
1729
+ let resolvedArgs : [ String ] = try resolver. resolveArgumentList ( for: testJob)
1730
+ XCTAssertTrue ( resolvedArgs. count == 3 )
1731
+ XCTAssertEqual ( resolvedArgs [ 2 ] . first, " @ " )
1732
+ let responseFilePath = try AbsolutePath ( validating: String ( resolvedArgs [ 2 ] . dropFirst ( ) ) )
1733
+ XCTAssertEqual ( responseFilePath. basename, " arguments-847d15e70d97df7c18033735497ca8dcc4441f461d5a9c2b764b127004524e81.resp " )
1734
+ }
1735
+ }
1715
1736
1716
1737
func testSpecificJobsResponseFiles( ) throws {
1717
1738
// The jobs below often take large command lines (e.g., when passing a large number of Clang
You can’t perform that action at this time.
0 commit comments