mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-04 05:51:31 +00:00
Unstaged changes for posterity
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* darwin-apk © 2024 Gay Pizza Specifications
|
* darwin-apk © 2024, 2025 Gay Pizza Specifications
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -31,11 +31,17 @@ public class ApkPackageGraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (id, package) in pkgIndex.packages.enumerated() {
|
for (id, package) in pkgIndex.packages.enumerated() {
|
||||||
let children: [ApkIndexRequirementRef] = package.dependencies.filter { dependency in dependency.requirement.versionSpec != .conflict }.compactMap { dependency in
|
let children: [ApkIndexRequirementRef] = package.dependencies.compactMap { dependency in
|
||||||
guard let id = provides[dependency.requirement.name] else {
|
guard dependency.requirement.versionSpec != .conflict,
|
||||||
|
let id = provides[dependency.requirement.name] else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return .init(self, id: id, constraint: .dep(version: dependency.requirement.versionSpec))
|
return .init(self, id: id, constraint: .dep(version: dependency.requirement.versionSpec))
|
||||||
|
} + package.installIf.compactMap { installIf in
|
||||||
|
guard let id = provides[installIf.requirement.name] else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return .init(self, id: id, constraint: .installIf(version: installIf.requirement.versionSpec ))
|
||||||
}
|
}
|
||||||
self._nodes.append(.init(self,
|
self._nodes.append(.init(self,
|
||||||
id: id,
|
id: id,
|
||||||
@ -54,7 +60,6 @@ public class ApkPackageGraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (ref, parents) in reverseDependencies {
|
for (ref, parents) in reverseDependencies {
|
||||||
let package = self._nodes[ref.packageID].package
|
|
||||||
self._nodes[ref.packageID].parents = parents
|
self._nodes[ref.packageID].parents = parents
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,7 +80,6 @@ extension ApkPackageGraph {
|
|||||||
for dependency in node.children {
|
for dependency in node.children {
|
||||||
let depNode = self._nodes[dependency.packageID]
|
let depNode = self._nodes[dependency.packageID]
|
||||||
if resolving.contains(depNode.packageID) {
|
if resolving.contains(depNode.packageID) {
|
||||||
print("VIA \(resolving.map({ self._nodes[$0].package.name } )) CYCLE \(node.package.name) \(depNode.package.name)")
|
|
||||||
return (node, depNode)
|
return (node, depNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,11 +123,10 @@ extension ApkPackageGraph {
|
|||||||
|
|
||||||
while !working.isEmpty {
|
while !working.isEmpty {
|
||||||
// Set of all nodes now with satisfied dependencies
|
// Set of all nodes now with satisfied dependencies
|
||||||
var set = working
|
var set = Set(working
|
||||||
.filter { _, children in children.isEmpty }
|
.filter { _, children in children.isEmpty }
|
||||||
.map(\.key)
|
.map(\.key))
|
||||||
|
|
||||||
print("set \(set.count) working \(working.count)")
|
|
||||||
// If nothing was satisfied in this loop, check for cycles
|
// If nothing was satisfied in this loop, check for cycles
|
||||||
// If no cycles exist and the working set is empty, resolve is complete
|
// If no cycles exist and the working set is empty, resolve is complete
|
||||||
if set.isEmpty {
|
if set.isEmpty {
|
||||||
@ -143,14 +146,11 @@ extension ApkPackageGraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Break cycles by setting the new resolution set to dependencies that cycled
|
// Break cycles by setting the new resolution set to dependencies that cycled
|
||||||
set = cycles.flatMap { [$0.0, $0.1] }
|
set = Set(cycles.flatMap { [$0.0, $0.1] })
|
||||||
set = Array(Set(set))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print(set.map({ $0.package.name + " " + String($0.packageID) }))
|
|
||||||
|
|
||||||
// Add installation set to list of installation sets
|
// Add installation set to list of installation sets
|
||||||
results.append(set)
|
results.append(Array(set))
|
||||||
|
|
||||||
// Filter the working set for anything that wasn't dealt with this iteration
|
// Filter the working set for anything that wasn't dealt with this iteration
|
||||||
working = working.filter { node, _ in
|
working = working.filter { node, _ in
|
||||||
@ -158,10 +158,6 @@ extension ApkPackageGraph {
|
|||||||
}.reduce(into: [ApkPackageGraphNode: Set<ApkPackageGraphNode>]()) { d, node in
|
}.reduce(into: [ApkPackageGraphNode: Set<ApkPackageGraphNode>]()) { d, node in
|
||||||
d[node.key] = node.value.subtracting(set)
|
d[node.key] = node.value.subtracting(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (what, deps) in working {
|
|
||||||
print("\(what.packageID) \(what.package.name): \(deps.map { $0.package.name + " " + String($0.packageID) })")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
@ -8,7 +8,7 @@ import Foundation
|
|||||||
public struct ApkIndexReader {
|
public struct ApkIndexReader {
|
||||||
static func read(from indexURL: URL) throws -> ApkIndex {
|
static func read(from indexURL: URL) throws -> ApkIndex {
|
||||||
let timed = false
|
let timed = false
|
||||||
var timer: ContinuousClock.Instant!
|
var timer: ContinuousClock.Instant = .now
|
||||||
let durFormat = Duration.UnitsFormatStyle(
|
let durFormat = Duration.UnitsFormatStyle(
|
||||||
allowedUnits: [ .seconds, .milliseconds ],
|
allowedUnits: [ .seconds, .milliseconds ],
|
||||||
width: .condensedAbbreviated,
|
width: .condensedAbbreviated,
|
||||||
|
@ -32,7 +32,7 @@ struct DpkGraphCommand: AsyncParsableCommand {
|
|||||||
#else
|
#else
|
||||||
do {
|
do {
|
||||||
let sorted = try graph.parallelOrderSort()
|
let sorted = try graph.parallelOrderSort()
|
||||||
print(sorted.count)
|
print(sorted)
|
||||||
} catch {
|
} catch {
|
||||||
fatalError(error.localizedDescription)
|
fatalError(error.localizedDescription)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user