@@ -14,13 +14,21 @@ import TSCUtility
14
14
import Foundation
15
15
16
16
/// A map from a module identifier to a path to its .swiftmodule file.
17
+ /// Deprecated in favour of the below `ExternalTargetModuleDetails`
17
18
public typealias ExternalTargetModulePathMap = [ ModuleDependencyId : AbsolutePath ]
18
19
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 ]
24
32
25
33
/// In Explicit Module Build mode, this planner is responsible for generating and providing
26
34
/// build jobs for all module dependencies and providing compile command options
@@ -211,18 +219,20 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
211
219
inputs: & inputs,
212
220
commandLine: & commandLine)
213
221
222
+ let moduleMapPath = moduleDetails. moduleMapPath. path
214
223
// Encode the target triple pcm args into the output `.pcm` filename
215
224
let targetEncodedModulePath =
216
225
try targetEncodedClangModuleFilePath ( for: moduleInfo,
217
- hashParts: getPCMHashParts ( pcmArgs: pcmArgs) )
226
+ hashParts: getPCMHashParts ( pcmArgs: pcmArgs,
227
+ moduleMapPath: moduleMapPath. description) )
218
228
outputs. append ( TypedVirtualPath ( file: targetEncodedModulePath, type: . pcm) )
219
229
commandLine. appendFlags ( " -emit-pcm " , " -module-name " , moduleId. moduleName,
220
230
" -o " , targetEncodedModulePath. description)
221
231
222
232
// The only required input is the .modulemap for this module.
223
233
// Command line options in the dependency scanner output will include the
224
234
// 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,
226
236
type: . clangModuleMap) )
227
237
228
238
jobs. append ( Job (
@@ -246,7 +256,7 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
246
256
commandLine: inout [ Job . ArgTemplate ] ) throws {
247
257
// Prohibit the frontend from implicitly building textual modules into binary modules.
248
258
commandLine. appendFlags ( " -disable-implicit-swift-modules " , " -Xcc " , " -Xclang " , " -Xcc " ,
249
- " -fno-implicit-modules " )
259
+ " -fno-implicit-modules " , " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-module-maps " )
250
260
var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
251
261
var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
252
262
try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
@@ -314,25 +324,28 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
314
324
let dependencyInfo = try dependencyGraph. moduleInfo ( of: dependencyId)
315
325
let dependencyClangModuleDetails =
316
326
try dependencyGraph. clangModuleDetails ( of: dependencyId)
327
+ let moduleMapPath = dependencyClangModuleDetails. moduleMapPath. path
317
328
let clangModulePath =
318
329
try targetEncodedClangModuleFilePath ( for: dependencyInfo,
319
- hashParts: getPCMHashParts ( pcmArgs: pcmArgs) )
330
+ hashParts: getPCMHashParts ( pcmArgs: pcmArgs,
331
+ moduleMapPath: moduleMapPath. description) )
320
332
// Accumulate the requried information about this dependency
321
333
clangDependencyArtifacts. append (
322
334
ClangModuleArtifactInfo ( name: dependencyId. moduleName,
323
335
modulePath: TextualVirtualPath ( path: clangModulePath) ,
324
336
moduleMapPath: dependencyClangModuleDetails. moduleMapPath) )
325
337
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
329
341
let swiftModulePath : TypedVirtualPath =
330
342
. init( file: compiledModulePath. path, type: . swiftModule)
331
343
// Accumulate the requried information about this dependency
332
344
// TODO: add .swiftdoc and .swiftsourceinfo for this module.
333
345
swiftDependencyArtifacts. append (
334
346
SwiftModuleArtifactInfo ( name: dependencyId. moduleName,
335
- modulePath: TextualVirtualPath ( path: swiftModulePath. fileHandle) ) )
347
+ modulePath: TextualVirtualPath ( path: swiftModulePath. fileHandle) ,
348
+ isFramework: isFramework) )
336
349
case . swiftPlaceholder:
337
350
fatalError ( " Unresolved placeholder dependencies at planning stage: \( dependencyId) of \( moduleId) " )
338
351
}
@@ -380,11 +393,14 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
380
393
return VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( " \( moduleId. moduleName) -dependencies.json " ) , contents)
381
394
}
382
395
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)
384
400
if integratedDriver {
385
- return pcmArgs
401
+ return results
386
402
}
387
- var results = pcmArgs
403
+
388
404
// We need this to enable explict modules in the driver-as-executable mode. For instance,
389
405
// we have two Swift targets A and B, where A depends on X.pcm which in turn depends on Y.pcm,
390
406
// 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 {
436
452
#else
437
453
hashedArguments = SHA256 ( ) . hash ( hashInput) . hexadecimalRepresentation
438
454
#endif
439
- let resultingName = moduleName + hashedArguments
455
+ let resultingName = moduleName + " - " + hashedArguments
440
456
hashedModuleNameCache [ cacheQuery] = resultingName
441
457
return resultingName
442
458
}
443
459
}
444
460
445
461
/// Encapsulates some of the common queries of the ExplicitDependencyBuildPlanner with error-checking
446
462
/// on the dependency graph's structure.
447
- internal extension InterModuleDependencyGraph {
463
+ @ _spi ( Testing ) public extension InterModuleDependencyGraph {
448
464
func moduleInfo( of moduleId: ModuleDependencyId ) throws -> ModuleInfo {
449
465
guard let moduleInfo = modules [ moduleId] else {
450
466
throw Driver . Error. missingModuleDependency ( moduleId. moduleName)
0 commit comments