2024-11-10 17:51:53 +11:00
|
|
|
/*
|
|
|
|
* darwin-apk © 2024 Gay Pizza Specifications
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2024-11-08 21:22:33 +11:00
|
|
|
|
|
|
|
import Foundation
|
2024-11-23 21:02:52 +11:00
|
|
|
import ArgumentParser
|
|
|
|
import darwin_apk
|
2024-11-08 21:22:33 +11:00
|
|
|
|
2024-11-23 21:02:52 +11:00
|
|
|
struct DpkGraphCommand: AsyncParsableCommand {
|
|
|
|
static let configuration = CommandConfiguration(commandName: "graph")
|
2024-11-08 21:22:33 +11:00
|
|
|
|
2024-11-23 21:02:52 +11:00
|
|
|
func run() async throws(ExitCode) {
|
2024-11-11 21:06:37 +11:00
|
|
|
let graph: ApkPackageGraph
|
2024-11-08 21:22:33 +11:00
|
|
|
do {
|
2024-11-23 21:02:52 +11:00
|
|
|
let localRepositories = try await ApkRepositoriesConfig()
|
2024-11-11 21:06:37 +11:00
|
|
|
|
2025-07-10 05:37:24 +10:00
|
|
|
var timerStart = DispatchTime.now()
|
|
|
|
var pkgIndex = try await ApkIndexReader.resolve(localRepositories.repositories, fetch: .lazy)
|
|
|
|
print("Index build took \(timerStart.distance(to: .now()).seconds) seconds")
|
|
|
|
try pkgIndex.description.write(to: URL(filePath: "packages.txt"), atomically: false, encoding: .utf8)
|
|
|
|
|
|
|
|
timerStart = DispatchTime.now()
|
|
|
|
try graph = ApkPackageGraph(from: &pkgIndex)
|
|
|
|
print("Graph build took \(timerStart.distance(to: .now()).seconds) seconds")
|
|
|
|
|
|
|
|
try graph.shallowIsolates.map { pkgIndex.packages[$0].nameDescription }.joined(separator: "\n")
|
|
|
|
.write(to: URL(filePath: "shallowIsolates.txt"), atomically: false, encoding: .utf8)
|
|
|
|
try graph.deepIsolates.map { pkgIndex.packages[$0].nameDescription }.joined(separator: "\n")
|
|
|
|
.write(to: URL(filePath: "deepIsolates.txt"), atomically: false, encoding: .utf8)
|
|
|
|
|
|
|
|
let sorted = try graph.sorted(breakCycles: false)
|
|
|
|
try sorted.map { pkgIndex.packages[$0].nameDescription }.joined(separator: "\n")
|
|
|
|
.write(to: URL(filePath: "sorted.txt"), atomically: false, encoding: .utf8)
|
|
|
|
|
2024-11-08 21:22:33 +11:00
|
|
|
} catch {
|
|
|
|
fatalError(error.localizedDescription)
|
|
|
|
}
|
2025-07-10 05:37:24 +10:00
|
|
|
}
|
|
|
|
}
|
2024-11-11 21:06:37 +11:00
|
|
|
|
2025-07-10 05:37:24 +10:00
|
|
|
fileprivate extension DispatchTimeInterval {
|
|
|
|
var seconds: Double {
|
|
|
|
switch self {
|
|
|
|
case .seconds(let value): Double(value)
|
|
|
|
case .milliseconds(let value): Double(value) / 1_000
|
|
|
|
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")
|
2024-11-11 23:08:01 +11:00
|
|
|
}
|
2024-11-08 21:22:33 +11:00
|
|
|
}
|
|
|
|
}
|