@@ -92,6 +92,11 @@ public struct ClangPrefixInfo: Serializable, Hashable, Encodable, Sendable {
9292 }
9393}
9494
95+ public struct ClangResponseFileInfo : SerializableCodable , Sendable {
96+ var attachmentPath : Path
97+ var format : ResponseFileFormat
98+ }
99+
95100/// The minimal data we need to serialize to reconstruct `ClangSourceFileIndexingInfo` from `generateIndexingInfo`
96101public struct ClangIndexingPayload : Serializable , Encodable , Sendable {
97102 let sourceFileIndex : Int
@@ -102,7 +107,7 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
102107 let workingDir : Path
103108 let prefixInfo : ClangPrefixInfo ?
104109 public let toolchains : [ String ]
105- let responseFileAttachmentPaths : [ Path : Path ]
110+ let responseFileAttachmentPaths : [ Path : ClangResponseFileInfo ]
106111
107112 init ( sourceFileIndex: Int ,
108113 outputFileIndex: Int ,
@@ -112,7 +117,7 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
112117 workingDir: Path ,
113118 prefixInfo: ClangPrefixInfo ? ,
114119 toolchains: [ String ] ,
115- responseFileAttachmentPaths: [ Path : Path ] ) {
120+ responseFileAttachmentPaths: [ Path : ClangResponseFileInfo ] ) {
116121 self . sourceFileIndex = sourceFileIndex
117122 self . outputFileIndex = outputFileIndex
118123 self . sourceLanguageIndex = sourceLanguageIndex
@@ -202,7 +207,7 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
202207 static let skippedArgsWithoutValues = Set < ByteString > ( [ " -M " , " -MD " , " -MMD " , " -MG " , " -MJ " , " -MM " , " -MP " , " -MV " , " -fmodules-validate-once-per-build-session " ] )
203208 static let skippedArgsWithValues = Set < ByteString > ( [ " -MT " , " -MF " , " -MQ " , " --serialize-diagnostics " ] )
204209
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 ] {
206211 var result = [ ByteString] ( )
207212 var iterator = commandLine. makeIterator ( )
208213 let _ = iterator. next ( ) // Skip compiler path
@@ -234,8 +239,8 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
234239 } else if arg. bytes. starts ( with: ByteString ( stringLiteral: " -fbuild-session-file= " ) . bytes) {
235240 // Skip
236241 } 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 ) {
239244 result. append ( contentsOf: responseFileArgs. map { ByteString ( encodingAsUTF8: $0) } )
240245 } else {
241246 result. append ( arg)
@@ -568,7 +573,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
568573 let inputs : [ Path ]
569574
570575 /// Maps response files in `flags` to the corresponding recorded attachment in the build description.
571- let responseFileMapping : [ Path : Path ]
576+ let responseFileMapping : [ Path : ClangResponseFileInfo ]
572577
573578 }
574579
@@ -719,9 +724,10 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
719724 ctx. add ( string: self . identifier)
720725
721726 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] )
723729
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 ) ] )
725731 } else {
726732 return ConstantFlags ( flags: commandLine, headerSearchPaths: headerSearchPaths, inputs: [ ] , responseFileMapping: [ : ] )
727733 }
0 commit comments