@@ -103,6 +103,7 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
103103 let prefixInfo : ClangPrefixInfo ?
104104 public let toolchains : [ String ]
105105 let responseFileAttachmentPaths : [ Path : Path ]
106+ let responseFileFormat : ResponseFileFormat
106107
107108 init ( sourceFileIndex: Int ,
108109 outputFileIndex: Int ,
@@ -112,7 +113,8 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
112113 workingDir: Path ,
113114 prefixInfo: ClangPrefixInfo ? ,
114115 toolchains: [ String ] ,
115- responseFileAttachmentPaths: [ Path : Path ] ) {
116+ responseFileAttachmentPaths: [ Path : Path ] ,
117+ responseFileFormat: ResponseFileFormat ) {
116118 self . sourceFileIndex = sourceFileIndex
117119 self . outputFileIndex = outputFileIndex
118120 self . sourceLanguageIndex = sourceLanguageIndex
@@ -122,14 +124,15 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
122124 self . prefixInfo = prefixInfo
123125 self . toolchains = toolchains
124126 self . responseFileAttachmentPaths = responseFileAttachmentPaths
127+ self . responseFileFormat = responseFileFormat
125128 }
126129
127130 func sourceFile( for task: any ExecutableTask ) -> Path {
128131 return Path ( task. commandLine [ self . sourceFileIndex] . asString)
129132 }
130133
131134 public func serialize< T: Serializer > ( to serializer: T ) {
132- serializer. serializeAggregate ( 9 ) {
135+ serializer. serializeAggregate ( 10 ) {
133136 serializer. serialize ( sourceFileIndex)
134137 serializer. serialize ( outputFileIndex)
135138 serializer. serialize ( sourceLanguageIndex)
@@ -139,11 +142,12 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
139142 serializer. serializeUniquely ( prefixInfo)
140143 serializer. serialize ( toolchains)
141144 serializer. serialize ( responseFileAttachmentPaths)
145+ serializer. serialize ( responseFileFormat)
142146 }
143147 }
144148
145149 public init ( from deserializer: any Deserializer ) throws {
146- try deserializer. beginAggregate ( 9 )
150+ try deserializer. beginAggregate ( 10 )
147151 self . sourceFileIndex = try deserializer. deserialize ( )
148152 self . outputFileIndex = try deserializer. deserialize ( )
149153 self . sourceLanguageIndex = try deserializer. deserialize ( )
@@ -153,6 +157,7 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
153157 self . prefixInfo = try deserializer. deserializeUniquely ( )
154158 self . toolchains = try deserializer. deserialize ( )
155159 self . responseFileAttachmentPaths = try deserializer. deserialize ( )
160+ self . responseFileFormat = try deserializer. deserialize ( )
156161 }
157162}
158163
@@ -192,7 +197,7 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
192197 fileprivate init ( task: any ExecutableTask , payload: ClangIndexingPayload , enableIndexBuildArena: Bool ) {
193198 self . outputFile = Path ( task. commandLine [ payload. outputFileIndex] . asString)
194199 self . sourceLanguage = task. commandLine [ payload. sourceLanguageIndex] . asByteString
195- self . commandLine = Self . indexingCommandLine ( from: task. commandLine. map ( \. asByteString) , workingDir: payload. workingDir, prefixInfo: payload. prefixInfo, addSupplementary: !enableIndexBuildArena, responseFileMapping: payload. responseFileAttachmentPaths)
200+ self . commandLine = Self . indexingCommandLine ( from: task. commandLine. map ( \. asByteString) , workingDir: payload. workingDir, prefixInfo: payload. prefixInfo, addSupplementary: !enableIndexBuildArena, responseFileMapping: payload. responseFileAttachmentPaths, responseFileFormat : payload . responseFileFormat )
196201 self . builtProductsDir = payload. builtProductsDir
197202 self . assetSymbolIndexPath = payload. assetSymbolIndexPath
198203 self . prefixInfo = payload. prefixInfo
@@ -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 : Path ] , responseFileFormat : ResponseFileFormat ? ) -> [ ByteString ] {
206211 var result = [ ByteString] ( )
207212 var iterator = commandLine. makeIterator ( )
208213 let _ = iterator. next ( ) // Skip compiler path
@@ -235,7 +240,8 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
235240 // Skip
236241 } else if arg. starts ( with: ByteString ( unicodeScalarLiteral: " @ " ) ) ,
237242 let attachmentPath = responseFileMapping [ Path ( arg. asString. dropFirst ( ) ) ] ,
238- let responseFileArgs = try ? ResponseFiles . expandResponseFiles ( [ " @ \( attachmentPath. str) " ] , fileSystem: localFS, relativeTo: workingDir, format: . llvmStyleEscaping) {
243+ let responseFileFormat,
244+ let responseFileArgs = try ? ResponseFiles . expandResponseFiles ( [ " @ \( attachmentPath. str) " ] , fileSystem: localFS, relativeTo: workingDir, format: responseFileFormat) {
239245 result. append ( contentsOf: responseFileArgs. map { ByteString ( encodingAsUTF8: $0) } )
240246 } else {
241247 result. append ( arg)
@@ -741,7 +747,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
741747 ctx. add ( string: self . identifier)
742748
743749 let responseFilePath = scope. evaluate ( BuiltinMacros . PER_ARCH_OBJECT_FILE_DIR) . join ( " \( ctx. signature. asString) -common-args.resp " )
744- let attachmentPath = producer. writeFileSpec. constructFileTasks ( CommandBuildContext ( producer: producer, scope: scope, inputs: [ ] , output: responseFilePath) , delegate, contents: ByteString ( encodingAsUTF8: ResponseFiles . responseFileContents ( args: responseFileCommandLine, format: . llvmStyleEscaping) ) , permissions: nil , logContents: true , preparesForIndexing: true , additionalTaskOrderingOptions: [ . immediate, . ignorePhaseOrdering] )
750+ let responseFileFormat = Self . responseFileFormat ( hostOS: producer. hostOperatingSystem)
751+ 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] )
745752
746753 return ConstantFlags ( flags: regularCommandLine + [ " @ \( responseFilePath. str) " ] , headerSearchPaths: headerSearchPaths, inputs: [ responseFilePath] , responseFileMapping: [ responseFilePath: attachmentPath] )
747754 } else {
@@ -1307,7 +1314,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
13071314 workingDir: cbc. scope. evaluate ( BuiltinMacros . PROJECT_DIR) ,
13081315 prefixInfo: prefixInfo,
13091316 toolchains: cbc. producer. toolchains. map { $0. identifier } ,
1310- responseFileAttachmentPaths: constantFlags. responseFileMapping
1317+ responseFileAttachmentPaths: constantFlags. responseFileMapping,
1318+ responseFileFormat: Self . responseFileFormat ( hostOS: cbc. producer. hostOperatingSystem)
13111319 )
13121320 } else {
13131321 indexingPayload = nil
@@ -1794,7 +1802,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
17941802 return ClangPrefixInfo . PCHInfo (
17951803 output: precompPath,
17961804 hashCriteria: nil , // rdar://problem/24469921
1797- commandLine: ClangSourceFileIndexingInfo . indexingCommandLine ( from: byteStringCommandLine, workingDir: cbc. scope. evaluate ( BuiltinMacros . PROJECT_DIR) , addSupplementary: !hasEnabledIndexBuildArena, replaceCompile: false , responseFileMapping: constantFlags. responseFileMapping)
1805+ commandLine: ClangSourceFileIndexingInfo . indexingCommandLine ( from: byteStringCommandLine, workingDir: cbc. scope. evaluate ( BuiltinMacros . PROJECT_DIR) , addSupplementary: !hasEnabledIndexBuildArena, replaceCompile: false , responseFileMapping: constantFlags. responseFileMapping, responseFileFormat : Self . responseFileFormat ( hostOS : cbc . producer . hostOperatingSystem ) )
17981806 )
17991807 }
18001808
@@ -1846,6 +1854,16 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
18461854 return try await discoveredClangToolInfo ( producer, delegate, toolPath: toolPath, arch: arch, sysroot: sdk? . path, language: fileType? . languageDialect? . dialectNameForCompilerCommandLineArgument ?? " c " , blocklistsPathOverride: userSpecifiedBlocklists)
18471855 }
18481856
1857+ package static func responseFileFormat( hostOS: OperatingSystem ) -> ResponseFileFormat {
1858+ switch hostOS {
1859+ case . macOS:
1860+ // Maintained for compatibility with projects which do manual shell escaping of their own in build settings.
1861+ . unixShellQuotedSpaceSeparated
1862+ default :
1863+ . llvmStyleEscaping
1864+ }
1865+ }
1866+
18491867 override public func discoveredCommandLineToolSpecInfo( _ producer: any CommandProducer , _ scope: MacroEvaluationScope , _ delegate: any CoreClientTargetDiagnosticProducingDelegate ) async -> ( any DiscoveredCommandLineToolSpecInfo ) ? {
18501868 do {
18511869 return try await discoveredCommandLineToolSpecInfo ( producer, scope, delegate, forLanguageOfFileType: nil )
0 commit comments