Skip to content

Commit 867a453

Browse files
authored
Fix handling of build environment when planning (#5787)
This fixes a few callsites that weren't taking conditionals into account, most notably the check for minimum deployment target. rdar://70543422
1 parent 486ec2d commit 867a453

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,10 @@ public class BuildPlan {
18881888
for target in graph.allTargets.sorted(by: { $0.name < $1.name }) {
18891889
// Validate the product dependencies of this target.
18901890
for dependency in target.dependencies {
1891+
guard dependency.satisfies(buildParameters.buildEnvironment) else {
1892+
continue
1893+
}
1894+
18911895
switch dependency {
18921896
case .target: break
18931897
case .product(let product, _):
@@ -2151,6 +2155,10 @@ public class BuildPlan {
21512155
// For a product dependency, we only include its content only if we
21522156
// need to statically link it or if it's a plugin.
21532157
case .product(let product, _):
2158+
guard dependency.satisfies(self.buildEnvironment) else {
2159+
return []
2160+
}
2161+
21542162
switch product.type {
21552163
case .library(.automatic), .library(.static), .plugin:
21562164
return product.targets.map { .target($0, conditions: []) }

Sources/Build/LLBuildManifestBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ extension LLBuildManifestBuilder {
443443
for target: ResolvedTarget,
444444
dependencyModulePathMap: inout SwiftDriver.ExternalTargetModulePathMap
445445
) throws {
446-
for dependency in target.dependencies {
446+
for dependency in target.dependencies(satisfying: self.buildEnvironment) {
447447
switch dependency {
448448
case .product:
449449
// Product dependencies are broken down into the targets that make them up.

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ final class BuildPlanTests: XCTestCase {
223223
let fs = InMemoryFileSystem(emptyFiles:
224224
Pkg.appending(components: "Sources", "exe", "main.swift").pathString,
225225
Pkg.appending(components: "Sources", "PkgLib", "lib.swift").pathString,
226-
"/ExtPkg/Sources/ExtLib/lib.swift"
226+
"/ExtPkg/Sources/ExtLib/lib.swift",
227+
"/PlatformPkg/Sources/PlatformLib/lib.swift"
227228
)
228229

229230
let observability = ObservabilitySystem.makeForTesting()
@@ -235,6 +236,7 @@ final class BuildPlanTests: XCTestCase {
235236
path: .init(Pkg.pathString),
236237
dependencies: [
237238
.localSourceControl(path: .init("/ExtPkg"), requirement: .upToNextMajor(from: "1.0.0")),
239+
.localSourceControl(path: .init("/PlatformPkg"), requirement: .upToNextMajor(from: "1.0.0")),
238240
],
239241
targets: [
240242
TargetDescription(name: "exe", dependencies: [
@@ -247,6 +249,9 @@ final class BuildPlanTests: XCTestCase {
247249
.product(name: "ExtLib", package: "ExtPkg", condition: PackageConditionDescription(
248250
platformNames: [],
249251
config: "debug"
252+
)),
253+
.product(name: "PlatformLib", package: "PlatformPkg", condition: PackageConditionDescription(
254+
platformNames: ["linux"]
250255
))
251256
]),
252257
]
@@ -261,6 +266,17 @@ final class BuildPlanTests: XCTestCase {
261266
TargetDescription(name: "ExtLib", dependencies: []),
262267
]
263268
),
269+
Manifest.createLocalSourceControlManifest(
270+
name: "PlatformPkg",
271+
path: .init("/PlatformPkg"),
272+
platforms: [PlatformDescription(name: "macos", version: "50.0")],
273+
products: [
274+
ProductDescription(name: "PlatformLib", type: .library(.automatic), targets: ["PlatformLib"]),
275+
],
276+
targets: [
277+
TargetDescription(name: "PlatformLib", dependencies: []),
278+
]
279+
),
264280
],
265281
observabilityScope: observability.topScope
266282
)

0 commit comments

Comments
 (0)