@@ -224,7 +224,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
224224 // First, take the command line options provided in the dependency information
225225 let moduleDetails = try dependencyGraph. clangModuleDetails ( of: moduleId)
226226 moduleDetails. commandLine. forEach { commandLine. appendFlags ( $0) }
227-
227+
228228 // Add the `-target` option as inherited from the dependent Swift module's PCM args
229229 pcmArgs. forEach { commandLine. appendFlags ( $0) }
230230
@@ -243,6 +243,11 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
243243 commandLine. appendFlags ( " -emit-pcm " , " -module-name " , moduleId. moduleName,
244244 " -o " , targetEncodedModulePath. description)
245245
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+
246251 // The only required input is the .modulemap for this module.
247252 // Command line options in the dependency scanner output will include the
248253 // required modulemap, so here we must only add it to the list of inputs.
@@ -269,8 +274,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
269274 inputs: inout [ TypedVirtualPath ] ,
270275 commandLine: inout [ Job . ArgTemplate ] ) throws {
271276 // 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 " )
274280 var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
275281 var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
276282 try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
@@ -298,11 +304,17 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
298304 let clangModulePath =
299305 TypedVirtualPath ( file: moduleArtifactInfo. modulePath. path,
300306 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+
301315 let clangModuleMapPath =
302316 TypedVirtualPath ( file: moduleArtifactInfo. moduleMapPath. path,
303317 type: . clangModuleMap)
304- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
305- " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
306318 commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
307319 " -fmodule-map-file= \( clangModuleMapPath. file. description) " )
308320 inputs. append ( clangModulePath)
0 commit comments