@@ -526,36 +526,22 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
526526 // FIXME: This is super unfortunate that we might need to load the package graph.
527527 let graph = try getPackageGraph ( )
528528
529- var product = graph. product (
529+ let product = graph. product (
530530 for: productName,
531531 destination: destination == . host ? . tools : . destination
532532 )
533533
534- var buildParameters = if destination == . host {
535- self . toolsBuildParameters
536- } else {
537- self . productsBuildParameters
538- }
539-
540- // It's possible to request a build of a macro or a plugin via `swift build`
541- // which won't have the right destination set because it's impossible to indicate it.
542- //
543- // Same happens with `--test-product` - if one of the test targets directly references
544- // a macro then all if its targets and the product itself become `host`.
545- if product == nil && destination == . target {
546- if let toolsProduct = graph. product ( for: productName, destination: . tools) ,
547- toolsProduct. type == . macro || toolsProduct. type == . plugin || toolsProduct. type == . test
548- {
549- product = toolsProduct
550- buildParameters = self . toolsBuildParameters
551- }
552- }
553-
554534 guard let product else {
555535 observabilityScope. emit ( error: " no product named ' \( productName) ' " )
556536 throw Diagnostics . fatalError
557537 }
558538
539+ let buildParameters = if product. buildTriple == . tools {
540+ self . toolsBuildParameters
541+ } else {
542+ self . productsBuildParameters
543+ }
544+
559545 // If the product is automatic, we build the main target because automatic products
560546 // do not produce a binary right now.
561547 if product. type == . library( . automatic) {
@@ -570,33 +556,22 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
570556 // FIXME: This is super unfortunate that we might need to load the package graph.
571557 let graph = try getPackageGraph ( )
572558
573- var target = graph. target (
559+ let target = graph. target (
574560 for: targetName,
575561 destination: destination == . host ? . tools : . destination
576562 )
577563
578- var buildParameters = if destination == . host {
579- self . toolsBuildParameters
580- } else {
581- self . productsBuildParameters
582- }
583-
584- // It's possible to request a build of a macro or a plugin via `swift build`
585- // which won't have the right destination because it's impossible to indicate it.
586- if target == nil && destination == . target {
587- if let toolsTarget = graph. target ( for: targetName, destination: . tools) ,
588- toolsTarget. type == . macro || toolsTarget. type == . plugin
589- {
590- target = toolsTarget
591- buildParameters = self . toolsBuildParameters
592- }
593- }
594-
595564 guard let target else {
596565 observabilityScope. emit ( error: " no target named ' \( targetName) ' " )
597566 throw Diagnostics . fatalError
598567 }
599568
569+ let buildParameters = if target. buildTriple == . tools {
570+ self . toolsBuildParameters
571+ } else {
572+ self . productsBuildParameters
573+ }
574+
600575 return target. getLLBuildTargetName ( buildParameters: buildParameters)
601576 }
602577 }
0 commit comments