Skip to content

Commit 91155bc

Browse files
committed
[Build/Commands] NFC: Replace more uses of buildTriple with build parameters
1 parent 46aeaa1 commit 91155bc

File tree

9 files changed

+18
-50
lines changed

9 files changed

+18
-50
lines changed

Sources/Build/BuildOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
638638
) { name, path in
639639
try buildOperationForPluginDependencies.build(subset: .product(name, for: .host))
640640
if let builtTool = try buildOperationForPluginDependencies.buildPlan.buildProducts.first(where: {
641-
$0.product.name == name && $0.product.buildTriple == .tools
641+
$0.product.name == name && $0.buildParameters.destination == .host
642642
}) {
643643
return try builtTool.binaryPath
644644
} else {

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public struct BuildDescription: Codable {
383383
.explicitTargetDependencyImportCheckingMode
384384
self.targetDependencyMap = try plan.targets.reduce(into: [TargetName: [TargetName]]()) { partial, targetBuildDescription in
385385
let deps = try targetBuildDescription.target.recursiveDependencies(
386-
satisfying: plan.buildParameters(for: targetBuildDescription.target).buildEnvironment
386+
satisfying: targetBuildDescription.buildParameters.buildEnvironment
387387
)
388388
.compactMap(\.target).map(\.c99name)
389389
partial[targetBuildDescription.target.c99name] = deps

Sources/Build/BuildPlan/BuildPlan+Test.swift

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import struct Basics.AbsolutePath
1616
import struct LLBuildManifest.TestDiscoveryTool
1717
import struct LLBuildManifest.TestEntryPointTool
1818
import struct PackageGraph.ModulesGraph
19+
import struct PackageGraph.ResolvedPackage
1920
import struct PackageGraph.ResolvedProduct
2021
import struct PackageGraph.ResolvedModule
2122
import struct PackageModel.Sources
@@ -26,9 +27,9 @@ import protocol TSCBasic.FileSystem
2627

2728
extension BuildPlan {
2829
static func makeDerivedTestTargets(
30+
testProducts: [(product: ResolvedProduct, buildDescription: ProductBuildDescription)],
2931
destinationBuildParameters: BuildParameters,
3032
toolsBuildParameters: BuildParameters,
31-
_ graph: ModulesGraph,
3233
shouldDisableSandbox: Bool,
3334
_ fileSystem: FileSystem,
3435
_ observabilityScope: ObservabilityScope
@@ -44,15 +45,14 @@ extension BuildPlan {
4445

4546
var isDiscoveryEnabledRedundantly = explicitlyEnabledDiscovery && !isEntryPointPathSpecifiedExplicitly
4647
var result: [(ResolvedProduct, SwiftTargetBuildDescription?, SwiftTargetBuildDescription)] = []
47-
for testProduct in graph.allProducts where testProduct.type == .test {
48-
guard let package = graph.package(for: testProduct) else {
49-
throw InternalError("package not found for \(testProduct)")
50-
}
48+
for (testProduct, testBuildDescription) in testProducts {
49+
let package = testBuildDescription.package
50+
5151
isDiscoveryEnabledRedundantly = isDiscoveryEnabledRedundantly && nil == testProduct.testEntryPointTarget
5252
// If a non-explicitly specified test entry point file exists, prefer that over test discovery.
5353
// This is designed as an escape hatch when test discovery is not appropriate and for backwards
5454
// compatibility for projects that have existing test entry point files (e.g. XCTMain.swift, LinuxMain.swift).
55-
let toolsVersion = graph.package(for: testProduct)?.manifest.toolsVersion ?? .v5_5
55+
let toolsVersion = package.manifest.toolsVersion
5656

5757
// If `testProduct.testEntryPointTarget` is non-nil, it may either represent an `XCTMain.swift` (formerly `LinuxMain.swift`) file
5858
// if such a file is located in the package, or it may represent a test entry point file at a path specified by the option
@@ -93,20 +93,13 @@ extension BuildPlan {
9393
supportedPlatforms: testProduct.supportedPlatforms,
9494
platformVersionProvider: testProduct.platformVersionProvider
9595
)
96-
9796
discoveryResolvedTarget.buildTriple = testProduct.buildTriple
98-
let discoveryTargetBuildParameters: BuildParameters
99-
switch discoveryResolvedTarget.buildTriple {
100-
case .tools:
101-
discoveryTargetBuildParameters = toolsBuildParameters
102-
case .destination:
103-
discoveryTargetBuildParameters = destinationBuildParameters
104-
}
97+
10598
let discoveryTargetBuildDescription = try SwiftTargetBuildDescription(
10699
package: package,
107100
target: discoveryResolvedTarget,
108101
toolsVersion: toolsVersion,
109-
buildParameters: discoveryTargetBuildParameters,
102+
buildParameters: testBuildDescription.buildParameters,
110103
testTargetRole: .discovery,
111104
shouldDisableSandbox: shouldDisableSandbox,
112105
fileSystem: fileSystem,
@@ -143,19 +136,12 @@ extension BuildPlan {
143136
platformVersionProvider: testProduct.platformVersionProvider
144137
)
145138
entryPointResolvedTarget.buildTriple = testProduct.buildTriple
146-
let entryPointBuildParameters: BuildParameters
147-
switch entryPointResolvedTarget.buildTriple {
148-
case .tools:
149-
entryPointBuildParameters = toolsBuildParameters
150-
case .destination:
151-
entryPointBuildParameters = destinationBuildParameters
152-
}
153139

154140
return try SwiftTargetBuildDescription(
155141
package: package,
156142
target: entryPointResolvedTarget,
157143
toolsVersion: toolsVersion,
158-
buildParameters: entryPointBuildParameters,
144+
buildParameters: testBuildDescription.buildParameters,
159145
testTargetRole: .entryPoint(isSynthesized: true),
160146
shouldDisableSandbox: shouldDisableSandbox,
161147
fileSystem: fileSystem,

Sources/Build/BuildPlan/BuildPlan.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,11 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
439439
// Plan the derived test targets, if necessary.
440440
if destinationBuildParameters.testingParameters.testProductStyle.requiresAdditionalDerivedTestTargets {
441441
let derivedTestTargets = try Self.makeDerivedTestTargets(
442+
testProducts: productMap.values.filter {
443+
$0.product.type == .test
444+
},
442445
destinationBuildParameters: destinationBuildParameters,
443446
toolsBuildParameters: toolsBuildParameters,
444-
graph,
445447
shouldDisableSandbox: self.shouldDisableSandbox,
446448
self.fileSystem,
447449
self.observabilityScope

Sources/Commands/PackageCommands/DumpCommands.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct DumpSymbolGraph: SwiftCommand {
7272
let result = try symbolGraphExtractor.extractSymbolGraph(
7373
module: target,
7474
buildPlan: buildPlan,
75+
buildParameters: buildPlan.destinationBuildParameters,
7576
outputRedirection: .collect(redirectStderr: true),
7677
outputDirectory: symbolGraphDirectory,
7778
verboseOutput: swiftCommandState.logLevel <= .info

Sources/Commands/PackageCommands/PluginCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ struct PluginCommand: SwiftCommand {
336336
// Build the product referenced by the tool, and add the executable to the tool map. Product dependencies are not supported within a package, so if the tool happens to be from the same package, we instead find the executable that corresponds to the product. There is always one, because of autogeneration of implicit executables with the same name as the target if there isn't an explicit one.
337337
try buildSystem.build(subset: .product(name, for: .host))
338338
if let builtTool = try buildSystem.buildPlan.buildProducts.first(where: {
339-
$0.product.name == name && $0.product.buildTriple == .tools
339+
$0.product.name == name && $0.buildParameters.destination == .host
340340
}) {
341341
return try builtTool.binaryPath
342342
} else {

Sources/Commands/Utilities/PluginDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ final class PluginDelegate: PluginInvocationDelegate {
430430
let result = try symbolGraphExtractor.extractSymbolGraph(
431431
module: target,
432432
buildPlan: try buildSystem.buildPlan,
433+
buildParameters: buildSystem.buildPlan.toolsBuildParameters,
433434
outputRedirection: .collect,
434435
outputDirectory: outputDir,
435436
verboseOutput: self.swiftCommandState.logLevel <= .info

Sources/Commands/Utilities/SymbolGraphExtract.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public struct SymbolGraphExtract {
5656
public func extractSymbolGraph(
5757
module: ResolvedModule,
5858
buildPlan: BuildPlan,
59+
buildParameters: BuildParameters,
5960
outputRedirection: TSCBasic.Process.OutputRedirection = .none,
6061
outputDirectory: AbsolutePath,
6162
verboseOutput: Bool
6263
) throws -> ProcessResult {
63-
let buildParameters = buildPlan.buildParameters(for: module)
6464
try self.fileSystem.createDirectory(outputDirectory, recursive: true)
6565

6666
// Construct arguments for extracting symbols for a single target.

Sources/SPMBuildCore/BuildSystem/BuildSystem.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,6 @@ public protocol BuildPlan {
9292
func createREPLArguments() throws -> [String]
9393
}
9494

95-
extension BuildPlan {
96-
/// Parameters used for building a given target.
97-
public func buildParameters(for target: ResolvedModule) -> BuildParameters {
98-
switch target.buildTriple {
99-
case .tools:
100-
return self.toolsBuildParameters
101-
case .destination:
102-
return self.destinationBuildParameters
103-
}
104-
}
105-
106-
/// Parameters used for building a given product.
107-
public func buildParameters(for product: ResolvedProduct) -> BuildParameters {
108-
switch product.buildTriple {
109-
case .tools:
110-
return self.toolsBuildParameters
111-
case .destination:
112-
return self.destinationBuildParameters
113-
}
114-
}
115-
}
116-
11795
public protocol BuildSystemFactory {
11896
func makeBuildSystem(
11997
explicitProduct: String?,

0 commit comments

Comments
 (0)