@@ -526,36 +526,22 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
526
526
// FIXME: This is super unfortunate that we might need to load the package graph.
527
527
let graph = try getPackageGraph ( )
528
528
529
- var product = graph. product (
529
+ let product = graph. product (
530
530
for: productName,
531
531
destination: destination == . host ? . tools : . destination
532
532
)
533
533
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
-
554
534
guard let product else {
555
535
observabilityScope. emit ( error: " no product named ' \( productName) ' " )
556
536
throw Diagnostics . fatalError
557
537
}
558
538
539
+ let buildParameters = if product. buildTriple == . tools {
540
+ self . toolsBuildParameters
541
+ } else {
542
+ self . productsBuildParameters
543
+ }
544
+
559
545
// If the product is automatic, we build the main target because automatic products
560
546
// do not produce a binary right now.
561
547
if product. type == . library( . automatic) {
@@ -570,33 +556,22 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
570
556
// FIXME: This is super unfortunate that we might need to load the package graph.
571
557
let graph = try getPackageGraph ( )
572
558
573
- var target = graph. target (
559
+ let target = graph. target (
574
560
for: targetName,
575
561
destination: destination == . host ? . tools : . destination
576
562
)
577
563
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
-
595
564
guard let target else {
596
565
observabilityScope. emit ( error: " no target named ' \( targetName) ' " )
597
566
throw Diagnostics . fatalError
598
567
}
599
568
569
+ let buildParameters = if target. buildTriple == . tools {
570
+ self . toolsBuildParameters
571
+ } else {
572
+ self . productsBuildParameters
573
+ }
574
+
600
575
return target. getLLBuildTargetName ( buildParameters: buildParameters)
601
576
}
602
577
}
0 commit comments