mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-03 21:41:31 +00:00
Rescue graph building test into subcommand
This commit is contained in:
@ -3,20 +3,20 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
class ApkPackageGraph {
|
||||
let pkgIndex: ApkIndex
|
||||
public class ApkPackageGraph {
|
||||
public let pkgIndex: ApkIndex
|
||||
|
||||
private var _nodes = [ApkPackageGraphNode]()
|
||||
|
||||
var nodes: [ApkPackageGraphNode] { self._nodes }
|
||||
var shallowIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.parents.isEmpty) }
|
||||
var deepIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.children.isEmpty) }
|
||||
public var nodes: [ApkPackageGraphNode] { self._nodes }
|
||||
public var shallowIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.parents.isEmpty) }
|
||||
public var deepIsolates: [ApkPackageGraphNode] { self._nodes.filter(\.children.isEmpty) }
|
||||
|
||||
init(index: ApkIndex) {
|
||||
public init(index: ApkIndex) {
|
||||
self.pkgIndex = index
|
||||
}
|
||||
|
||||
func buildGraphNode() {
|
||||
public func buildGraphNode() {
|
||||
var provides = [String: Int]()
|
||||
|
||||
for (idx, package) in self.pkgIndex.packages.enumerated() {
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class ApkPackageGraphNode {
|
||||
public class ApkPackageGraphNode {
|
||||
private weak var graph: ApkPackageGraph!
|
||||
let package: ApkIndexPackage
|
||||
|
||||
@ -21,7 +21,7 @@ class ApkPackageGraphNode {
|
||||
}
|
||||
|
||||
extension ApkPackageGraphNode: CustomStringConvertible {
|
||||
var description: String {
|
||||
public var description: String {
|
||||
var result = "node[\(self.package.name)]"
|
||||
if !self.parents.isEmpty {
|
||||
result += ", parents[\(self.parents.lazy.map(\.description).joined(separator: ", "))]"
|
||||
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* darwin-apk © 2024 Gay Pizza Specifications
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct ApkIndexUpdater {
|
||||
public var repositories: [ApkIndexRepository]
|
||||
|
||||
public init() {
|
||||
self.repositories = []
|
||||
}
|
||||
|
||||
public func buildGraph() async {
|
||||
let graph: ApkPackageGraph
|
||||
do {
|
||||
graph = ApkPackageGraph(index: try await ApkIndexReader.resolve(self.repositories, fetch: .lazy))
|
||||
graph.buildGraphNode()
|
||||
|
||||
try graph.pkgIndex.description.write(to: URL(filePath: "packages.txt"), atomically: false, encoding: .utf8)
|
||||
} catch {
|
||||
fatalError(error.localizedDescription)
|
||||
}
|
||||
|
||||
if var out = TextFileWriter(URL(filePath: "shallowIsolates.txt")) {
|
||||
for node in graph.shallowIsolates { print(node, to: &out) }
|
||||
}
|
||||
if var out = TextFileWriter(URL(filePath: "deepIsolates.txt")) {
|
||||
for node in graph.deepIsolates { print(node, to: &out) }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* darwin-apk © 2024 Gay Pizza Specifications
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import Darwin
|
||||
|
||||
struct TextFileWriter: TextOutputStream {
|
||||
private var _hnd: FileHandle
|
||||
|
||||
init?(_ to: URL) {
|
||||
let file = open(to.path(), O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, 0o644)
|
||||
guard file >= 0 else {
|
||||
return nil
|
||||
}
|
||||
self._hnd = FileHandle(fileDescriptor: file, closeOnDealloc: true)
|
||||
}
|
||||
|
||||
mutating func write(_ string: String) {
|
||||
if let data = string.data(using: .utf8) {
|
||||
try? self._hnd.write(contentsOf: data)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func close() throws {
|
||||
try self._hnd.close()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user