Factor out resolution responsibilities

This commit is contained in:
2025-07-11 20:40:23 +10:00
parent 08a05a44eb
commit 1ba8e14ef4
5 changed files with 59 additions and 83 deletions

View File

@ -10,23 +10,10 @@ public class ApkPackageGraphNode {
public var parentIDs = [ApkIndex.Index]()
public var children: [ChildRef]
private weak var _graph: ApkPackageGraph?
public var package: ApkIndexPackage {
self._graph!.pkgIndex.packages[self.packageID]
}
public var parents: [ApkIndexPackage] {
self.parentIDs.map { index in self._graph!.pkgIndex.packages[index] }
}
public var childPackages: [ApkIndexPackage] {
self.children.map { child in self._graph!.pkgIndex.packages[child.packageID] }
}
@inlinable public var isShallow: Bool { self.parentIDs.isEmpty }
@inlinable public var isDeep: Bool { self.children.isEmpty }
internal init(_ graph: ApkPackageGraph, id: Int, children: [ChildRef]) {
self._graph = graph
self.packageID = id
self.children = children
}
@ -54,31 +41,8 @@ extension ApkPackageGraphNode {
}
}
extension ApkPackageGraphNode: CustomStringConvertible {
public var description: String {
let package = self.package
var result = " \(package.nameDescription):\n"
if !self.parentIDs.isEmpty {
result += " parents:\n"
for parent in self.parents {
result += " \(parent.nameDescription)\n"
}
}
if !self.children.isEmpty {
result += " children:\n"
for child in self.children {
let childPackage = self._graph!.pkgIndex.packages[child.packageID]
result += " "
switch child.constraint {
case .dependency: result += "dep="
case .installIf: result += "installIf="
}
result += childPackage.nameDescription
result += ", "
result += child.versionSpec.description
result += "\n"
}
}
return result
extension ApkIndex {
public func at(node: ApkPackageGraphNode) -> ApkIndexPackage {
self.packages[node.packageID]
}
}