Skip to content

Commit c86ea69

Browse files
committed
Give clang target description access to the package it's associated with
We need this information to set `-w` and other package specific options.
1 parent 2bc24f0 commit c86ea69

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Basics
14+
import PackageGraph
1415
import PackageLoading
1516
import PackageModel
1617
import struct PackageGraph.ModulesGraph
@@ -23,6 +24,9 @@ import enum TSCBasic.ProcessEnv
2324

2425
/// Target description for a Clang target i.e. C language family target.
2526
package final class ClangTargetBuildDescription {
27+
/// The package this target belongs to.
28+
package let package: ResolvedPackage
29+
2630
/// The target described by this target.
2731
package let target: ResolvedTarget
2832

@@ -109,6 +113,7 @@ package final class ClangTargetBuildDescription {
109113

110114
/// Create a new target description with target and build parameters.
111115
init(
116+
package: ResolvedPackage,
112117
target: ResolvedTarget,
113118
toolsVersion: ToolsVersion,
114119
additionalFileRules: [FileRuleDescription] = [],
@@ -122,6 +127,7 @@ package final class ClangTargetBuildDescription {
122127
throw InternalError("underlying target type mismatch \(target)")
123128
}
124129

130+
self.package = package
125131
self.clangTarget = clangTarget
126132
self.fileSystem = fileSystem
127133
self.target = target

Sources/Build/BuildPlan/BuildPlan.swift

+5
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,13 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
394394
)
395395
)
396396
case is ClangTarget:
397+
guard let package = graph.package(for: target) else {
398+
throw InternalError("package not found for \(target)")
399+
}
400+
397401
targetMap[target.id] = try .clang(
398402
ClangTargetBuildDescription(
403+
package: package,
399404
target: target,
400405
toolsVersion: toolsVersion,
401406
additionalFileRules: additionalFileRules,

Tests/BuildTests/ClangTargetBuildDescriptionTests.swift

+26-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,33 @@ final class ClangTargetBuildDescriptionTests: XCTestCase {
4949

5050
private func makeTargetBuildDescription() throws -> ClangTargetBuildDescription {
5151
let observability = ObservabilitySystem.makeForTesting(verbose: false)
52+
53+
let manifest = Manifest.createRootManifest(
54+
displayName: "dummy",
55+
toolsVersion: .v5,
56+
targets: [try TargetDescription(name: "dummy")]
57+
)
58+
59+
let target = try makeResolvedTarget()
60+
61+
let package = Package(identity: .plain("dummy"),
62+
manifest: manifest,
63+
path: .root,
64+
targets: [target.underlying],
65+
products: [],
66+
targetSearchPath: .root,
67+
testTargetSearchPath: .root)
68+
5269
return try ClangTargetBuildDescription(
53-
target: try makeResolvedTarget(),
70+
package: .init(underlying: package,
71+
defaultLocalization: nil,
72+
supportedPlatforms: [],
73+
dependencies: [],
74+
targets: [target],
75+
products: [],
76+
registryMetadata: nil,
77+
platformVersionProvider: .init(implementation: .minimumDeploymentTargetDefault)),
78+
target: target,
5479
toolsVersion: .current,
5580
buildParameters: mockBuildParameters(
5681
toolchain: try UserToolchain.default,

0 commit comments

Comments
 (0)