|
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | 13 | import Basics |
| 14 | + |
| 15 | +import struct OrderedCollections.OrderedDictionary |
| 16 | + |
14 | 17 | import PackageModel |
15 | 18 |
|
16 | 19 | /// A fully resolved package. Contains resolved targets, products and dependencies of the package. |
@@ -64,8 +67,43 @@ public struct ResolvedPackage { |
64 | 67 | platformVersionProvider: PlatformVersionProvider |
65 | 68 | ) { |
66 | 69 | self.underlying = underlying |
67 | | - self.targets = targets |
68 | | - self.products = products |
| 70 | + |
| 71 | + var processedTargets = OrderedDictionary<ResolvedTarget.ID, ResolvedTarget>( |
| 72 | + uniqueKeysWithValues: targets.map { ($0.id, $0) } |
| 73 | + ) |
| 74 | + var processedProducts = [ResolvedProduct]() |
| 75 | + // Make sure that direct macro dependencies of test products are also built for the target triple. |
| 76 | + // Without this workaround, `assertMacroExpansion` in tests can't be built, as it requires macros |
| 77 | + // and SwiftSyntax to be built for the target triple: https://github.com/apple/swift-package-manager/pull/7349 |
| 78 | + for var product in products { |
| 79 | + if product.type == .test { |
| 80 | + var targets = IdentifiableSet<ResolvedTarget>() |
| 81 | + for var target in product.targets { |
| 82 | + var dependencies = [ResolvedTarget.Dependency]() |
| 83 | + for dependency in target.dependencies { |
| 84 | + switch dependency { |
| 85 | + case .target(var target, let conditions) where target.type == .macro: |
| 86 | + target.buildTriple = .destination |
| 87 | + dependencies.append(.target(target, conditions: conditions)) |
| 88 | + processedTargets[target.id] = target |
| 89 | + case .product(var product, let conditions) where product.type == .macro: |
| 90 | + product.buildTriple = .destination |
| 91 | + dependencies.append(.product(product, conditions: conditions)) |
| 92 | + default: |
| 93 | + dependencies.append(dependency) |
| 94 | + } |
| 95 | + } |
| 96 | + target.dependencies = dependencies |
| 97 | + targets.insert(target) |
| 98 | + } |
| 99 | + product.targets = targets |
| 100 | + } |
| 101 | + |
| 102 | + processedProducts.append(product) |
| 103 | + } |
| 104 | + |
| 105 | + self.products = processedProducts |
| 106 | + self.targets = Array(processedTargets.values) |
69 | 107 | self.dependencies = dependencies |
70 | 108 | self.defaultLocalization = defaultLocalization |
71 | 109 | self.supportedPlatforms = supportedPlatforms |
|
0 commit comments