make ApkIndexDependency conform to ApkIndexRequirementRef

dunno if this is necessary for the graph to work but we'll see
This commit is contained in:
2024-11-10 21:00:07 +11:00
parent d6b0acf807
commit e7fc47d640
6 changed files with 17 additions and 28 deletions

View File

@ -3,22 +3,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
enum ApkVersionSpecification: Equatable {
enum ApkVersionSpecification: Equatable, Hashable {
case any
case constraint(op: Operator, version: String)
case conflict
}
extension ApkVersionSpecification: CustomStringConvertible {
var description: String {
switch self {
case .any: ""
case .conflict: "!"
case .constraint(let op, let version): "\(op)\(version)"
}
}
}
extension ApkVersionSpecification {
enum Operator: Equatable {
case equals

View File

@ -9,8 +9,9 @@ struct ApkIndexDependency: ApkIndexRequirementRef {
let name: String
let versionSpec: ApkVersionSpecification
init(extract: String) throws(ApkRequirement.ParseError) {
(self.name, self.versionSpec) = try ApkRequirement.extract(blob: extract)
init(name: String, version spec: ApkVersionSpecification) {
self.name = name
self.versionSpec = spec
}
}

View File

@ -7,7 +7,8 @@ struct ApkIndexInstallIf: ApkIndexRequirementRef {
let name: String
let versionSpec: ApkVersionSpecification
init(extract: String) throws(ApkRequirement.ParseError) {
(self.name, self.versionSpec) = try ApkRequirement.extract(blob: extract)
init(name: String, version spec: ApkVersionSpecification) {
self.name = name
self.versionSpec = spec
}
}

View File

@ -5,7 +5,7 @@
import Foundation
struct ApkIndexPackage: Hashable {
struct ApkIndexPackage: ApkIndexRequirementRef {
let indexChecksum: ApkIndexDigest
let name: String
let version: String
@ -28,6 +28,10 @@ struct ApkIndexPackage: Hashable {
//TODO: Implementation
//lazy var semanticVersion: (Int, Int, Int) = (0, 0, 0)
init(name: String, version spec: ApkVersionSpecification) {
fatalError("Cannot construct an ApkIndexPackage this way")
}
}
extension ApkIndexPackage {

View File

@ -6,7 +6,7 @@
struct ApkIndexProvides: ApkIndexRequirementRef {
let name: String
init(extract: String) throws(ApkRequirement.ParseError) {
(self.name, _) = try ApkRequirement.extract(blob: extract)
init(name: String, version _: ApkVersionSpecification) {
self.name = name
}
}

View File

@ -7,7 +7,7 @@ protocol ApkIndexRequirementRef: Equatable, Hashable {
var name: String { get }
var invert: Bool { get }
init(extract: String) throws(ApkRequirement.ParseError)
init(name: String, version spec: ApkVersionSpecification)
func satisfied(by other: ApkIndexPackage) -> Bool
}
@ -16,18 +16,11 @@ extension ApkIndexRequirementRef {
var invert: Bool { false }
func satisfied(by _: ApkIndexPackage) -> Bool { true }
static func == (lhs: Self, rhs: Self) -> Bool {
return !(lhs.name != rhs.name && !lhs.invert)
}
func hash(into hasher: inout Hasher) {
self.name.hash(into: &hasher)
}
static func extract<T: ApkIndexRequirementRef>(_ blob: String) throws(ApkRequirement.ParseError) -> [T] {
return try blob.components(separatedBy: " ")
.map { token throws(ApkRequirement.ParseError) in
try .init(extract: token)
let (name, versionSpec) = try ApkRequirement.extract(blob: token)
return .init(name: name, version: versionSpec)
}
}
}