@@ -14,13 +14,21 @@ import TSCUtility
1414import Foundation
1515
1616/// A map from a module identifier to a path to its .swiftmodule file.
17+ /// Deprecated in favour of the below `ExternalTargetModuleDetails`
1718public typealias ExternalTargetModulePathMap = [ ModuleDependencyId : AbsolutePath ]
1819
19- // FIXME: ExternalBuildArtifacts is a temporary backwards-compatibility shim
20- // to help transition SwiftPM to the new API.
21- /// A tuple all external artifacts a build system may pass in as input to the explicit build of the current module
22- /// Consists of a map of externally-built targets, and a map of all previously discovered/scanned modules.
23- public typealias ExternalBuildArtifacts = ( ExternalTargetModulePathMap , ModuleInfoMap )
20+ /// Details about an external target, including the path to its .swiftmodule file
21+ /// and whether it is a framework.
22+ public struct ExternalTargetModuleDetails {
23+ public init ( path: AbsolutePath , isFramework: Bool ) {
24+ self . path = path
25+ self . isFramework = isFramework
26+ }
27+ let path : AbsolutePath
28+ let isFramework : Bool
29+ }
30+
31+ public typealias ExternalTargetModuleDetailsMap = [ ModuleDependencyId : ExternalTargetModuleDetails ]
2432
2533/// In Explicit Module Build mode, this planner is responsible for generating and providing
2634/// build jobs for all module dependencies and providing compile command options
@@ -211,18 +219,20 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
211219 inputs: & inputs,
212220 commandLine: & commandLine)
213221
222+ let moduleMapPath = moduleDetails. moduleMapPath. path
214223 // Encode the target triple pcm args into the output `.pcm` filename
215224 let targetEncodedModulePath =
216225 try targetEncodedClangModuleFilePath ( for: moduleInfo,
217- hashParts: getPCMHashParts ( pcmArgs: pcmArgs) )
226+ hashParts: getPCMHashParts ( pcmArgs: pcmArgs,
227+ moduleMapPath: moduleMapPath. description) )
218228 outputs. append ( TypedVirtualPath ( file: targetEncodedModulePath, type: . pcm) )
219229 commandLine. appendFlags ( " -emit-pcm " , " -module-name " , moduleId. moduleName,
220230 " -o " , targetEncodedModulePath. description)
221231
222232 // The only required input is the .modulemap for this module.
223233 // Command line options in the dependency scanner output will include the
224234 // required modulemap, so here we must only add it to the list of inputs.
225- inputs. append ( TypedVirtualPath ( file: moduleDetails . moduleMapPath. path ,
235+ inputs. append ( TypedVirtualPath ( file: moduleMapPath,
226236 type: . clangModuleMap) )
227237
228238 jobs. append ( Job (
@@ -246,7 +256,7 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
246256 commandLine: inout [ Job . ArgTemplate ] ) throws {
247257 // Prohibit the frontend from implicitly building textual modules into binary modules.
248258 commandLine. appendFlags ( " -disable-implicit-swift-modules " , " -Xcc " , " -Xclang " , " -Xcc " ,
249- " -fno-implicit-modules " )
259+ " -fno-implicit-modules " , " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-module-maps " )
250260 var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
251261 var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
252262 try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
@@ -314,25 +324,28 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
314324 let dependencyInfo = try dependencyGraph. moduleInfo ( of: dependencyId)
315325 let dependencyClangModuleDetails =
316326 try dependencyGraph. clangModuleDetails ( of: dependencyId)
327+ let moduleMapPath = dependencyClangModuleDetails. moduleMapPath. path
317328 let clangModulePath =
318329 try targetEncodedClangModuleFilePath ( for: dependencyInfo,
319- hashParts: getPCMHashParts ( pcmArgs: pcmArgs) )
330+ hashParts: getPCMHashParts ( pcmArgs: pcmArgs,
331+ moduleMapPath: moduleMapPath. description) )
320332 // Accumulate the requried information about this dependency
321333 clangDependencyArtifacts. append (
322334 ClangModuleArtifactInfo ( name: dependencyId. moduleName,
323335 modulePath: TextualVirtualPath ( path: clangModulePath) ,
324336 moduleMapPath: dependencyClangModuleDetails. moduleMapPath) )
325337 case . swiftPrebuiltExternal:
326- let compiledModulePath = try dependencyGraph
327- . swiftPrebuiltDetails ( of : dependencyId )
328- . compiledModulePath
338+ let prebuiltModuleDetails = try dependencyGraph. swiftPrebuiltDetails ( of : dependencyId )
339+ let compiledModulePath = prebuiltModuleDetails . compiledModulePath
340+ let isFramework = prebuiltModuleDetails . isFramework
329341 let swiftModulePath : TypedVirtualPath =
330342 . init( file: compiledModulePath. path, type: . swiftModule)
331343 // Accumulate the requried information about this dependency
332344 // TODO: add .swiftdoc and .swiftsourceinfo for this module.
333345 swiftDependencyArtifacts. append (
334346 SwiftModuleArtifactInfo ( name: dependencyId. moduleName,
335- modulePath: TextualVirtualPath ( path: swiftModulePath. fileHandle) ) )
347+ modulePath: TextualVirtualPath ( path: swiftModulePath. fileHandle) ,
348+ isFramework: isFramework) )
336349 case . swiftPlaceholder:
337350 fatalError ( " Unresolved placeholder dependencies at planning stage: \( dependencyId) of \( moduleId) " )
338351 }
@@ -380,11 +393,14 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
380393 return VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( " \( moduleId. moduleName) -dependencies.json " ) , contents)
381394 }
382395
383- private func getPCMHashParts( pcmArgs: [ String ] ) -> [ String ] {
396+ private func getPCMHashParts( pcmArgs: [ String ] , moduleMapPath: String ) -> [ String ] {
397+ var results : [ String ] = [ ]
398+ results. append ( moduleMapPath)
399+ results. append ( contentsOf: pcmArgs)
384400 if integratedDriver {
385- return pcmArgs
401+ return results
386402 }
387- var results = pcmArgs
403+
388404 // We need this to enable explict modules in the driver-as-executable mode. For instance,
389405 // we have two Swift targets A and B, where A depends on X.pcm which in turn depends on Y.pcm,
390406 // and B only depends on Y.pcm. In the driver-as-executable mode, the build system isn't aware
@@ -436,15 +452,15 @@ extension ExplicitDependencyBuildPlanner {
436452 #else
437453 hashedArguments = SHA256 ( ) . hash ( hashInput) . hexadecimalRepresentation
438454 #endif
439- let resultingName = moduleName + hashedArguments
455+ let resultingName = moduleName + " - " + hashedArguments
440456 hashedModuleNameCache [ cacheQuery] = resultingName
441457 return resultingName
442458 }
443459}
444460
445461/// Encapsulates some of the common queries of the ExplicitDependencyBuildPlanner with error-checking
446462/// on the dependency graph's structure.
447- internal extension InterModuleDependencyGraph {
463+ @ _spi ( Testing ) public extension InterModuleDependencyGraph {
448464 func moduleInfo( of moduleId: ModuleDependencyId ) throws -> ModuleInfo {
449465 guard let moduleInfo = modules [ moduleId] else {
450466 throw Driver . Error. missingModuleDependency ( moduleId. moduleName)
0 commit comments