Skip to content

Commit fcebba0

Browse files
committed
PackageGraph: make some of the private API more public
This extends the visibility of some of the private implementation to the package level to allow use for testing without `@testable` imports.
1 parent ff7ea75 commit fcebba0

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

Sources/PackageGraph/ModulesGraph.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import protocol Basics.FileSystem
1919
import class Basics.ObservabilityScope
2020
import struct Basics.IdentifiableSet
2121

22-
enum PackageGraphError: Swift.Error {
22+
package enum PackageGraphError: Swift.Error {
2323
/// Indicates a non-root package with no modules.
2424
case noModules(Package)
2525

@@ -379,7 +379,7 @@ extension PackageGraphError: CustomStringConvertible {
379379
}
380380
}
381381

382-
enum GraphError: Error {
382+
package enum GraphError: Error {
383383
/// A cycle was detected in the input.
384384
case unexpectedCycle
385385
}
@@ -401,7 +401,7 @@ enum GraphError: Error {
401401
///
402402
/// - Complexity: O(v + e) where (v, e) are the number of vertices and edges
403403
/// reachable from the input nodes via the relation.
404-
func topologicalSortIdentifiable<T: Identifiable>(
404+
package func topologicalSortIdentifiable<T: Identifiable>(
405405
_ nodes: [T], successors: (T) throws -> [T]
406406
) throws -> [T] {
407407
// Implements a topological sort via recursion and reverse postorder DFS.

Sources/PackageGraph/Resolution/PubGrub/PubGrubDependencyResolver.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct PubGrubDependencyResolver {
2626
public typealias Constraint = PackageContainerConstraint
2727

2828
/// the mutable state that get computed
29-
internal final class State {
29+
package final class State {
3030
/// The root package reference.
3131
let root: DependencyResolutionNode
3232

@@ -44,7 +44,7 @@ public struct PubGrubDependencyResolver {
4444

4545
private let lock = NSLock()
4646

47-
init(root: DependencyResolutionNode,
47+
package init(root: DependencyResolutionNode,
4848
overriddenPackages: [PackageReference: (version: BoundVersion, products: ProductFilter)] = [:],
4949
solution: PartialSolution = PartialSolution())
5050
{
@@ -53,7 +53,7 @@ public struct PubGrubDependencyResolver {
5353
self.solution = solution
5454
}
5555

56-
func addIncompatibility(_ incompatibility: Incompatibility, at location: LogLocation) {
56+
package func addIncompatibility(_ incompatibility: Incompatibility, at location: LogLocation) {
5757
self.lock.withLock {
5858
// log("incompat: \(incompatibility) \(location)")
5959
for package in incompatibility.terms.map(\.node) {
@@ -69,7 +69,7 @@ public struct PubGrubDependencyResolver {
6969
}
7070

7171
/// Find all incompatibilities containing a positive term for a given package.
72-
func positiveIncompatibilities(for node: DependencyResolutionNode) -> [Incompatibility]? {
72+
package func positiveIncompatibilities(for node: DependencyResolutionNode) -> [Incompatibility]? {
7373
self.lock.withLock {
7474
guard let all = self.incompatibilities[node] else {
7575
return nil
@@ -80,15 +80,15 @@ public struct PubGrubDependencyResolver {
8080
}
8181
}
8282

83-
func decide(_ node: DependencyResolutionNode, at version: Version) {
83+
package func decide(_ node: DependencyResolutionNode, at version: Version) {
8484
let term = Term(node, .exact(version))
8585
self.lock.withLock {
8686
assert(term.isValidDecision(for: self.solution))
8787
self.solution.decide(node, at: version)
8888
}
8989
}
9090

91-
func derive(_ term: Term, cause: Incompatibility) {
91+
package func derive(_ term: Term, cause: Incompatibility) {
9292
self.lock.withLock {
9393
self.solution.derive(term, cause: cause)
9494
}
@@ -209,7 +209,7 @@ public struct PubGrubDependencyResolver {
209209
/// Find a set of dependencies that fit the given constraints. If dependency
210210
/// resolution is unable to provide a result, an error is thrown.
211211
/// - Warning: It is expected that the root package reference has been set before this is called.
212-
internal func solve(root: DependencyResolutionNode, constraints: [Constraint]) async throws -> (bindings: [DependencyResolverBinding], state: State) {
212+
package func solve(root: DependencyResolutionNode, constraints: [Constraint]) async throws -> (bindings: [DependencyResolverBinding], state: State) {
213213
// first process inputs
214214
let inputs = try await self.processInputs(root: root, with: constraints)
215215

@@ -511,7 +511,7 @@ public struct PubGrubDependencyResolver {
511511
/// partial solution.
512512
/// If a conflict is found, the conflicting incompatibility is returned to
513513
/// resolve the conflict on.
514-
internal func propagate(state: State, node: DependencyResolutionNode) throws {
514+
package func propagate(state: State, node: DependencyResolutionNode) throws {
515515
var changed: OrderedCollections.OrderedSet<DependencyResolutionNode> = [node]
516516

517517
while !changed.isEmpty {
@@ -575,7 +575,7 @@ public struct PubGrubDependencyResolver {
575575
// Based on:
576576
// https://github.com/dart-lang/pub/tree/master/doc/solver.md#conflict-resolution
577577
// https://github.com/dart-lang/pub/blob/master/lib/src/solver/version_solver.dart#L201
578-
internal func resolve(state: State, conflict: Incompatibility) throws -> Incompatibility {
578+
package func resolve(state: State, conflict: Incompatibility) throws -> Incompatibility {
579579
self.delegate?.conflict(conflict: conflict)
580580

581581
var incompatibility = conflict
@@ -703,7 +703,7 @@ public struct PubGrubDependencyResolver {
703703
}
704704
}
705705

706-
internal func makeDecision(
706+
package func makeDecision(
707707
state: State
708708
) async throws -> DependencyResolutionNode? {
709709
// If there are no more undecided terms, version solving is complete.
@@ -771,7 +771,7 @@ public struct PubGrubDependencyResolver {
771771
}
772772
}
773773

774-
internal enum LogLocation: String {
774+
package enum LogLocation: String {
775775
case topLevel = "top level"
776776
case unitPropagation = "unit propagation"
777777
case decisionMaking = "decision making"

Sources/PackageGraph/Resolution/PubGrub/PubGrubPackageContainer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import struct TSCUtility.Version
1919

2020
/// A container for an individual package. This enhances PackageContainer to add PubGrub specific
2121
/// logic which is mostly related to computing incompatibilities at a particular version.
22-
final class PubGrubPackageContainer {
22+
package final class PubGrubPackageContainer {
2323
/// The underlying package container.
2424
let underlying: PackageContainer
2525

2626
/// `Package.resolved` in-memory representation.
2727
private let resolvedPackages: ResolvedPackagesStore.ResolvedPackages
2828

29-
init(underlying: PackageContainer, resolvedPackages: ResolvedPackagesStore.ResolvedPackages) {
29+
package init(underlying: PackageContainer, resolvedPackages: ResolvedPackagesStore.ResolvedPackages) {
3030
self.underlying = underlying
3131
self.resolvedPackages = resolvedPackages
3232
}
@@ -150,7 +150,7 @@ final class PubGrubPackageContainer {
150150
}
151151

152152
/// Returns the incompatibilities of a package at the given version.
153-
func incompatibilites(
153+
package func incompatibilites(
154154
at version: Version,
155155
node: DependencyResolutionNode,
156156
overriddenPackages: [PackageReference: (version: BoundVersion, products: ProductFilter)],

Sources/PackageGraph/Resolution/ResolvedModule.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ extension ResolvedModule: Identifiable {
289289

290290
public let moduleName: String
291291
let packageIdentity: PackageIdentity
292+
293+
package init(moduleName: String, packageIdentity: PackageIdentity) {
294+
self.moduleName = moduleName
295+
self.packageIdentity = packageIdentity
296+
}
292297
}
293298

294299
public var id: ID {

Sources/PackageGraph/Resolution/ResolvedProduct.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ extension ResolvedProduct: Identifiable {
196196
public struct ID: Hashable {
197197
public let productName: String
198198
let packageIdentity: PackageIdentity
199+
200+
package init(productName: String, packageIdentity: PackageIdentity) {
201+
self.productName = productName
202+
self.packageIdentity = packageIdentity
203+
}
199204
}
200205

201206
public var id: ID {

0 commit comments

Comments
 (0)