Skip to content

Commit 028ab15

Browse files
authored
Merge branch 'main' into package-dependency-description
2 parents b86b409 + 27f444f commit 028ab15

File tree

11 files changed

+81
-9
lines changed

11 files changed

+81
-9
lines changed

Sources/PackageGraph/DependencyResolutionNode.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public enum DependencyResolutionNode {
7878

7979
/// Assembles the product filter to use on the manifest for this node to determine its dependencies.
8080
public var productFilter: ProductFilter {
81+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
8182
switch self {
8283
case .empty:
8384
return .specific([])
@@ -86,6 +87,9 @@ public enum DependencyResolutionNode {
8687
case .root:
8788
return .everything
8889
}
90+
#else
91+
return .everything
92+
#endif
8993
}
9094

9195
/// Returns the dependency that a product has on its own package, if relevant.

Sources/PackageModel/Manifest.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public final class Manifest: ObjectIdentifierProtocol {
131131

132132
/// Returns the targets required for a particular product filter.
133133
public func targetsRequired(for productFilter: ProductFilter) -> [TargetDescription] {
134+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
134135
// If we have already calcualted it, returned the cached value.
135136
if let targets = _requiredTargets[productFilter] {
136137
return targets
@@ -147,6 +148,9 @@ public final class Manifest: ObjectIdentifierProtocol {
147148
_requiredTargets[productFilter] = targets
148149
return targets
149150
}
151+
#else
152+
return self.targets
153+
#endif
150154
}
151155

152156
/// Returns the package dependencies required for a particular products filter.
@@ -212,6 +216,7 @@ public final class Manifest: ObjectIdentifierProtocol {
212216
}
213217

214218
return dependencies.compactMap { dependency in
219+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
215220
if let filter = associations[dependency.name] {
216221
return dependency.filtered(by: filter)
217222
} else if keepUnused {
@@ -221,6 +226,9 @@ public final class Manifest: ObjectIdentifierProtocol {
221226
// Dependencies known to not have any relevant products are discarded.
222227
return nil
223228
}
229+
#else
230+
return FilteredDependencyDescription(declaration: dependency, productFilter: .everything)
231+
#endif
224232
}
225233
}
226234

Sources/SourceControl/InMemoryGitRepository.swift renamed to Sources/SPMTestSupport/InMemoryGitRepository.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
*/
1010

1111
import TSCBasic
12-
import Dispatch
1312
import TSCUtility
13+
import SourceControl
14+
import Dispatch
1415
import class Foundation.NSUUID
1516

1617
/// The error encountered during in memory git repository operations.

Sources/SourceControl/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
add_library(SourceControl
1010
GitRepository.swift
11-
InMemoryGitRepository.swift
1211
Repository.swift
1312
RepositoryManager.swift
1413
SwiftPMConfig.swift)

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,18 +1316,25 @@ final class BuildPlanTests: XCTestCase {
13161316
]
13171317
)
13181318

1319+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
13191320
XCTAssertEqual(diagnostics.diagnostics.count, 1)
13201321
let firstDiagnostic = diagnostics.diagnostics.first.map({ $0.message.text })
13211322
XCTAssert(
13221323
firstDiagnostic == "dependency 'C' is not used by any target",
13231324
"Unexpected diagnostic: " + (firstDiagnostic ?? "[none]")
13241325
)
1326+
#endif
13251327

13261328
let graphResult = PackageGraphResult(graph)
13271329
graphResult.check(reachableProducts: "aexec", "BLibrary")
13281330
graphResult.check(reachableTargets: "ATarget", "BTarget1")
1331+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
13291332
graphResult.check(products: "aexec", "BLibrary")
13301333
graphResult.check(targets: "ATarget", "BTarget1")
1334+
#else
1335+
graphResult.check(products: "BLibrary", "bexec", "aexec", "cexec")
1336+
graphResult.check(targets: "ATarget", "BTarget1", "BTarget2", "CTarget")
1337+
#endif
13311338

13321339
let planResult = BuildPlanResult(plan: try BuildPlan(
13331340
buildParameters: mockBuildParameters(),
@@ -1336,8 +1343,13 @@ final class BuildPlanTests: XCTestCase {
13361343
fileSystem: fileSystem
13371344
))
13381345

1346+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
13391347
planResult.checkProductsCount(2)
13401348
planResult.checkTargetsCount(2)
1349+
#else
1350+
planResult.checkProductsCount(4)
1351+
planResult.checkTargetsCount(4)
1352+
#endif
13411353
}
13421354

13431355
func testReachableBuildProductsAndTargets() throws {

Tests/PackageGraphTests/PackageGraphTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,9 @@ class PackageGraphTests: XCTestCase {
739739

740740
DiagnosticsEngineTester(diagnostics) { result in
741741
result.check(diagnostic: "dependency 'Baz' is not used by any target", behavior: .warning)
742+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
742743
result.check(diagnostic: "dependency 'Biz' is not used by any target", behavior: .warning)
744+
#endif
743745
}
744746
}
745747

@@ -1077,7 +1079,12 @@ class PackageGraphTests: XCTestCase {
10771079
}
10781080
}
10791081

1080-
func testUnreachableProductsSkipped() {
1082+
func testUnreachableProductsSkipped() throws {
1083+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
1084+
#else
1085+
try XCTSkipIf(true)
1086+
#endif
1087+
10811088
let fs = InMemoryFileSystem(emptyFiles:
10821089
"/Root/Sources/Root/Root.swift",
10831090
"/Immediate/Sources/ImmediateUsed/ImmediateUsed.swift",

Tests/PackageGraphTests/PubgrubTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,12 @@ final class PubgrubTests: XCTestCase {
10581058
])
10591059
}
10601060

1061-
func testUnreachableProductsSkipped() {
1061+
func testUnreachableProductsSkipped() throws {
1062+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
1063+
#else
1064+
try XCTSkipIf(true)
1065+
#endif
1066+
10621067
builder.serve("root", at: .unversioned, with: [
10631068
"root": ["immediate": (.versionSet(v1Range), .specific(["ImmediateUsed"]))]
10641069
])

Tests/PackageGraphTests/RepositoryPackageContainerProviderTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ class RepositoryPackageContainerProviderTests: XCTestCase {
360360
}
361361

362362
func testDependencyConstraints() throws {
363+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
364+
#else
365+
try XCTSkipIf(true)
366+
#endif
367+
363368
let dependencies = [
364369
PackageDependencyDescription(name: "Bar1", url: "/Bar1", requirement: .upToNextMajor(from: "1.0.0")),
365370
PackageDependencyDescription(name: "Bar2", url: "/Bar2", requirement: .upToNextMajor(from: "1.0.0")),

Tests/PackageModelTests/ManifestTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ class ManifestTests: XCTestCase {
5656
targets: targets
5757
)
5858

59+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
5960
XCTAssertEqual(manifest.targetsRequired(for: .specific(["Foo", "Bar"])).map({ $0.name }).sorted(), [
6061
"Bar",
6162
"Baz",
6263
"Foo",
6364
])
65+
#endif
6466
}
6567
}
6668

@@ -150,11 +152,13 @@ class ManifestTests: XCTestCase {
150152
targets: targets
151153
)
152154

155+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
153156
XCTAssertEqual(manifest.dependenciesRequired(for: .specific(["Foo"])).map({ $0.name }).sorted(), [
154157
"Bar1", // Foo → Foo1 → Bar1
155158
"Bar2", // Foo → Foo1 → Foo2 → Bar2
156159
// (Bar3 is unreachable.)
157160
])
161+
#endif
158162
}
159163
}
160164
}

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,11 +1468,15 @@ final class WorkspaceTests: XCTestCase {
14681468
// Run update.
14691469
workspace.checkUpdateDryRun(roots: ["Root"]) { changes, diagnostics in
14701470
XCTAssertNoDiagnostics(diagnostics)
1471+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
1472+
let stateChange = Workspace.PackageStateChange.updated(.init(requirement: .version(Version("1.5.0")), products: .specific(["Foo"])))
1473+
#else
1474+
let stateChange = Workspace.PackageStateChange.updated(.init(requirement: .version(Version("1.5.0")), products: .everything))
1475+
#endif
1476+
14711477
let expectedChange = (
14721478
PackageReference(identity: "foo", path: "/tmp/ws/pkgs/Foo"),
1473-
Workspace.PackageStateChange.updated(
1474-
.init(requirement: .version(Version("1.5.0")), products: .specific(["Foo"]))
1475-
)
1479+
stateChange
14761480
)
14771481
guard let change = changes?.first, changes?.count == 1 else {
14781482
XCTFail()
@@ -2028,11 +2032,13 @@ final class WorkspaceTests: XCTestCase {
20282032
]
20292033
)
20302034

2035+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
20312036
workspace.checkPackageGraph(roots: ["Root"]) { (graph, diagnostics) in
20322037
DiagnosticsEngineTester(diagnostics) { result in
20332038
result.check(diagnostic: .contains("Foo[Foo] 1.0.0..<2.0.0"), behavior: .error)
20342039
}
20352040
}
2041+
#endif
20362042
}
20372043

20382044
func testToolsVersionRootPackages() throws {
@@ -2865,9 +2871,11 @@ final class WorkspaceTests: XCTestCase {
28652871
result.check(packages: "Foo")
28662872
result.check(targets: "Foo")
28672873
}
2874+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
28682875
DiagnosticsEngineTester(diagnostics) { result in
28692876
result.check(diagnostic: .contains("Bar[Bar] {1.0.0..<1.5.0, 1.5.1..<2.0.0} is forbidden"), behavior: .error)
28702877
}
2878+
#endif
28712879
}
28722880
}
28732881

@@ -3996,6 +4004,11 @@ final class WorkspaceTests: XCTestCase {
39964004
}
39974005

39984006
func testTargetBasedDependency() throws {
4007+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
4008+
#else
4009+
try XCTSkipIf(true)
4010+
#endif
4011+
39994012
let sandbox = AbsolutePath("/tmp/ws/")
40004013
let fs = InMemoryFileSystem()
40014014

Tests/XCBuildSupportTests/PIFBuilderTests.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,20 @@ class PIFBuilderTests: XCTestCase {
8686
let targetAExeDependencies = pif.workspace.projects[0].targets[0].dependencies
8787
XCTAssertEqual(targetAExeDependencies.map{ $0.targetGUID }, ["PACKAGE-PRODUCT:blib", "PACKAGE-TARGET:A2", "PACKAGE-TARGET:A3"])
8888
let projectBTargetNames = pif.workspace.projects[1].targets.map({ $0.name })
89+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
8990
XCTAssertEqual(projectBTargetNames, ["blib", "B2"])
91+
#else
92+
XCTAssertEqual(projectBTargetNames, ["bexe", "blib", "B2"])
93+
#endif
9094
}
9195
}
9296

93-
func testProject() {
97+
func testProject() throws {
98+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
99+
#else
100+
try XCTSkipIf(true)
101+
#endif
102+
94103
let fs = InMemoryFileSystem(emptyFiles:
95104
"/Foo/Sources/foo/main.swift",
96105
"/Foo/Tests/FooTests/tests.swift",
@@ -675,7 +684,12 @@ class PIFBuilderTests: XCTestCase {
675684
}
676685
}
677686

678-
func testTestProducts() {
687+
func testTestProducts() throws {
688+
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
689+
#else
690+
try XCTSkipIf(true)
691+
#endif
692+
679693
let fs = InMemoryFileSystem(emptyFiles:
680694
"/Foo/Sources/FooTests/FooTests.swift",
681695
"/Foo/Sources/CFooTests/CFooTests.m",

0 commit comments

Comments
 (0)