@@ -224,7 +224,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
224
224
// First, take the command line options provided in the dependency information
225
225
let moduleDetails = try dependencyGraph. clangModuleDetails ( of: moduleId)
226
226
moduleDetails. commandLine. forEach { commandLine. appendFlags ( $0) }
227
-
227
+
228
228
// Add the `-target` option as inherited from the dependent Swift module's PCM args
229
229
pcmArgs. forEach { commandLine. appendFlags ( $0) }
230
230
@@ -243,6 +243,11 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
243
243
commandLine. appendFlags ( " -emit-pcm " , " -module-name " , moduleId. moduleName,
244
244
" -o " , targetEncodedModulePath. description)
245
245
246
+ // Fixup "-o -Xcc -Xclang -Xcc '<replace-me>'"
247
+ if let outputIndex = commandLine. firstIndex ( of: . flag( " <replace-me> " ) ) {
248
+ commandLine [ outputIndex] = . path( VirtualPath . lookup ( targetEncodedModulePath) )
249
+ }
250
+
246
251
// The only required input is the .modulemap for this module.
247
252
// Command line options in the dependency scanner output will include the
248
253
// required modulemap, so here we must only add it to the list of inputs.
@@ -269,8 +274,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
269
274
inputs: inout [ TypedVirtualPath ] ,
270
275
commandLine: inout [ Job . ArgTemplate ] ) throws {
271
276
// Prohibit the frontend from implicitly building textual modules into binary modules.
272
- commandLine. appendFlags ( " -disable-implicit-swift-modules " , " -Xcc " , " -Xclang " , " -Xcc " ,
273
- " -fno-implicit-modules " , " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-module-maps " )
277
+ commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
278
+ " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-modules " ,
279
+ " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-module-maps " )
274
280
var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
275
281
var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
276
282
try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
@@ -298,11 +304,17 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
298
304
let clangModulePath =
299
305
TypedVirtualPath ( file: moduleArtifactInfo. modulePath. path,
300
306
type: . pcm)
307
+ // If an existing dependency module path stub exists, replace it.
308
+ if let existingIndex = commandLine. firstIndex ( of: . flag( " -fmodule-file= " + moduleArtifactInfo. moduleName + " =<replace-me> " ) ) {
309
+ commandLine [ existingIndex] = . flag( " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
310
+ } else {
311
+ commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
312
+ " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
313
+ }
314
+
301
315
let clangModuleMapPath =
302
316
TypedVirtualPath ( file: moduleArtifactInfo. moduleMapPath. path,
303
317
type: . clangModuleMap)
304
- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
305
- " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
306
318
commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
307
319
" -fmodule-map-file= \( clangModuleMapPath. file. description) " )
308
320
inputs. append ( clangModulePath)
0 commit comments