mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-06 22:51:34 +00:00
Factor out resolution responsibilities
This commit is contained in:
@ -11,23 +11,23 @@ struct DpkGraphCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(commandName: "graph")
|
||||
|
||||
func run() async throws(ExitCode) {
|
||||
let graph: ApkPackageGraph
|
||||
do {
|
||||
let localRepositories = try await ApkRepositoriesConfig()
|
||||
|
||||
var timerStart = DispatchTime.now()
|
||||
graph = ApkPackageGraph(index:
|
||||
try await ApkIndexReader.resolve(localRepositories.repositories, fetch: .lazy))
|
||||
let pkgIndex = try await ApkIndexReader.resolve(localRepositories.repositories, fetch: .lazy)
|
||||
print("Index build took \(timerStart.distance(to: .now()).seconds) seconds")
|
||||
try graph.pkgIndex.description.write(to: URL(filePath: "packages.txt"), atomically: false, encoding: .utf8)
|
||||
try pkgIndex.description.write(to: URL(filePath: "packages.txt"), atomically: false, encoding: .utf8)
|
||||
|
||||
timerStart = DispatchTime.now()
|
||||
graph.buildGraphNode()
|
||||
let providerCache = ApkIndexProviderCache(index: pkgIndex)
|
||||
let graph = ApkPackageGraph()
|
||||
graph.buildGraphNode(index: pkgIndex, providers: providerCache)
|
||||
print("Graph build took \(timerStart.distance(to: .now()).seconds) seconds")
|
||||
|
||||
try graph.shallowIsolates.map { $0.package.nameDescription }.joined(separator: "\n")
|
||||
try graph.shallowIsolates.map { pkgIndex.at(node: $0).nameDescription }.joined(separator: "\n")
|
||||
.write(to: URL(filePath: "shallowIsolates.txt"), atomically: false, encoding: .utf8)
|
||||
try graph.deepIsolates.map { $0.package.nameDescription }.joined(separator: "\n")
|
||||
try graph.deepIsolates.map { pkgIndex.at(node: $0).nameDescription }.joined(separator: "\n")
|
||||
.write(to: URL(filePath: "deepIsolates.txt"), atomically: false, encoding: .utf8)
|
||||
|
||||
timerStart = DispatchTime.now()
|
||||
@ -37,17 +37,19 @@ struct DpkGraphCommand: AsyncParsableCommand {
|
||||
|
||||
if var out = TextFileWriter(URL(filePath: "sorted.txt")) {
|
||||
for (i, set) in sorted.enumerated() {
|
||||
print("\(i):\n", to: &out)
|
||||
print("\(i):", to: &out)
|
||||
for item in set {
|
||||
print("\(item.description)", to: &out)
|
||||
let pkg = pkgIndex.at(node: item)
|
||||
print(" \(pkg.nameDescription)", to: &out)
|
||||
}
|
||||
print(to: &out)
|
||||
}
|
||||
}
|
||||
#else
|
||||
let sorted = try graph.orderSort()
|
||||
print("Order sort took \(timerStart.distance(to: .now()).seconds) seconds")
|
||||
|
||||
try sorted.map(String.init).joined(separator: "\n")
|
||||
try sorted.map { node in pkgIndex.at(node: node).nameDescription }.joined(separator: "\n")
|
||||
.write(to: URL(filePath: "sorted.txt"), atomically: false, encoding: .utf8)
|
||||
#endif
|
||||
} catch {
|
||||
@ -64,8 +66,7 @@ fileprivate extension DispatchTimeInterval {
|
||||
case .microseconds(let value): Double(value) / 1_000_000
|
||||
case .nanoseconds(let value): Double(value) / 1_000_000_000
|
||||
case .never: .infinity
|
||||
@unknown default:
|
||||
fatalError("Unsupported")
|
||||
@unknown default: fatalError("Unsupported")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user