@@ -92,6 +92,11 @@ public struct ClangPrefixInfo: Serializable, Hashable, Encodable, Sendable {
92
92
}
93
93
}
94
94
95
+ public struct ClangResponseFileInfo : SerializableCodable , Sendable {
96
+ var attachmentPath : Path
97
+ var format : ResponseFileFormat
98
+ }
99
+
95
100
/// The minimal data we need to serialize to reconstruct `ClangSourceFileIndexingInfo` from `generateIndexingInfo`
96
101
public struct ClangIndexingPayload : Serializable , Encodable , Sendable {
97
102
let sourceFileIndex : Int
@@ -102,7 +107,7 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
102
107
let workingDir : Path
103
108
let prefixInfo : ClangPrefixInfo ?
104
109
public let toolchains : [ String ]
105
- let responseFileAttachmentPaths : [ Path : Path ]
110
+ let responseFileAttachmentPaths : [ Path : ClangResponseFileInfo ]
106
111
107
112
init ( sourceFileIndex: Int ,
108
113
outputFileIndex: Int ,
@@ -112,7 +117,7 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
112
117
workingDir: Path ,
113
118
prefixInfo: ClangPrefixInfo ? ,
114
119
toolchains: [ String ] ,
115
- responseFileAttachmentPaths: [ Path : Path ] ) {
120
+ responseFileAttachmentPaths: [ Path : ClangResponseFileInfo ] ) {
116
121
self . sourceFileIndex = sourceFileIndex
117
122
self . outputFileIndex = outputFileIndex
118
123
self . sourceLanguageIndex = sourceLanguageIndex
@@ -202,7 +207,7 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
202
207
static let skippedArgsWithoutValues = Set < ByteString > ( [ " -M " , " -MD " , " -MMD " , " -MG " , " -MJ " , " -MM " , " -MP " , " -MV " , " -fmodules-validate-once-per-build-session " ] )
203
208
static let skippedArgsWithValues = Set < ByteString > ( [ " -MT " , " -MF " , " -MQ " , " --serialize-diagnostics " ] )
204
209
205
- public static func indexingCommandLine( from commandLine: [ ByteString ] , workingDir: Path , prefixInfo: ClangPrefixInfo ? = nil , addSupplementary: Bool = true , replaceCompile: Bool = true , responseFileMapping: [ Path : Path ] ) -> [ ByteString ] {
210
+ public static func indexingCommandLine( from commandLine: [ ByteString ] , workingDir: Path , prefixInfo: ClangPrefixInfo ? = nil , addSupplementary: Bool = true , replaceCompile: Bool = true , responseFileMapping: [ Path : ClangResponseFileInfo ] ) -> [ ByteString ] {
206
211
var result = [ ByteString] ( )
207
212
var iterator = commandLine. makeIterator ( )
208
213
let _ = iterator. next ( ) // Skip compiler path
@@ -234,8 +239,8 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
234
239
} else if arg. bytes. starts ( with: ByteString ( stringLiteral: " -fbuild-session-file= " ) . bytes) {
235
240
// Skip
236
241
} else if arg. starts ( with: ByteString ( unicodeScalarLiteral: " @ " ) ) ,
237
- let attachmentPath = responseFileMapping [ Path ( arg. asString. dropFirst ( ) ) ] ,
238
- let responseFileArgs = try ? ResponseFiles . expandResponseFiles ( [ " @ \( attachmentPath. str) " ] , fileSystem: localFS, relativeTo: workingDir, format: . unixShellQuotedSpaceSeparated ) {
242
+ let attachment = responseFileMapping [ Path ( arg. asString. dropFirst ( ) ) ] ,
243
+ let responseFileArgs = try ? ResponseFiles . expandResponseFiles ( [ " @ \( attachment . attachmentPath. str) " ] , fileSystem: localFS, relativeTo: workingDir, format: attachment . format ) {
239
244
result. append ( contentsOf: responseFileArgs. map { ByteString ( encodingAsUTF8: $0) } )
240
245
} else {
241
246
result. append ( arg)
@@ -568,7 +573,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
568
573
let inputs : [ Path ]
569
574
570
575
/// Maps response files in `flags` to the corresponding recorded attachment in the build description.
571
- let responseFileMapping : [ Path : Path ]
576
+ let responseFileMapping : [ Path : ClangResponseFileInfo ]
572
577
573
578
}
574
579
@@ -719,9 +724,10 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
719
724
ctx. add ( string: self . identifier)
720
725
721
726
let responseFilePath = scope. evaluate ( BuiltinMacros . PER_ARCH_OBJECT_FILE_DIR) . join ( " \( ctx. signature. asString) -common-args.resp " )
722
- let attachmentPath = producer. writeFileSpec. constructFileTasks ( CommandBuildContext ( producer: producer, scope: scope, inputs: [ ] , output: responseFilePath) , delegate, contents: ByteString ( encodingAsUTF8: ResponseFiles . responseFileContents ( args: responseFileCommandLine, format: . unixShellQuotedSpaceSeparated) ) , permissions: nil , logContents: true , preparesForIndexing: true , additionalTaskOrderingOptions: [ . immediate, . ignorePhaseOrdering] )
727
+ let responseFileFormat = scope. evaluate ( BuiltinMacros . HOST_RESPONSE_FILE_FORMAT)
728
+ let attachmentPath = producer. writeFileSpec. constructFileTasks ( CommandBuildContext ( producer: producer, scope: scope, inputs: [ ] , output: responseFilePath) , delegate, contents: ByteString ( encodingAsUTF8: ResponseFiles . responseFileContents ( args: responseFileCommandLine, format: responseFileFormat) ) , permissions: nil , logContents: true , preparesForIndexing: true , additionalTaskOrderingOptions: [ . immediate, . ignorePhaseOrdering] )
723
729
724
- return ConstantFlags ( flags: regularCommandLine + [ " @ \( responseFilePath. str) " ] , headerSearchPaths: headerSearchPaths, inputs: [ responseFilePath] , responseFileMapping: [ responseFilePath: attachmentPath] )
730
+ return ConstantFlags ( flags: regularCommandLine + [ " @ \( responseFilePath. str) " ] , headerSearchPaths: headerSearchPaths, inputs: [ responseFilePath] , responseFileMapping: [ responseFilePath: . init ( attachmentPath: attachmentPath , format : responseFileFormat ) ] )
725
731
} else {
726
732
return ConstantFlags ( flags: commandLine, headerSearchPaths: headerSearchPaths, inputs: [ ] , responseFileMapping: [ : ] )
727
733
}
0 commit comments