@@ -162,24 +162,11 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
162162 // Add precompiled module candidates, if present
163163 if let compiledCandidateList = moduleDetails. compiledModuleCandidates {
164164 for compiledCandidate in compiledCandidateList {
165- commandLine. appendFlag ( " -candidate-module-file " )
166- let compiledCandidatePath = compiledCandidate
167- commandLine. appendPath ( VirtualPath . lookup ( compiledCandidatePath. path) )
168- inputs. append ( TypedVirtualPath ( file: compiledCandidatePath. path,
165+ inputs. append ( TypedVirtualPath ( file: compiledCandidate. path,
169166 type: . swiftModule) )
170167 }
171168 }
172169
173- if supportsExplicitInterfaceBuild {
174- // Ensure the compiler flags specified in the interface are ignored
175- // because they are already captured in the dependency scanner output
176- commandLine. appendFlag ( . explicitInterfaceModuleBuild)
177- }
178-
179- // Set the output path
180- commandLine. appendFlag ( . o)
181- commandLine. appendPath ( VirtualPath . lookup ( moduleInfo. modulePath. path) )
182-
183170 jobs. append ( Job (
184171 moduleName: moduleId. moduleName,
185172 kind: . compileModuleFromInterface,
@@ -232,23 +219,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
232219 let moduleMapPath = moduleDetails. moduleMapPath. path
233220 let modulePCMPath = moduleInfo. modulePath
234221 outputs. append ( TypedVirtualPath ( file: modulePCMPath. path, type: . pcm) )
235-
236- // TODO: Remove this once toolchain is updated
237- // If the dependency scanner did not append its own "-o", add it here.
238- // This is temporary and is meant to handle both: the scanner that
239- // appends '-o' and one that doesn't, until we have a toolchain snapshot with the scanner
240- // that appends '-o' always.
241- let outputFlagIndeces = commandLine. enumerated ( ) . compactMap { $1 == . flag( " -o " ) ? $0 : nil }
242- // One '-o' is expected as an `-Xcc` flag.
243- if outputFlagIndeces. count <= 1 {
244- commandLine. appendFlags ( " -o " , modulePCMPath. path. description)
245- }
246-
247- // TODO: Remove this once toolchain is updated
248- // Fixup "-o -Xcc '<replace-me>'"
249- if let outputIndex = commandLine. firstIndex ( of: . flag( " <replace-me> " ) ) {
250- commandLine [ outputIndex] = . path( VirtualPath . lookup ( modulePCMPath. path) )
251- }
252222
253223 // The only required input is the .modulemap for this module.
254224 // Command line options in the dependency scanner output will include the
@@ -276,53 +246,42 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
276246 inputs: inout [ TypedVirtualPath ] ,
277247 commandLine: inout [ Job . ArgTemplate ] ) throws {
278248 // Prohibit the frontend from implicitly building textual modules into binary modules.
279- commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
280- " -Xcc " , " -fno-implicit-modules " ,
281- " -Xcc " , " -fno-implicit-module-maps " )
282249 var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
283250 var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
284251 try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
285252 clangDependencyArtifacts: & clangDependencyArtifacts,
286253 swiftDependencyArtifacts: & swiftDependencyArtifacts)
287254
288- // Swift Module dependencies are passed encoded in a JSON file as described by
289- // SwiftModuleArtifactInfo
290- if !swiftDependencyArtifacts. isEmpty {
291- let dependencyFile =
292- try serializeModuleDependencies ( for: moduleId, dependencyArtifacts: swiftDependencyArtifacts)
293- commandLine. appendFlag ( " -explicit-swift-module-map-file " )
294- commandLine. appendPath ( dependencyFile)
295- inputs. append ( TypedVirtualPath ( file: dependencyFile. intern ( ) ,
296- type: . jsonSwiftArtifacts) )
297- // Each individual module binary is still an "input" to ensure the build system gets the
298- // order correctly.
299- for dependencyModule in swiftDependencyArtifacts {
300- inputs. append ( TypedVirtualPath ( file: dependencyModule. modulePath. path,
301- type: . swiftModule) )
302- }
255+ // Each individual module binary is still an "input" to ensure the build system gets the
256+ // order correctly.
257+ for dependencyModule in swiftDependencyArtifacts {
258+ inputs. append ( TypedVirtualPath ( file: dependencyModule. modulePath. path,
259+ type: . swiftModule) )
303260 }
261+
304262 // Clang module dependencies are specified on the command line explicitly
305263 for moduleArtifactInfo in clangDependencyArtifacts {
306264 let clangModulePath =
307- TypedVirtualPath ( file: moduleArtifactInfo. modulePath . path,
265+ TypedVirtualPath ( file: moduleArtifactInfo. clangModulePath . path,
308266 type: . pcm)
309267 let clangModuleMapPath =
310- TypedVirtualPath ( file: moduleArtifactInfo. moduleMapPath . path,
268+ TypedVirtualPath ( file: moduleArtifactInfo. clangModuleMapPath . path,
311269 type: . clangModuleMap)
312270 inputs. append ( clangModulePath)
313271 inputs. append ( clangModuleMapPath)
272+ }
314273
315- // If an existing dependency module path stub exists, replace it.
316- if let existingIndex = commandLine . firstIndex ( of : . flag ( " -fmodule-file= " + moduleArtifactInfo . moduleName + " =<replace-me> " ) ) {
317- commandLine [ existingIndex ] = . flag ( " -fmodule-file= \( moduleArtifactInfo . moduleName) = \( clangModulePath . file . description ) " )
318- } else if case . swift ( _ ) = moduleId {
319- commandLine . appendFlags ( " -Xcc " ,
320- " -fmodule-file= \( moduleArtifactInfo . moduleName ) = \( clangModulePath . file . description ) " )
321- }
322- if case . swift ( _ ) = moduleId {
323- commandLine. appendFlags ( " -Xcc " ,
324- " -fmodule-map-file= \( clangModuleMapPath . file. description ) " )
325- }
274+ // Swift Main Module dependencies are passed encoded in a JSON file as described by
275+ // SwiftModuleArtifactInfo
276+ if moduleId . moduleName == mainModuleName {
277+ let dependencyFile =
278+ try serializeModuleDependencies ( for : moduleId ,
279+ swiftDependencyArtifacts : swiftDependencyArtifacts ,
280+ clangDependencyArtifacts : clangDependencyArtifacts )
281+ commandLine . appendFlag ( " -explicit-swift-module-map-file " )
282+ commandLine. appendPath ( dependencyFile )
283+ inputs . append ( TypedVirtualPath ( file: dependencyFile . intern ( ) ,
284+ type : . jsonSwiftArtifacts ) )
326285 }
327286 }
328287
@@ -401,6 +360,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
401360 public mutating func resolveMainModuleDependencies( inputs: inout [ TypedVirtualPath ] ,
402361 commandLine: inout [ Job . ArgTemplate ] ) throws {
403362 let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
363+ commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
364+ " -Xcc " , " -fno-implicit-modules " ,
365+ " -Xcc " , " -fno-implicit-module-maps " )
404366 try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
405367 pcmArgs:
406368 try dependencyGraph. swiftModulePCMArgs ( of: mainModuleId) ,
@@ -410,11 +372,15 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
410372
411373 /// Store the output file artifacts for a given module in a JSON file, return the file's path.
412374 private func serializeModuleDependencies( for moduleId: ModuleDependencyId ,
413- dependencyArtifacts: [ SwiftModuleArtifactInfo ]
375+ swiftDependencyArtifacts: [ SwiftModuleArtifactInfo ] ,
376+ clangDependencyArtifacts: [ ClangModuleArtifactInfo ]
414377 ) throws -> VirtualPath {
378+ let allDependencyArtifacts : [ ModuleDependencyArtifactInfo ] =
379+ swiftDependencyArtifacts. map { ModuleDependencyArtifactInfo . swift ( $0) } +
380+ clangDependencyArtifacts. map { ModuleDependencyArtifactInfo . clang ( $0) }
415381 let encoder = JSONEncoder ( )
416382 encoder. outputFormatting = [ . prettyPrinted]
417- let contents = try encoder. encode ( dependencyArtifacts )
383+ let contents = try encoder. encode ( allDependencyArtifacts )
418384 return VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( " \( moduleId. moduleName) -dependencies.json " ) , contents)
419385 }
420386
0 commit comments