From e7fc47d64013ea84cb5dd40e1535ea17c1d45f7e Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Sun, 10 Nov 2024 21:00:07 +1100 Subject: [PATCH] make ApkIndexDependency conform to ApkIndexRequirementRef dunno if this is necessary for the graph to work but we'll see --- Sources/apk/Common/ApkVersionSpecification.swift | 12 +----------- Sources/apk/Index/ApkIndexDependency.swift | 5 +++-- Sources/apk/Index/ApkIndexInstallIf.swift | 5 +++-- Sources/apk/Index/ApkIndexPackage.swift | 6 +++++- Sources/apk/Index/ApkIndexProvides.swift | 4 ++-- Sources/apk/Index/ApkIndexRequirementRef.swift | 13 +++---------- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Sources/apk/Common/ApkVersionSpecification.swift b/Sources/apk/Common/ApkVersionSpecification.swift index 7d1f7d9..02c359c 100644 --- a/Sources/apk/Common/ApkVersionSpecification.swift +++ b/Sources/apk/Common/ApkVersionSpecification.swift @@ -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 diff --git a/Sources/apk/Index/ApkIndexDependency.swift b/Sources/apk/Index/ApkIndexDependency.swift index f59bc99..6514e35 100644 --- a/Sources/apk/Index/ApkIndexDependency.swift +++ b/Sources/apk/Index/ApkIndexDependency.swift @@ -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 } } diff --git a/Sources/apk/Index/ApkIndexInstallIf.swift b/Sources/apk/Index/ApkIndexInstallIf.swift index e9ddbf5..fcade26 100644 --- a/Sources/apk/Index/ApkIndexInstallIf.swift +++ b/Sources/apk/Index/ApkIndexInstallIf.swift @@ -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 } } diff --git a/Sources/apk/Index/ApkIndexPackage.swift b/Sources/apk/Index/ApkIndexPackage.swift index 795c045..daa0765 100644 --- a/Sources/apk/Index/ApkIndexPackage.swift +++ b/Sources/apk/Index/ApkIndexPackage.swift @@ -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 { diff --git a/Sources/apk/Index/ApkIndexProvides.swift b/Sources/apk/Index/ApkIndexProvides.swift index 6f20dd6..0e86438 100644 --- a/Sources/apk/Index/ApkIndexProvides.swift +++ b/Sources/apk/Index/ApkIndexProvides.swift @@ -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 } } diff --git a/Sources/apk/Index/ApkIndexRequirementRef.swift b/Sources/apk/Index/ApkIndexRequirementRef.swift index 5c483ed..4b527bd 100644 --- a/Sources/apk/Index/ApkIndexRequirementRef.swift +++ b/Sources/apk/Index/ApkIndexRequirementRef.swift @@ -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(_ 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) } } }