@@ -162,33 +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- // FIXME: This is a temporary measure meant to be deleted once supported toolchains'
180- // scanners always output commands with '-o'.
181- //
182- // If the dependency scanner did not append its own "-o", add it here.
183- // This is temporary and is meant to handle both: the scanner that
184- // appends '-o' and one that doesn't, until we have a toolchain snapshot with the scanner
185- // that appends '-o' always.
186- let outputFlagIndeces = commandLine. enumerated ( ) . compactMap { $1 == . flag( " -o " ) ? $0 : nil }
187- if outputFlagIndeces. isEmpty {
188- commandLine. appendFlag ( . o)
189- commandLine. appendPath ( VirtualPath . lookup ( moduleInfo. modulePath. path) )
190- }
191-
192170 jobs. append ( Job (
193171 moduleName: moduleId. moduleName,
194172 kind: . compileModuleFromInterface,
@@ -241,23 +219,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
241219 let moduleMapPath = moduleDetails. moduleMapPath. path
242220 let modulePCMPath = moduleInfo. modulePath
243221 outputs. append ( TypedVirtualPath ( file: modulePCMPath. path, type: . pcm) )
244-
245- // TODO: Remove this once toolchain is updated
246- // If the dependency scanner did not append its own "-o", add it here.
247- // This is temporary and is meant to handle both: the scanner that
248- // appends '-o' and one that doesn't, until we have a toolchain snapshot with the scanner
249- // that appends '-o' always.
250- let outputFlagIndeces = commandLine. enumerated ( ) . compactMap { $1 == . flag( " -o " ) ? $0 : nil }
251- // One '-o' is expected as an `-Xcc` flag.
252- if outputFlagIndeces. count <= 1 {
253- commandLine. appendFlags ( " -o " , modulePCMPath. path. description)
254- }
255-
256- // TODO: Remove this once toolchain is updated
257- // Fixup "-o -Xcc '<replace-me>'"
258- if let outputIndex = commandLine. firstIndex ( of: . flag( " <replace-me> " ) ) {
259- commandLine [ outputIndex] = . path( VirtualPath . lookup ( modulePCMPath. path) )
260- }
261222
262223 // The only required input is the .modulemap for this module.
263224 // Command line options in the dependency scanner output will include the
@@ -285,53 +246,42 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
285246 inputs: inout [ TypedVirtualPath ] ,
286247 commandLine: inout [ Job . ArgTemplate ] ) throws {
287248 // Prohibit the frontend from implicitly building textual modules into binary modules.
288- commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
289- " -Xcc " , " -fno-implicit-modules " ,
290- " -Xcc " , " -fno-implicit-module-maps " )
291249 var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
292250 var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
293251 try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
294252 clangDependencyArtifacts: & clangDependencyArtifacts,
295253 swiftDependencyArtifacts: & swiftDependencyArtifacts)
296254
297- // Swift Module dependencies are passed encoded in a JSON file as described by
298- // SwiftModuleArtifactInfo
299- if !swiftDependencyArtifacts. isEmpty {
300- let dependencyFile =
301- try serializeModuleDependencies ( for: moduleId, dependencyArtifacts: swiftDependencyArtifacts)
302- commandLine. appendFlag ( " -explicit-swift-module-map-file " )
303- commandLine. appendPath ( dependencyFile)
304- inputs. append ( TypedVirtualPath ( file: dependencyFile. intern ( ) ,
305- type: . jsonSwiftArtifacts) )
306- // Each individual module binary is still an "input" to ensure the build system gets the
307- // order correctly.
308- for dependencyModule in swiftDependencyArtifacts {
309- inputs. append ( TypedVirtualPath ( file: dependencyModule. modulePath. path,
310- type: . swiftModule) )
311- }
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) )
312260 }
261+
313262 // Clang module dependencies are specified on the command line explicitly
314263 for moduleArtifactInfo in clangDependencyArtifacts {
315264 let clangModulePath =
316- TypedVirtualPath ( file: moduleArtifactInfo. modulePath . path,
265+ TypedVirtualPath ( file: moduleArtifactInfo. clangModulePath . path,
317266 type: . pcm)
318267 let clangModuleMapPath =
319- TypedVirtualPath ( file: moduleArtifactInfo. moduleMapPath . path,
268+ TypedVirtualPath ( file: moduleArtifactInfo. clangModuleMapPath . path,
320269 type: . clangModuleMap)
321270 inputs. append ( clangModulePath)
322271 inputs. append ( clangModuleMapPath)
272+ }
323273
324- // If an existing dependency module path stub exists, replace it.
325- if let existingIndex = commandLine . firstIndex ( of : . flag ( " -fmodule-file= " + moduleArtifactInfo . moduleName + " =<replace-me> " ) ) {
326- commandLine [ existingIndex ] = . flag ( " -fmodule-file= \( moduleArtifactInfo . moduleName) = \( clangModulePath . file . description ) " )
327- } else if case . swift ( _ ) = moduleId {
328- commandLine . appendFlags ( " -Xcc " ,
329- " -fmodule-file= \( moduleArtifactInfo . moduleName ) = \( clangModulePath . file . description ) " )
330- }
331- if case . swift ( _ ) = moduleId {
332- commandLine. appendFlags ( " -Xcc " ,
333- " -fmodule-map-file= \( clangModuleMapPath . file. description ) " )
334- }
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 ) )
335285 }
336286 }
337287
@@ -410,6 +360,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
410360 public mutating func resolveMainModuleDependencies( inputs: inout [ TypedVirtualPath ] ,
411361 commandLine: inout [ Job . ArgTemplate ] ) throws {
412362 let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
363+ commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
364+ " -Xcc " , " -fno-implicit-modules " ,
365+ " -Xcc " , " -fno-implicit-module-maps " )
413366 try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
414367 pcmArgs:
415368 try dependencyGraph. swiftModulePCMArgs ( of: mainModuleId) ,
@@ -419,11 +372,15 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
419372
420373 /// Store the output file artifacts for a given module in a JSON file, return the file's path.
421374 private func serializeModuleDependencies( for moduleId: ModuleDependencyId ,
422- dependencyArtifacts: [ SwiftModuleArtifactInfo ]
375+ swiftDependencyArtifacts: [ SwiftModuleArtifactInfo ] ,
376+ clangDependencyArtifacts: [ ClangModuleArtifactInfo ]
423377 ) throws -> VirtualPath {
378+ let allDependencyArtifacts : [ ModuleDependencyArtifactInfo ] =
379+ swiftDependencyArtifacts. map { ModuleDependencyArtifactInfo . swift ( $0) } +
380+ clangDependencyArtifacts. map { ModuleDependencyArtifactInfo . clang ( $0) }
424381 let encoder = JSONEncoder ( )
425382 encoder. outputFormatting = [ . prettyPrinted]
426- let contents = try encoder. encode ( dependencyArtifacts )
383+ let contents = try encoder. encode ( allDependencyArtifacts )
427384 return VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( " \( moduleId. moduleName) -dependencies.json " ) , contents)
428385 }
429386
0 commit comments