Skip to content

NFC: Rename PinsStore to PackageResolvedStore #7839

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 10 commits into from
Aug 5, 2024
8 changes: 4 additions & 4 deletions Sources/Commands/PackageCommands/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ extension SwiftPackageCommand {
observabilityScope: swiftCommandState.observabilityScope
)

if self.dryRun, let changes = changes, let pinsStore = swiftCommandState.observabilityScope.trap({ try workspace.pinsStore.load() }){
self.logPackageChanges(changes: changes, pins: pinsStore)
if self.dryRun, let changes = changes, let resolvedPackagesStore = swiftCommandState.observabilityScope.trap({ try workspace.resolvedPackagesStore.load() }){
self.logPackageChanges(changes: changes, store: resolvedPackagesStore)
}

if !self.dryRun {
Expand All @@ -55,12 +55,12 @@ extension SwiftPackageCommand {
}
}

private func logPackageChanges(changes: [(PackageReference, Workspace.PackageStateChange)], pins: PinsStore) {
private func logPackageChanges(changes: [(PackageReference, Workspace.PackageStateChange)], store: ResolvedPackagesStore) {
let changes = changes.filter { $0.1 != .unchanged }

var report = "\(changes.count) dependenc\(changes.count == 1 ? "y has" : "ies have") changed\(changes.count > 0 ? ":" : ".")"
for (package, change) in changes {
let currentVersion = pins.pins[package.identity]?.state.description ?? ""
let currentVersion = store.resolvedPackages[package.identity]?.state.description ?? ""
switch change {
case let .added(state):
report += "\n"
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageGraph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ add_library(PackageGraph
PackageGraphRoot.swift
PackageModel+Extensions.swift
PackageRequirement.swift
PinsStore.swift
ResolvedPackagesStore.swift
TraitConfiguration.swift
Resolution/PubGrub/Assignment.swift
Resolution/PubGrub/ContainerProvider.swift
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageGraph/PackageGraphRoot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public struct PackageGraphRoot {

// FIXME: Deprecate special casing once the manifest supports declaring used executable products.
// Special casing explicit products like this is necessary to pass the test suite and satisfy backwards compatibility.
// However, changing the dependencies based on the command line arguments may force pins to temporarily change,
// However, changing the dependencies based on the command line arguments may force `Package.resolved` to temporarily change,
// which can become a nuisance.
// Such pin switching can currently be worked around by declaring the executable product as a dependency of a dummy target.
// But in the future it might be worth providing a way of declaring them in the manifest without a dummy target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ final class ContainerProvider {
/// Whether to perform update (git fetch) on existing cloned repositories or not.
private let skipUpdate: Bool

/// Reference to the pins store.
private let pins: PinsStore.Pins
/// `Package.resolved` file representation.
private let resolvedPackages: ResolvedPackagesStore.ResolvedPackages

/// Observability scope to emit diagnostics with
private let observabilityScope: ObservabilityScope
Expand All @@ -39,12 +39,12 @@ final class ContainerProvider {
init(
provider underlying: PackageContainerProvider,
skipUpdate: Bool,
pins: PinsStore.Pins,
resolvedPackages: ResolvedPackagesStore.ResolvedPackages,
observabilityScope: ObservabilityScope
) {
self.underlying = underlying
self.skipUpdate = skipUpdate
self.pins = pins
self.resolvedPackages = resolvedPackages
self.observabilityScope = observabilityScope
}

Expand Down Expand Up @@ -87,7 +87,7 @@ final class ContainerProvider {
on: .sharedConcurrent
) { result in
let result = result.tryMap { container -> PubGrubPackageContainer in
let pubGrubContainer = PubGrubPackageContainer(underlying: container, pins: self.pins)
let pubGrubContainer = PubGrubPackageContainer(underlying: container, resolvedPackages: self.resolvedPackages)
// only cache positive results
self.containersCache[package] = pubGrubContainer
return pubGrubContainer
Expand Down Expand Up @@ -118,7 +118,7 @@ final class ContainerProvider {
defer { self.prefetches[identifier]?.leave() }
// only cache positive results
if case .success(let container) = result {
self.containersCache[identifier] = PubGrubPackageContainer(underlying: container, pins: self.pins)
self.containersCache[identifier] = PubGrubPackageContainer(underlying: container, resolvedPackages: self.resolvedPackages)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public struct PubGrubDependencyResolver {
}
}

/// Reference to the pins store, if provided.
private let pins: PinsStore.Pins
/// `Package.resolved` representation.
private let resolvedPackages: ResolvedPackagesStore.ResolvedPackages

/// The container provider used to load package containers.
private let provider: ContainerProvider
Expand All @@ -119,22 +119,46 @@ public struct PubGrubDependencyResolver {
/// Resolver delegate
private let delegate: DependencyResolverDelegate?

@available(*,
deprecated,
renamed: "init(provider:resolvedPackages:skipDependenciesUpdates:prefetchBasedOnResolvedFile:observabilityScope:delegate:)",
message: "Renamed for consistency with the actual name of the feature"
)
@_disfavoredOverload
public init(
provider: PackageContainerProvider,
pins: PinsStore.Pins = [:],
pins: ResolvedPackagesStore.ResolvedPackages = [:],
skipDependenciesUpdates: Bool = false,
prefetchBasedOnResolvedFile: Bool = false,
observabilityScope: ObservabilityScope,
delegate: DependencyResolverDelegate? = nil
) {
self.init(
provider: provider,
resolvedPackages: pins,
skipDependenciesUpdates: skipDependenciesUpdates,
prefetchBasedOnResolvedFile: prefetchBasedOnResolvedFile,
observabilityScope: observabilityScope,
delegate: delegate
)
}

public init(
provider: PackageContainerProvider,
resolvedPackages: ResolvedPackagesStore.ResolvedPackages = [:],
skipDependenciesUpdates: Bool = false,
prefetchBasedOnResolvedFile: Bool = false,
observabilityScope: ObservabilityScope,
delegate: DependencyResolverDelegate? = nil
) {
self.packageContainerProvider = provider
self.pins = pins
self.resolvedPackages = resolvedPackages
self.skipDependenciesUpdates = skipDependenciesUpdates
self.prefetchBasedOnResolvedFile = prefetchBasedOnResolvedFile
self.provider = ContainerProvider(
provider: self.packageContainerProvider,
skipUpdate: self.skipDependenciesUpdates,
pins: self.pins,
resolvedPackages: self.resolvedPackages,
observabilityScope: observabilityScope
)
self.delegate = delegate
Expand All @@ -161,15 +185,15 @@ public struct PubGrubDependencyResolver {
return .success(bindings)
} catch {
// If version solving failing, build the user-facing diagnostic.
if let pubGrubError = error as? PubgrubError, let rootCause = pubGrubError.rootCause, let incompatibilities = pubGrubError.incompatibilities {
if let pubGrubError = error as? PubGrubError, let rootCause = pubGrubError.rootCause, let incompatibilities = pubGrubError.incompatibilities {
do {
var builder = DiagnosticReportBuilder(
root: root,
incompatibilities: incompatibilities,
provider: self.provider
)
let diagnostic = try builder.makeErrorReport(for: rootCause)
return .failure(PubgrubError.unresolvable(diagnostic))
return .failure(PubGrubError.unresolvable(diagnostic))
} catch {
// failed to construct the report, will report the original error
return .failure(error)
Expand All @@ -191,10 +215,10 @@ public struct PubGrubDependencyResolver {
// We avoid prefetching packages that are overridden since
// otherwise we'll end up creating a repository container
// for them.
let pins = self.pins.values
let resolvedPackageReferences = self.resolvedPackages.values
.map(\.packageRef)
.filter { !inputs.overriddenPackages.keys.contains($0) }
self.provider.prefetch(containers: pins)
self.provider.prefetch(containers: resolvedPackageReferences)
}

let state = State(root: root, overriddenPackages: inputs.overriddenPackages)
Expand Down Expand Up @@ -357,7 +381,7 @@ public struct PubGrubDependencyResolver {
case .revision(let existingRevision, let branch)?:
// If this branch-based package was encountered before, ensure the references match.
if (branch ?? existingRevision) != revision {
throw PubgrubError.unresolvable("\(package.identity) is required using two different revision-based requirements (\(existingRevision) and \(revision)), which is not supported")
throw PubGrubError.unresolvable("\(package.identity) is required using two different revision-based requirements (\(existingRevision) and \(revision)), which is not supported")
} else {
// Otherwise, continue since we've already processed this constraint. Any cycles will be diagnosed separately.
continue
Expand All @@ -377,7 +401,7 @@ public struct PubGrubDependencyResolver {
// latest commit on that branch. Note that if this revision-based dependency is
// already a commit, then its pin entry doesn't matter in practice.
let revisionForDependencies: String
if case .branch(revision, let pinRevision) = self.pins[package.identity]?.state {
if case .branch(revision, let pinRevision) = self.resolvedPackages[package.identity]?.state {
revisionForDependencies = pinRevision

// Mark the package as overridden with the pinned revision and record the branch as well.
Expand Down Expand Up @@ -632,7 +656,7 @@ public struct PubGrubDependencyResolver {
}

self.delegate?.failedToResolve(incompatibility: incompatibility)
throw PubgrubError._unresolvable(incompatibility, state.incompatibilities)
throw PubGrubError._unresolvable(incompatibility, state.incompatibilities)
}

/// Does a given incompatibility specify that version solving has entirely
Expand Down Expand Up @@ -747,7 +771,7 @@ internal enum LogLocation: String {
}

public extension PubGrubDependencyResolver {
enum PubgrubError: Swift.Error, CustomStringConvertible {
enum PubGrubError: Swift.Error, CustomStringConvertible {
case _unresolvable(Incompatibility, [DependencyResolutionNode: [Incompatibility]])
case unresolvable(String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ final class PubGrubPackageContainer {
/// The underlying package container.
let underlying: PackageContainer

/// Reference to the pins map.
private let pins: PinsStore.Pins
/// `Package.resolved` in-memory representation.
private let resolvedPackages: ResolvedPackagesStore.ResolvedPackages

init(underlying: PackageContainer, pins: PinsStore.Pins) {
init(underlying: PackageContainer, resolvedPackages: ResolvedPackagesStore.ResolvedPackages) {
self.underlying = underlying
self.pins = pins
self.resolvedPackages = resolvedPackages
}

var package: PackageReference {
Expand All @@ -36,7 +36,7 @@ final class PubGrubPackageContainer {

/// Returns the pinned version for this package, if any.
var pinnedVersion: Version? {
switch self.pins[self.underlying.package.identity]?.state {
switch self.resolvedPackages[self.underlying.package.identity]?.state {
case .version(let version, _):
version
default:
Expand Down
Loading