@@ -80,6 +80,8 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
80
80
public let outputs : [ Path ]
81
81
/// The command line to execute for this job
82
82
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
83
85
/// Cache keys for the swift-frontend invocation (one key per output producing input)
84
86
public let cacheKeys : [ String ]
85
87
@@ -91,27 +93,43 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
91
93
self . displayInputs = try job. displayInputs. map { try Path ( resolver. resolve ( . path( $0. file) ) ) }
92
94
self . outputs = try job. outputs. map { try Path ( resolver. resolve ( . path( $0. file) ) ) }
93
95
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
100
116
}
117
+
101
118
self . cacheKeys = job. outputCacheKeys. reduce ( into: [ String] ( ) ) { result, key in
102
119
result. append ( key. value)
103
120
} . sorted ( )
104
121
}
105
122
106
123
public func serialize< T> ( to serializer: T ) where T : Serializer {
107
- serializer. serializeAggregate ( 9 ) {
124
+ serializer. serializeAggregate ( 10 ) {
108
125
serializer. serialize ( kind)
109
126
serializer. serialize ( ruleInfoType)
110
127
serializer. serialize ( moduleName)
111
128
serializer. serialize ( inputs)
112
129
serializer. serialize ( displayInputs)
113
130
serializer. serialize ( outputs)
114
131
serializer. serialize ( commandLine)
132
+ serializer. serialize ( commandLineSignature)
115
133
serializer. serialize ( descriptionForLifecycle)
116
134
serializer. serialize ( cacheKeys)
117
135
}
@@ -126,6 +144,7 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
126
144
try self . displayInputs = deserializer. deserialize ( )
127
145
try self . outputs = deserializer. deserialize ( )
128
146
try self . commandLine = deserializer. deserialize ( )
147
+ try self . commandLineSignature = deserializer. deserialize ( )
129
148
try self . descriptionForLifecycle = deserializer. deserialize ( )
130
149
try self . cacheKeys = deserializer. deserialize ( )
131
150
}
@@ -173,9 +192,7 @@ extension LibSwiftDriver {
173
192
self . dependencies = dependencies
174
193
self . workingDirectory = workingDirectory
175
194
let md5 = InsecureHashContext ( )
176
- for arg in driverJob. commandLine {
177
- md5. add ( bytes: arg)
178
- }
195
+ md5. add ( bytes: driverJob. commandLineSignature)
179
196
md5. add ( string: workingDirectory. str)
180
197
md5. add ( number: dependencies. hashValue)
181
198
self . signature = md5. signature
0 commit comments