Skip to content

Commit b26293c

Browse files
committed
[Workspace] Enable package mirror for graph root dependencies
<rdar://problem/45744090> Enable package mirroring for graph root dependencies
1 parent eb87c77 commit b26293c

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

Sources/PackageGraph/PackageGraphRoot.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ public struct PackageGraphRoot {
5656
public let requirement: Requirement
5757

5858
/// Create the package reference object for the dependency.
59-
public func createPackageRef() -> PackageReference {
59+
public func createPackageRef(config: SwiftPMConfig) -> PackageReference {
60+
let effectiveURL = config.mirroredURL(forURL: self.url)
6061
return PackageReference(
61-
identity: PackageReference.computeIdentity(packageURL: url),
62-
path: url,
62+
identity: PackageReference.computeIdentity(packageURL: effectiveURL),
63+
path: effectiveURL,
6364
isLocal: (requirement == .localPackage)
6465
)
6566
}
@@ -101,13 +102,13 @@ public struct PackageGraphRoot {
101102
}
102103

103104
/// Returns the constraints imposed by root manifests + dependencies.
104-
public var constraints: [RepositoryPackageConstraint] {
105+
public func constraints(config: SwiftPMConfig) -> [RepositoryPackageConstraint] {
105106
let constraints = packageRefs.map({
106107
RepositoryPackageConstraint(container: $0, requirement: .unversioned)
107108
})
108109
return constraints + dependencies.map({
109110
RepositoryPackageConstraint(
110-
container: $0.createPackageRef(),
111+
container: $0.createPackageRef(config: config),
111112
requirement: $0.requirement.toConstraintRequirement()
112113
)
113114
})

Sources/Workspace/Workspace.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ public class Workspace {
155155
let inputIdentities = root.manifests.map({
156156
PackageReference(identity: $0.name.lowercased(), path: $0.url)
157157
}) + root.dependencies.map({
158-
let identity = PackageReference.computeIdentity(packageURL: $0.url)
159-
return PackageReference(identity: identity, path: $0.url)
158+
let url = workspace.config.mirroredURL(forURL: $0.url)
159+
let identity = PackageReference.computeIdentity(packageURL: url)
160+
return PackageReference(identity: identity, path: url)
160161
})
161162

162163
var requiredIdentities = transitiveClosure(inputIdentities) { identity in
@@ -550,7 +551,7 @@ extension Workspace {
550551
var updateConstraints = currentManifests.editedPackagesConstraints()
551552

552553
// Create constraints based on root manifest and pins for the update resolution.
553-
updateConstraints += graphRoot.constraints
554+
updateConstraints += graphRoot.constraints(config: config)
554555

555556
// Record the start time of dependency resolution.
556557
let resolutionStartTime = Date()
@@ -929,8 +930,9 @@ extension Workspace {
929930
return DependencyManifests(root: root, dependencies: [], workspace: self)
930931
}
931932

932-
let rootDependencyManifests = root.dependencies.compactMap({
933-
return loadManifest(forURL: $0.url, diagnostics: diagnostics)
933+
let rootDependencyManifests: [Manifest] = root.dependencies.compactMap({
934+
let url = config.mirroredURL(forURL: $0.url)
935+
return loadManifest(forURL: url, diagnostics: diagnostics)
934936
})
935937
let inputManifests = root.manifests + rootDependencyManifests
936938

@@ -1141,7 +1143,7 @@ extension Workspace {
11411143
// Use root constraints, dependency manifest constraints and extra
11421144
// constraints to compute if a new resolution is required.
11431145
let dependencies =
1144-
graphRoot.constraints +
1146+
graphRoot.constraints(config: config) +
11451147
// Include constraints from the manifests in the graph root.
11461148
graphRoot.manifests.flatMap({ $0.dependencyConstraints(config: config) }) +
11471149
currentManifests.dependencyConstraints() +
@@ -1164,7 +1166,7 @@ extension Workspace {
11641166
// Create the constraints.
11651167
var constraints = [RepositoryPackageConstraint]()
11661168
constraints += currentManifests.editedPackagesConstraints()
1167-
constraints += graphRoot.constraints + extraConstraints
1169+
constraints += graphRoot.constraints(config: config) + extraConstraints
11681170

11691171
// Record the start time of dependency resolution.
11701172
let resolutionStartTime = Date()

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,16 @@ final class WorkspaceTests: XCTestCase {
24082408
],
24092409
versions: ["1.0.0", "1.4.0"]
24102410
),
2411+
TestPackage(
2412+
name: "Bam",
2413+
targets: [
2414+
TestTarget(name: "Bam"),
2415+
],
2416+
products: [
2417+
TestProduct(name: "Bar", targets: ["Bam"]),
2418+
],
2419+
versions: ["1.0.0", "1.5.0"]
2420+
),
24112421
]
24122422
)
24132423

@@ -2426,8 +2436,13 @@ final class WorkspaceTests: XCTestCase {
24262436
}
24272437

24282438
try workspace.config.set(mirrorURL: workspace.packagesDir.appending(component: "Baz").asString, forPackageURL: workspace.packagesDir.appending(component: "Bar").asString)
2439+
try workspace.config.set(mirrorURL: workspace.packagesDir.appending(component: "Baz").asString, forPackageURL: workspace.packagesDir.appending(component: "Bam").asString)
24292440

2430-
workspace.checkPackageGraph(roots: ["Foo"]) { (graph, diagnostics) in
2441+
let deps: [TestWorkspace.PackageDependency] = [
2442+
.init(name: "Bam", requirement: .upToNextMajor(from: "1.0.0")),
2443+
]
2444+
2445+
workspace.checkPackageGraph(roots: ["Foo"], deps: deps) { (graph, diagnostics) in
24312446
PackageGraphTester(graph) { result in
24322447
result.check(roots: "Foo")
24332448
result.check(packages: "Foo", "Dep", "Baz")
@@ -2439,6 +2454,7 @@ final class WorkspaceTests: XCTestCase {
24392454
result.check(dependency: "Dep", at: .checkout(.version("1.5.0")))
24402455
result.check(dependency: "Baz", at: .checkout(.version("1.4.0")))
24412456
result.check(notPresent: "Bar")
2457+
result.check(notPresent: "Bam")
24422458
}
24432459
}
24442460

0 commit comments

Comments
 (0)