mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-03 21:41:31 +00:00
Implement dependency wrapping & version spec
This commit is contained in:
22
Sources/apk/Index/ApkIndexDependency.swift
Normal file
22
Sources/apk/Index/ApkIndexDependency.swift
Normal file
@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import Foundation
|
||||
|
||||
struct ApkIndexDependency: ApkIndexRequirementRef {
|
||||
let name: String
|
||||
let versionSpec: ApkVersionSpecification
|
||||
|
||||
init(extract: String) throws(ApkRequirement.ParseError) {
|
||||
(self.name, self.versionSpec) = try ApkRequirement.extract(blob: extract)
|
||||
}
|
||||
}
|
||||
|
||||
extension ApkIndexDependency: CustomStringConvertible {
|
||||
var description: String {
|
||||
switch self.versionSpec {
|
||||
case .any: self.name
|
||||
case .conflict: "!\(self.name)"
|
||||
case .constraint(let op, let version): "\(self.name)\(op)\(version)"
|
||||
}
|
||||
}
|
||||
}
|
10
Sources/apk/Index/ApkIndexInstallIf.swift
Normal file
10
Sources/apk/Index/ApkIndexInstallIf.swift
Normal file
@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
struct ApkIndexInstallIf: ApkIndexRequirementRef {
|
||||
let name: String
|
||||
let versionSpec: ApkVersionSpecification
|
||||
|
||||
init(extract: String) throws(ApkRequirement.ParseError) {
|
||||
(self.name, self.versionSpec) = try ApkRequirement.extract(blob: extract)
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct ApkIndexPackage {
|
||||
struct ApkIndexPackage: Hashable {
|
||||
let indexChecksum: String //TODO: Decode cus why not
|
||||
let name: String
|
||||
let version: String
|
||||
@ -17,9 +17,9 @@ struct ApkIndexPackage {
|
||||
let buildTime: Date?
|
||||
let commit: String?
|
||||
let providerPriority: UInt16?
|
||||
let dependencies: [String] //TODO: stuff
|
||||
let provides: [String] //TODO: stuff
|
||||
let installIf: [String] //TODO: stuff
|
||||
let dependencies: [ApkIndexDependency]
|
||||
let provides: [ApkIndexProvides]
|
||||
let installIf: [ApkIndexInstallIf]
|
||||
|
||||
var downloadFilename: String { "\(self.name)-\(version).apk" }
|
||||
|
||||
@ -39,9 +39,9 @@ extension ApkIndexPackage {
|
||||
var packageSize: UInt64? = nil
|
||||
var installedSize: UInt64? = nil
|
||||
|
||||
var dependencies = [String]()
|
||||
var provides = [String]()
|
||||
var installIf = [String]()
|
||||
var dependencies = [ApkIndexDependency]()
|
||||
var provides = [ApkIndexProvides]()
|
||||
var installIf = [ApkIndexInstallIf]()
|
||||
|
||||
// Optional fields
|
||||
var architecture: String? = nil
|
||||
@ -67,7 +67,8 @@ extension ApkIndexPackage {
|
||||
case "A":
|
||||
architecture = record.value
|
||||
case "D":
|
||||
dependencies = record.value.components(separatedBy: " ")
|
||||
do { dependencies = try ApkIndexDependency.extract(record.value) }
|
||||
catch { throw .badValue(key: record.key) }
|
||||
case "C":
|
||||
indexChecksum = record.value // base64-encoded SHA1 hash prefixed with "Q1"
|
||||
case "S":
|
||||
@ -81,9 +82,11 @@ extension ApkIndexPackage {
|
||||
}
|
||||
installedSize = value
|
||||
case "p":
|
||||
provides = record.value.components(separatedBy: " ")
|
||||
do { provides = try ApkIndexProvides.extract(record.value) }
|
||||
catch { throw .badValue(key: record.key) }
|
||||
case "i":
|
||||
installIf = record.value.components(separatedBy: " ")
|
||||
do { installIf = try ApkIndexInstallIf.extract(record.value) }
|
||||
catch { throw .badValue(key: record.key) }
|
||||
case "o":
|
||||
origin = record.value
|
||||
case "m":
|
||||
|
9
Sources/apk/Index/ApkIndexProvides.swift
Normal file
9
Sources/apk/Index/ApkIndexProvides.swift
Normal file
@ -0,0 +1,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
struct ApkIndexProvides: ApkIndexRequirementRef {
|
||||
let name: String
|
||||
|
||||
init(extract: String) throws(ApkRequirement.ParseError) {
|
||||
(self.name, _) = try ApkRequirement.extract(blob: extract)
|
||||
}
|
||||
}
|
30
Sources/apk/Index/ApkIndexRequirementRef.swift
Normal file
30
Sources/apk/Index/ApkIndexRequirementRef.swift
Normal file
@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
protocol ApkIndexRequirementRef: Equatable, Hashable {
|
||||
var name: String { get }
|
||||
var invert: Bool { get }
|
||||
|
||||
init(extract: String) throws(ApkRequirement.ParseError)
|
||||
|
||||
func satisfied(by other: ApkIndexPackage) -> Bool
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@ public struct ApkIndexUpdater {
|
||||
}
|
||||
|
||||
for package in index.packages {
|
||||
print(package)
|
||||
print("\(package.name):", package.dependencies)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user