forked from swiftlang/swift-package-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibraryMetadata.swift
63 lines (54 loc) · 2.01 KB
/
LibraryMetadata.swift
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
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 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 Basics
import struct TSCUtility.Version
public struct ProvidedLibrary: Hashable {
public let location: AbsolutePath
public let metadata: LibraryMetadata
public var version: Version {
.init(stringLiteral: metadata.version)
}
}
public struct LibraryMetadata: Hashable, Decodable {
public enum Identity: Hashable, Decodable {
case packageIdentity(scope: String, name: String)
case sourceControl(url: SourceControlURL)
}
/// The package from which it was built (e.g., the URL https://github.com/swiftlang/swift-syntax.git)
public let identities: [Identity]
/// The version that was built (e.g., 509.0.2)
public let version: String
/// The product name, if it differs from the module name (e.g., SwiftParser).
public let productName: String
let schemaVersion: Int
}
extension LibraryMetadata.Identity {
public var identity: PackageIdentity {
switch self {
case .packageIdentity(let scope, let name):
return PackageIdentity.plain("\(scope)/\(name)")
case .sourceControl(let url):
return PackageIdentity(url: url)
}
}
public var kind: PackageReference.Kind {
switch self {
case .packageIdentity:
return .registry(self.identity)
case .sourceControl(let url):
return .remoteSourceControl(.init(url.absoluteString))
}
}
public var ref: PackageReference {
return PackageReference(identity: self.identity, kind: self.kind)
}
}