Skip to content

Commit b22168e

Browse files
committed
[PackageGraph] Add a an executable product to match executable target that plugin depends on
Create a new executable product if plugin depends on an executable target. This is necessary, even though PackageBuilder creates one already, because that product is going to be built for `destination`, and this one has to be built for `tools`.
1 parent ec7c830 commit b22168e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Sources/PackageGraph/ModulesGraph.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,38 @@ public struct ModulesGraph {
222222
}
223223
}
224224
}
225+
226+
// Create a new executable product if plugin depends on an executable target.
227+
// This is necessary, even though PackageBuilder creates one already, because
228+
// that product is going to be built for `destination`, and this one has to
229+
// be built for `tools`.
230+
if target.underlying is PluginTarget {
231+
for dependency in target.dependencies {
232+
switch dependency {
233+
case .product(_, conditions: _):
234+
break
235+
236+
case .target(let target, conditions: _):
237+
if target.type != .executable {
238+
continue
239+
}
240+
241+
var product = try ResolvedProduct(
242+
packageIdentity: target.packageIdentity,
243+
product: .init(
244+
package: target.packageIdentity,
245+
name: target.name,
246+
type: .executable,
247+
targets: [target.underlying]
248+
),
249+
targets: IdentifiableSet([target])
250+
)
251+
product.buildTriple = .tools
252+
253+
allProducts.insert(product)
254+
}
255+
}
256+
}
225257
}
226258

227259
if rootPackages.contains(id: package.id) {

0 commit comments

Comments
 (0)