@@ -103,6 +103,7 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
103
103
let prefixInfo : ClangPrefixInfo ?
104
104
public let toolchains : [ String ]
105
105
let responseFileAttachmentPaths : [ Path : Path ]
106
+ let responseFileFormat : ResponseFileFormat
106
107
107
108
init ( sourceFileIndex: Int ,
108
109
outputFileIndex: Int ,
@@ -112,7 +113,8 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
112
113
workingDir: Path ,
113
114
prefixInfo: ClangPrefixInfo ? ,
114
115
toolchains: [ String ] ,
115
- responseFileAttachmentPaths: [ Path : Path ] ) {
116
+ responseFileAttachmentPaths: [ Path : Path ] ,
117
+ responseFileFormat: ResponseFileFormat ) {
116
118
self . sourceFileIndex = sourceFileIndex
117
119
self . outputFileIndex = outputFileIndex
118
120
self . sourceLanguageIndex = sourceLanguageIndex
@@ -122,14 +124,15 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
122
124
self . prefixInfo = prefixInfo
123
125
self . toolchains = toolchains
124
126
self . responseFileAttachmentPaths = responseFileAttachmentPaths
127
+ self . responseFileFormat = responseFileFormat
125
128
}
126
129
127
130
func sourceFile( for task: any ExecutableTask ) -> Path {
128
131
return Path ( task. commandLine [ self . sourceFileIndex] . asString)
129
132
}
130
133
131
134
public func serialize< T: Serializer > ( to serializer: T ) {
132
- serializer. serializeAggregate ( 9 ) {
135
+ serializer. serializeAggregate ( 10 ) {
133
136
serializer. serialize ( sourceFileIndex)
134
137
serializer. serialize ( outputFileIndex)
135
138
serializer. serialize ( sourceLanguageIndex)
@@ -139,11 +142,12 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
139
142
serializer. serializeUniquely ( prefixInfo)
140
143
serializer. serialize ( toolchains)
141
144
serializer. serialize ( responseFileAttachmentPaths)
145
+ serializer. serialize ( responseFileFormat)
142
146
}
143
147
}
144
148
145
149
public init ( from deserializer: any Deserializer ) throws {
146
- try deserializer. beginAggregate ( 9 )
150
+ try deserializer. beginAggregate ( 10 )
147
151
self . sourceFileIndex = try deserializer. deserialize ( )
148
152
self . outputFileIndex = try deserializer. deserialize ( )
149
153
self . sourceLanguageIndex = try deserializer. deserialize ( )
@@ -153,6 +157,7 @@ public struct ClangIndexingPayload: Serializable, Encodable, Sendable {
153
157
self . prefixInfo = try deserializer. deserializeUniquely ( )
154
158
self . toolchains = try deserializer. deserialize ( )
155
159
self . responseFileAttachmentPaths = try deserializer. deserialize ( )
160
+ self . responseFileFormat = try deserializer. deserialize ( )
156
161
}
157
162
}
158
163
@@ -192,7 +197,7 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
192
197
fileprivate init ( task: any ExecutableTask , payload: ClangIndexingPayload , enableIndexBuildArena: Bool ) {
193
198
self . outputFile = Path ( task. commandLine [ payload. outputFileIndex] . asString)
194
199
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 )
196
201
self . builtProductsDir = payload. builtProductsDir
197
202
self . assetSymbolIndexPath = payload. assetSymbolIndexPath
198
203
self . prefixInfo = payload. prefixInfo
@@ -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 : Path ] , responseFileFormat : ResponseFileFormat ? ) -> [ ByteString ] {
206
211
var result = [ ByteString] ( )
207
212
var iterator = commandLine. makeIterator ( )
208
213
let _ = iterator. next ( ) // Skip compiler path
@@ -235,7 +240,8 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
235
240
// Skip
236
241
} else if arg. starts ( with: ByteString ( unicodeScalarLiteral: " @ " ) ) ,
237
242
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) {
239
245
result. append ( contentsOf: responseFileArgs. map { ByteString ( encodingAsUTF8: $0) } )
240
246
} else {
241
247
result. append ( arg)
@@ -741,7 +747,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
741
747
ctx. add ( string: self . identifier)
742
748
743
749
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] )
745
752
746
753
return ConstantFlags ( flags: regularCommandLine + [ " @ \( responseFilePath. str) " ] , headerSearchPaths: headerSearchPaths, inputs: [ responseFilePath] , responseFileMapping: [ responseFilePath: attachmentPath] )
747
754
} else {
@@ -1307,7 +1314,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
1307
1314
workingDir: cbc. scope. evaluate ( BuiltinMacros . PROJECT_DIR) ,
1308
1315
prefixInfo: prefixInfo,
1309
1316
toolchains: cbc. producer. toolchains. map { $0. identifier } ,
1310
- responseFileAttachmentPaths: constantFlags. responseFileMapping
1317
+ responseFileAttachmentPaths: constantFlags. responseFileMapping,
1318
+ responseFileFormat: Self . responseFileFormat ( hostOS: cbc. producer. hostOperatingSystem)
1311
1319
)
1312
1320
} else {
1313
1321
indexingPayload = nil
@@ -1794,7 +1802,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
1794
1802
return ClangPrefixInfo . PCHInfo (
1795
1803
output: precompPath,
1796
1804
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 ) )
1798
1806
)
1799
1807
}
1800
1808
@@ -1846,6 +1854,16 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
1846
1854
return try await discoveredClangToolInfo ( producer, delegate, toolPath: toolPath, arch: arch, sysroot: sdk? . path, language: fileType? . languageDialect? . dialectNameForCompilerCommandLineArgument ?? " c " , blocklistsPathOverride: userSpecifiedBlocklists)
1847
1855
}
1848
1856
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
+
1849
1867
override public func discoveredCommandLineToolSpecInfo( _ producer: any CommandProducer , _ scope: MacroEvaluationScope , _ delegate: any CoreClientTargetDiagnosticProducingDelegate ) async -> ( any DiscoveredCommandLineToolSpecInfo ) ? {
1850
1868
do {
1851
1869
return try await discoveredCommandLineToolSpecInfo ( producer, scope, delegate, forLanguageOfFileType: nil )
0 commit comments