Skip to content

Improve Resolver Determinism #3862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/PackageGraph/PackageGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private func createResolvedPackages(
metadata: package.diagnosticsMetadata
)

var dependencies = [PackageIdentity: ResolvedPackageBuilder]()
var dependencies = OrderedDictionary<PackageIdentity, ResolvedPackageBuilder>()
var dependenciesByNameForTargetDependencyResolution = [String: ResolvedPackageBuilder]()

// Establish the manifest-declared package dependencies.
Expand All @@ -257,7 +257,7 @@ private func createResolvedPackages(
// check if this resolved package already listed in the dependencies
// this means that the dependencies share the same identity
// FIXME: this works but the way we find out about this is based on a side effect, need to improve it
guard !dependencies.keys.contains(resolvedPackage.package.identity) else {
guard dependencies[resolvedPackage.package.identity] == nil else {
let error = PackageGraphError.dependencyAlreadySatisfiedByIdentifier(
package: package.identity.description,
dependencyLocation: dependencyLocation,
Expand Down
92 changes: 92 additions & 0 deletions Tests/PackageGraphTests/PackageGraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,98 @@ class PackageGraphTests: XCTestCase {
})
}

func testResolutionDeterminism() throws {
let fileSystem = InMemoryFileSystem(
emptyFiles: [
"/A/Sources/A/A.swift",
"/B/Sources/B/B.swift",
"/C/Sources/C/C.swift",
"/D/Sources/D/D.swift",
"/E/Sources/E/E.swift",
"/F/Sources/F/F.swift",
]
)

let observability = ObservabilitySystem.makeForTesting()
_ = try loadPackageGraph(
fs: fileSystem,
manifests: [
Manifest.createRootManifest(
name: "A",
path: .init("/A"),
dependencies: [
.localSourceControl(path: .init("/B"), requirement: .upToNextMajor(from: "1.0.0")),
.localSourceControl(path: .init("/C"), requirement: .upToNextMajor(from: "1.0.0")),
.localSourceControl(path: .init("/D"), requirement: .upToNextMajor(from: "1.0.0")),
.localSourceControl(path: .init("/E"), requirement: .upToNextMajor(from: "1.0.0")),
.localSourceControl(path: .init("/F"), requirement: .upToNextMajor(from: "1.0.0")),
],
targets: [
TargetDescription(name: "A", dependencies: []),
]),
Manifest.createFileSystemManifest(
name: "B",
path: .init("/B"),
products: [
ProductDescription(name: "B", type: .library(.automatic), targets: ["B"])
],
targets: [
TargetDescription(name: "B"),
]
),
Manifest.createFileSystemManifest(
name: "C",
path: .init("/C"),
products: [
ProductDescription(name: "C", type: .library(.automatic), targets: ["C"])
],
targets: [
TargetDescription(name: "C"),
]
),
Manifest.createFileSystemManifest(
name: "D",
path: .init("/D"),
products: [
ProductDescription(name: "D", type: .library(.automatic), targets: ["D"])
],
targets: [
TargetDescription(name: "D"),
]
),
Manifest.createFileSystemManifest(
name: "E",
path: .init("/E"),
products: [
ProductDescription(name: "E", type: .library(.automatic), targets: ["E"])
],
targets: [
TargetDescription(name: "E"),
]
),
Manifest.createFileSystemManifest(
name: "F",
path: .init("/F"),
products: [
ProductDescription(name: "F", type: .library(.automatic), targets: ["F"])
],
targets: [
TargetDescription(name: "F"),
]
),
],
observabilityScope: observability.topScope
)

testDiagnostics(observability.diagnostics) { result in
result.check(diagnostic: "dependency 'b' is not used by any target", severity: .warning)
result.check(diagnostic: "dependency 'c' is not used by any target", severity: .warning)
result.check(diagnostic: "dependency 'd' is not used by any target", severity: .warning)
result.check(diagnostic: "dependency 'e' is not used by any target", severity: .warning)
result.check(diagnostic: "dependency 'f' is not used by any target", severity: .warning)
}
}

func testTargetDependencies_Pre52() throws {
let fs = InMemoryFileSystem(emptyFiles:
"/Foo/Sources/Foo/foo.swift",
Expand Down