1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import struct Foundation.URL
import Basics
import PackageModel
import struct TSCUtility.Version
public struct Fingerprint: Equatable {
public let origin: Origin
public let value: String
public let contentType: ContentType
public init(origin: Origin, value: String, contentType: ContentType) {
self.origin = origin
self.value = value
self.contentType = contentType
}
}
extension Fingerprint {
public enum Kind: String, Hashable {
case sourceControl
case registry
}
public enum Origin: Equatable, CustomStringConvertible {
case sourceControl(SourceControlURL)
case registry(URL)
public var kind: Fingerprint.Kind {
switch self {
case .sourceControl:
return .sourceControl
case .registry:
return .registry
}
}
public var url: SourceControlURL? {
switch self {
case .sourceControl(let url):
return url
case .registry(let url):
return SourceControlURL(url.absoluteString)
}
}
public var description: String {
switch self {
case .sourceControl(let url):
return "sourceControl(\(url))"
case .registry(let url):
return "registry(\(url))"
}
}
}
/// Each package version has a dictionary of fingerprints identified by content type.
/// Fingerprints of content type `sourceCode` can come from registry (i.e., source archive checksum)
/// or git repo (commit hash). However, the current implementation only stores fingerprints for manifests
/// downloaded from registry. It doesn't not save fingerprints for manifests in git repo.
public enum ContentType: Hashable, CustomStringConvertible {
case sourceCode
case manifest(ToolsVersion?)
public var description: String {
switch self {
case .sourceCode:
return "sourceCode"
case .manifest(.none):
return Manifest.filename
case .manifest(.some(let toolsVersion)):
return "Package@swift-\(toolsVersion).swift"
}
}
}
}
public typealias PackageFingerprints = [Version: [Fingerprint.Kind: [Fingerprint.ContentType: Fingerprint]]]
public enum FingerprintCheckingMode: String {
case strict
case warn
}
|