Skip to content

Commit 3d6473c

Browse files
committed
[Plugins] Fix build parameter handling during symbol graph entry point builds
Supersedes #7629
1 parent 09b3ed1 commit 3d6473c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Sources/Commands/Utilities/PluginDelegate.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,19 @@ final class PluginDelegate: PluginInvocationDelegate {
389389
throw StringError("could not find a target named “\(targetName)")
390390
}
391391

392+
// FIXME: This is currently necessary because `target(for:destination:)` can
393+
// produce a module that is targeting host when `targetName`` corresponds to
394+
// a macro, plugin, or a test. Ideally we'd ask a build system for a`BuildSubset`
395+
// and get the destination from there but there are other places that need
396+
// refactoring in that way as well.
397+
let buildParameters = if target.buildTriple == .tools {
398+
try swiftCommandState.toolsBuildParameters
399+
} else {
400+
try swiftCommandState.productsBuildParameters
401+
}
402+
392403
// Build the target, if needed.
393-
try buildSystem.build(subset: .target(target.name))
404+
try buildSystem.build(subset: .target(target.name, for: buildParameters.destination))
394405

395406
// Configure the symbol graph extractor.
396407
var symbolGraphExtractor = try SymbolGraphExtract(
@@ -419,7 +430,7 @@ final class PluginDelegate: PluginInvocationDelegate {
419430
guard let package = packageGraph.package(for: target) else {
420431
throw StringError("could not determine the package for target “\(target.name)")
421432
}
422-
let outputDir = try buildSystem.buildPlan.toolsBuildParameters.dataPath.appending(
433+
let outputDir = try buildParameters.dataPath.appending(
423434
components: "extracted-symbols",
424435
package.identity.description,
425436
target.name
@@ -430,7 +441,7 @@ final class PluginDelegate: PluginInvocationDelegate {
430441
let result = try symbolGraphExtractor.extractSymbolGraph(
431442
module: target,
432443
buildPlan: try buildSystem.buildPlan,
433-
buildParameters: buildSystem.buildPlan.destinationBuildParameters,
444+
buildParameters: buildParameters,
434445
outputRedirection: .collect,
435446
outputDirectory: outputDir,
436447
verboseOutput: self.swiftCommandState.logLevel <= .info

0 commit comments

Comments
 (0)