@@ -80,6 +80,8 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
8080 public let outputs : [ Path ]
8181 /// The command line to execute for this job
8282 public let commandLine : [ SWBUtil . ByteString ]
83+ /// The signature uniquely identifying the command line, looking through any indirection through response files.
84+ public let commandLineSignature : SWBUtil . ByteString
8385 /// Cache keys for the swift-frontend invocation (one key per output producing input)
8486 public let cacheKeys : [ String ]
8587
@@ -91,27 +93,43 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
9193 self . displayInputs = try job. displayInputs. map { try Path ( resolver. resolve ( . path( $0. file) ) ) }
9294 self . outputs = try job. outputs. map { try Path ( resolver. resolve ( . path( $0. file) ) ) }
9395 self . descriptionForLifecycle = job. descriptionForLifecycle
94- if categorizer. isExplicitDependencyBuild {
95- self . commandLine = try explicitModulesResolver. resolveArgumentList ( for: job, useResponseFiles: . heuristic) . map { ByteString ( encodingAsUTF8: $0) }
96- self . kind = . explicitModule( uniqueID: commandLine. hashValue)
97- } else {
98- self . commandLine = try resolver. resolveArgumentList ( for: job, useResponseFiles: . heuristic) . map { ByteString ( encodingAsUTF8: $0) }
99- self . kind = . target
96+ let chosenResolver = categorizer. isExplicitDependencyBuild ? explicitModulesResolver : resolver
97+ let args : ResolvedCommandLine = try chosenResolver. resolveArgumentList ( for: job, useResponseFiles: . heuristic)
98+ switch args {
99+ case . plain( let args) :
100+ self . commandLine = args. map { ByteString ( encodingAsUTF8: $0) }
101+ let ctx = InsecureHashContext ( )
102+ for arg in args {
103+ ctx. add ( string: arg)
104+ }
105+ self . commandLineSignature = ctx. signature
106+ self . kind = categorizer. isExplicitDependencyBuild ? . explicitModule( uniqueID: args. hashValue) : . target
107+ case . usingResponseFile( resolved: let args, responseFileContents: let responseFileContents) :
108+ // When using a response file, jobs should be uniqued based on the contents of the response file
109+ self . commandLine = args. map { ByteString ( encodingAsUTF8: $0) }
110+ let ctx = InsecureHashContext ( )
111+ for arg in responseFileContents {
112+ ctx. add ( string: arg)
113+ }
114+ self . commandLineSignature = ctx. signature
115+ self . kind = categorizer. isExplicitDependencyBuild ? . explicitModule( uniqueID: responseFileContents. hashValue) : . target
100116 }
117+
101118 self . cacheKeys = job. outputCacheKeys. reduce ( into: [ String] ( ) ) { result, key in
102119 result. append ( key. value)
103120 } . sorted ( )
104121 }
105122
106123 public func serialize< T> ( to serializer: T ) where T : Serializer {
107- serializer. serializeAggregate ( 9 ) {
124+ serializer. serializeAggregate ( 10 ) {
108125 serializer. serialize ( kind)
109126 serializer. serialize ( ruleInfoType)
110127 serializer. serialize ( moduleName)
111128 serializer. serialize ( inputs)
112129 serializer. serialize ( displayInputs)
113130 serializer. serialize ( outputs)
114131 serializer. serialize ( commandLine)
132+ serializer. serialize ( commandLineSignature)
115133 serializer. serialize ( descriptionForLifecycle)
116134 serializer. serialize ( cacheKeys)
117135 }
@@ -126,6 +144,7 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
126144 try self . displayInputs = deserializer. deserialize ( )
127145 try self . outputs = deserializer. deserialize ( )
128146 try self . commandLine = deserializer. deserialize ( )
147+ try self . commandLineSignature = deserializer. deserialize ( )
129148 try self . descriptionForLifecycle = deserializer. deserialize ( )
130149 try self . cacheKeys = deserializer. deserialize ( )
131150 }
@@ -173,9 +192,7 @@ extension LibSwiftDriver {
173192 self . dependencies = dependencies
174193 self . workingDirectory = workingDirectory
175194 let md5 = InsecureHashContext ( )
176- for arg in driverJob. commandLine {
177- md5. add ( bytes: arg)
178- }
195+ md5. add ( bytes: driverJob. commandLineSignature)
179196 md5. add ( string: workingDirectory. str)
180197 md5. add ( number: dependencies. hashValue)
181198 self . signature = md5. signature
0 commit comments