Skip to content

Commit e74d91f

Browse files
authored
Merge pull request #3005 from abertelrud/fix-package-identity-regression
Fix a recent regression in package identity
2 parents fa1f7d5 + 9f035ef commit e74d91f

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

Sources/PackageGraph/PackageModel+Extensions.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ extension PackageDependencyDescription {
1717
let effectiveURL = config.mirroredURL(forURL: url)
1818

1919
// FIXME: The identity of a package dependency is currently based on
20-
// the explicit name provided in the package manifest, if provided,
21-
// falling back on a name computed from its effective URL.
22-
// We should instead use the declared URL of a package dependency as its identity,
23-
// as it will be necessary for supporting package registries.
24-
let identity = explicitName?.lowercased() ?? PackageReference.computeIdentity(packageURL: effectiveURL)
20+
// on a name computed from the package's effective URL. This
21+
// is because the name of the package that's in the manifest
22+
// is not known until the manifest has been parsed.
23+
// We should instead use the declared URL of a package dependency
24+
// as its identity, as it will be needed for supporting package
25+
// registries.
26+
let identity = PackageReference.computeIdentity(packageURL: effectiveURL)
2527

2628
return PackageReference(
2729
identity: identity,

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,66 @@ final class WorkspaceTests: XCTestCase {
413413
}
414414
}
415415
}
416+
417+
/// Test that the explicit name given to a package is not used as its identity.
418+
func testExplicitPackageNameIsNotUsedAsPackageIdentity() throws {
419+
let sandbox = AbsolutePath("/tmp/ws/")
420+
let fs = InMemoryFileSystem()
421+
422+
let workspace = try TestWorkspace(
423+
sandbox: sandbox,
424+
fs: fs,
425+
roots: [
426+
TestPackage(
427+
name: "FooPackage",
428+
path: "foo-package",
429+
targets: [
430+
TestTarget(name: "FooTarget", dependencies: [.product(name: "BarProduct", package: "BarPackage")]),
431+
],
432+
products: [],
433+
dependencies: [
434+
TestDependency(name: "BarPackage", path: "bar-package", requirement: .upToNextMajor(from: "1.0.0")),
435+
],
436+
toolsVersion: .v5
437+
),
438+
TestPackage(
439+
name: "BarPackage",
440+
path: "bar-package",
441+
targets: [
442+
TestTarget(name: "BarTarget"),
443+
],
444+
products: [
445+
TestProduct(name: "BarProduct", targets: ["BarTarget"]),
446+
],
447+
versions: ["1.0.0", "1.0.1"]
448+
),
449+
],
450+
packages: [
451+
TestPackage(
452+
name: "BarPackage",
453+
path: "bar-package",
454+
targets: [
455+
TestTarget(name: "BarTarget"),
456+
],
457+
products: [
458+
TestProduct(name: "BarProduct", targets: ["BarTarget"]),
459+
],
460+
versions: ["1.0.0", "1.0.1"]
461+
),
462+
]
463+
)
464+
465+
workspace.checkPackageGraph(roots: ["foo-package", "bar-package"], dependencies: [PackageDependencyDescription(url: "/tmp/ws/pkgs/bar-package", requirement: .upToNextMajor(from: "1.0.0"), productFilter: .everything)]) { (graph, diagnostics) in
466+
PackageGraphTester(graph) { result in
467+
result.check(roots: "FooPackage", "BarPackage")
468+
result.check(packages: "FooPackage", "BarPackage")
469+
result.checkTarget("FooTarget") { result in result.check(dependencies: "BarProduct") }
470+
}
471+
XCTAssertNoDiagnostics(diagnostics)
472+
}
473+
}
474+
475+
416476

417477
/// Test that the remote repository is not resolved when a root package with same name is already present.
418478
func testRootAsDependency1() throws {

0 commit comments

Comments
 (0)