@@ -191,10 +191,8 @@ extension LLBuildManifestBuilder {
191
191
public func addTargetsToExplicitBuildManifest( ) throws {
192
192
// Sort the product targets in topological order in order to collect and "bubble up"
193
193
// their respective dependency graphs to the depending targets.
194
- let nodes = self . plan. targets. compactMap {
195
- ResolvedModule . Dependency. module ( $0. module, conditions: [ ] )
196
- }
197
- let allPackageDependencies = try topologicalSort ( nodes, successors: { $0. dependencies } )
194
+ let allPackageDependencies = self . plan. targets. flatMap { $0. recursiveDependencies ( using: self . plan) }
195
+
198
196
// Instantiate the inter-module dependency oracle which will cache commonly-scanned
199
197
// modules across targets' Driver instances.
200
198
let dependencyOracle = InterModuleDependencyOracle ( )
@@ -206,14 +204,15 @@ extension LLBuildManifestBuilder {
206
204
207
205
// Create commands for all module descriptions in the plan.
208
206
for dependency in allPackageDependencies. reversed ( ) {
209
- guard case . module( let target , _ ) = dependency else {
207
+ guard case . module( let module , let description ) = dependency else {
210
208
// Product dependency build jobs are added after the fact.
211
209
// Targets that depend on product dependencies will expand the corresponding
212
210
// product into its constituent targets.
213
211
continue
214
212
}
215
- guard target. underlying. type != . systemModule,
216
- target. underlying. type != . binary
213
+
214
+ guard module. underlying. type != . systemModule,
215
+ module. underlying. type != . binary
217
216
else {
218
217
// Much like non-Swift targets, system modules will consist of a modulemap
219
218
// somewhere in the filesystem, with the path to that module being either
@@ -225,9 +224,11 @@ extension LLBuildManifestBuilder {
225
224
// be able to detect such targets' modules.
226
225
continue
227
226
}
228
- guard let description = plan. targetMap [ target. id] else {
229
- throw InternalError ( " Expected description for target \( target) " )
227
+
228
+ guard let description else {
229
+ throw InternalError ( " Expected description for module \( module) " )
230
230
}
231
+
231
232
switch description {
232
233
case . swift( let desc) :
233
234
try self . createExplicitSwiftTargetCompileCommand (
@@ -319,32 +320,29 @@ extension LLBuildManifestBuilder {
319
320
for targetDescription: ModuleBuildDescription ,
320
321
dependencyModuleDetailsMap: inout SwiftDriver . ExternalTargetModuleDetailsMap
321
322
) throws {
322
- for dependency in targetDescription. module . dependencies ( satisfying : targetDescription . buildParameters . buildEnvironment ) {
323
+ for dependency in targetDescription. dependencies ( using : self . plan ) {
323
324
switch dependency {
324
- case . product:
325
- // Product dependencies are broken down into the targets that make them up.
326
- guard let dependencyProduct = dependency . product else {
327
- throw InternalError ( " unknown dependency product for \( dependency ) " )
328
- }
329
- for dependencyProductTarget in dependencyProduct . modules {
330
- guard let dependencyTargetDescription = self . plan . targetMap [ dependencyProductTarget . id ] else {
331
- throw InternalError ( " unknown dependency target for \( dependencyProductTarget ) " )
325
+ case . product( let product , let productDescription ) :
326
+ for productDependency in product . modules {
327
+ guard let dependencyModuleDescription = self . plan . description (
328
+ for: productDependency ,
329
+ context : productDescription ? . destination ?? targetDescription . destination
330
+ ) else
331
+ {
332
+ throw InternalError ( " unknown dependency target for \( productDependency ) " )
332
333
}
333
334
try self . addTargetDependencyInfo (
334
- for: dependencyTargetDescription ,
335
+ for: dependencyModuleDescription ,
335
336
dependencyModuleDetailsMap: & dependencyModuleDetailsMap
336
337
)
337
338
}
338
- case . module:
339
- // Product dependencies are broken down into the targets that make them up.
340
- guard
341
- let dependencyTarget = dependency. module,
342
- let dependencyTargetDescription = self . plan. targetMap [ dependencyTarget. id]
343
- else {
344
- throw InternalError ( " unknown dependency target for \( dependency) " )
339
+ case . module( let dependencyModule, let dependencyDescription) :
340
+ guard let dependencyDescription else {
341
+ throw InternalError ( " No build description for module: \( dependencyModule) " )
345
342
}
343
+ // Product dependencies are broken down into the targets that make them up.
346
344
try self . addTargetDependencyInfo (
347
- for: dependencyTargetDescription ,
345
+ for: dependencyDescription ,
348
346
dependencyModuleDetailsMap: & dependencyModuleDetailsMap
349
347
)
350
348
}
@@ -422,63 +420,69 @@ extension LLBuildManifestBuilder {
422
420
423
421
let prepareForIndexing = target. buildParameters. prepareForIndexing
424
422
425
- func addStaticTargetInputs( _ target : ResolvedModule ) throws {
423
+ func addStaticTargetInputs( _ module : ResolvedModule , _ description : ModuleBuildDescription ? ) throws {
426
424
// Ignore C Modules.
427
- if target . underlying is SystemLibraryModule { return }
425
+ if module . underlying is SystemLibraryModule { return }
428
426
// Ignore Binary Modules.
429
- if target . underlying is BinaryModule { return }
427
+ if module . underlying is BinaryModule { return }
430
428
// Ignore Plugin Modules.
431
- if target . underlying is PluginModule { return }
429
+ if module . underlying is PluginModule { return }
432
430
433
431
// Depend on the binary for executable targets.
434
- if target . type == . executable && prepareForIndexing == . off {
432
+ if module . type == . executable && prepareForIndexing == . off {
435
433
// FIXME: Optimize.
436
434
if let productDescription = try plan. productMap. values. first ( where: {
437
- try $0. product. type == . executable && $0. product. executableModule. id == target . id
435
+ try $0. product. type == . executable && $0. product. executableModule. id == module . id
438
436
} ) {
439
437
try inputs. append ( file: productDescription. binaryPath)
440
438
}
441
439
return
442
440
}
443
441
444
- switch self . plan. targetMap [ target. id] {
445
- case . swift( let target) ? :
446
- inputs. append ( file: target. moduleOutputPath)
447
- case . clang( let target) ? :
442
+ guard let description else {
443
+ throw InternalError ( " No build description for module: \( module) " )
444
+ }
445
+
446
+ switch description {
447
+ case . swift( let swiftDescription) :
448
+ inputs. append ( file: swiftDescription. moduleOutputPath)
449
+ case . clang( let clangDescription) :
448
450
if prepareForIndexing != . off {
449
451
// In preparation, we're only building swiftmodules
450
452
// propagate the dependency to the header files in this target
451
- for header in target . clangTarget. headers {
453
+ for header in clangDescription . clangTarget. headers {
452
454
inputs. append ( file: header)
453
455
}
454
456
} else {
455
- for object in try target . objects {
457
+ for object in try clangDescription . objects {
456
458
inputs. append ( file: object)
457
459
}
458
460
}
459
- case nil :
460
- throw InternalError ( " unexpected: target \( target) not in target map \( self . plan. targetMap) " )
461
461
}
462
462
}
463
463
464
- for dependency in target. target . dependencies ( satisfying : target . buildParameters . buildEnvironment ) {
464
+ for dependency in target. dependencies ( using : self . plan ) {
465
465
switch dependency {
466
- case . module( let target , _ ) :
467
- try addStaticTargetInputs ( target )
466
+ case . module( let module , let description ) :
467
+ try addStaticTargetInputs ( module , description )
468
468
469
- case . product( let product, _ ) :
469
+ case . product( let product, let productDescription ) :
470
470
switch product. type {
471
471
case . executable, . snippet, . library( . dynamic) , . macro:
472
- guard let planProduct = plan . productMap [ product . id ] else {
473
- throw InternalError ( " unknown product \( product) " )
472
+ guard let productDescription else {
473
+ throw InternalError ( " No description for product: \( product) " )
474
474
}
475
475
// Establish a dependency on binary of the product.
476
- try inputs. append ( file: planProduct . binaryPath)
476
+ try inputs. append ( file: productDescription . binaryPath)
477
477
478
478
// For automatic and static libraries, and plugins, add their targets as static input.
479
479
case . library( . automatic) , . library( . static) , . plugin:
480
- for target in product. modules {
481
- try addStaticTargetInputs ( target)
480
+ for module in product. modules {
481
+ let description = self . plan. description (
482
+ for: module,
483
+ context: product. type == . plugin ? . host : target. destination
484
+ )
485
+ try addStaticTargetInputs ( module, description)
482
486
}
483
487
484
488
case . test:
0 commit comments