mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-03 13:31:32 +00:00
Rescue graph building test into subcommand
This commit is contained in:
@ -3,20 +3,20 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ApkPackageGraph {
|
public class ApkPackageGraph {
|
||||||
let pkgIndex: ApkIndex
|
public let pkgIndex: ApkIndex
|
||||||
|
|
||||||
private var _nodes = [ApkPackageGraphNode]()
|
private var _nodes = [ApkPackageGraphNode]()
|
||||||
|
|
||||||
var nodes: [ApkPackageGraphNode] { self._nodes }
|
public var nodes: [ApkPackageGraphNode] { self._nodes }
|
||||||
var shallowIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.parents.isEmpty) }
|
public var shallowIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.parents.isEmpty) }
|
||||||
var deepIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.children.isEmpty) }
|
public var deepIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.children.isEmpty) }
|
||||||
|
|
||||||
init(index: ApkIndex) {
|
public init(index: ApkIndex) {
|
||||||
self.pkgIndex = index
|
self.pkgIndex = index
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildGraphNode() {
|
public func buildGraphNode() {
|
||||||
var provides = [String: Int]()
|
var provides = [String: Int]()
|
||||||
|
|
||||||
for (idx, package) in self.pkgIndex.packages.enumerated() {
|
for (idx, package) in self.pkgIndex.packages.enumerated() {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class ApkPackageGraphNode {
|
public class ApkPackageGraphNode {
|
||||||
private weak var graph: ApkPackageGraph!
|
private weak var graph: ApkPackageGraph!
|
||||||
let package: ApkIndexPackage
|
let package: ApkIndexPackage
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ class ApkPackageGraphNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension ApkPackageGraphNode: CustomStringConvertible {
|
extension ApkPackageGraphNode: CustomStringConvertible {
|
||||||
var description: String {
|
public var description: String {
|
||||||
var result = "node[\(self.package.name)]"
|
var result = "node[\(self.package.name)]"
|
||||||
if !self.parents.isEmpty {
|
if !self.parents.isEmpty {
|
||||||
result += ", parents[\(self.parents.lazy.map(\.description).joined(separator: ", "))]"
|
result += ", parents[\(self.parents.lazy.map(\.description).joined(separator: ", "))]"
|
||||||
|
@ -16,6 +16,7 @@ struct DarwinApkCLI: AsyncParsableCommand {
|
|||||||
DpkUpdateCommand.self,
|
DpkUpdateCommand.self,
|
||||||
DpkUpgradeCommand.self,
|
DpkUpgradeCommand.self,
|
||||||
DpkSearchCommand.self,
|
DpkSearchCommand.self,
|
||||||
DpkInfoCommand.self
|
DpkInfoCommand.self,
|
||||||
|
DpkGraphCommand.self
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import ArgumentParser
|
||||||
|
import darwin_apk
|
||||||
|
|
||||||
public struct ApkIndexUpdater {
|
struct DpkGraphCommand: AsyncParsableCommand {
|
||||||
public var repositories: [ApkIndexRepository]
|
static let configuration = CommandConfiguration(commandName: "graph")
|
||||||
|
|
||||||
public init() {
|
func run() async throws(ExitCode) {
|
||||||
self.repositories = []
|
|
||||||
}
|
|
||||||
|
|
||||||
public func buildGraph() async {
|
|
||||||
let graph: ApkPackageGraph
|
let graph: ApkPackageGraph
|
||||||
do {
|
do {
|
||||||
graph = ApkPackageGraph(index: try await ApkIndexReader.resolve(self.repositories, fetch: .lazy))
|
let localRepositories = try await ApkRepositoriesConfig()
|
||||||
|
graph = ApkPackageGraph(index: try await ApkIndexReader.resolve(localRepositories.repositories, fetch: .lazy))
|
||||||
graph.buildGraphNode()
|
graph.buildGraphNode()
|
||||||
|
|
||||||
try graph.pkgIndex.description.write(to: URL(filePath: "packages.txt"), atomically: false, encoding: .utf8)
|
try graph.pkgIndex.description.write(to: URL(filePath: "packages.txt"), atomically: false, encoding: .utf8)
|
Reference in New Issue
Block a user