-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathInstalledSwiftPMConfiguration.swift
More file actions
96 lines (85 loc) · 3.24 KB
/
Copy pathInstalledSwiftPMConfiguration.swift
File metadata and controls
96 lines (85 loc) · 3.24 KB
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
96
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 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
//
//===----------------------------------------------------------------------===//
public struct InstalledSwiftPMConfiguration {
public struct Version: Codable, CustomStringConvertible {
let major: Int
let minor: Int
let patch: Int
let prereleaseIdentifier: String?
public init(major: Int, minor: Int, patch: Int, prereleaseIdentifier: String? = nil) {
self.major = major
self.minor = minor
self.patch = patch
self.prereleaseIdentifier = prereleaseIdentifier
}
public var description: String {
return "\(major).\(minor).\(patch)\(prereleaseIdentifier.map { "-\($0)" } ?? "")"
}
}
let version: Int
public let swiftSyntaxVersionForMacroTemplate: Version
public let swiftTestingVersionForTestTemplate: Version
public static var `default`: InstalledSwiftPMConfiguration {
return .init(
version: 0,
swiftSyntaxVersionForMacroTemplate: .init(
major: 605,
minor: 0,
patch: 0,
prereleaseIdentifier: "latest"
),
swiftTestingVersionForTestTemplate: defaultSwiftTestingVersionForTestTemplate
)
}
private static var defaultSwiftTestingVersionForTestTemplate: Version {
.init(
major: 0,
minor: 8,
patch: 0,
prereleaseIdentifier: nil
)
}
}
extension InstalledSwiftPMConfiguration: Codable {
enum CodingKeys: CodingKey {
case version
case swiftSyntaxVersionForMacroTemplate
case swiftTestingVersionForTestTemplate
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.version = try container.decode(
Int.self,
forKey: CodingKeys.version
)
self.swiftSyntaxVersionForMacroTemplate = try container.decode(
Version.self,
forKey: CodingKeys.swiftSyntaxVersionForMacroTemplate
)
self.swiftTestingVersionForTestTemplate = try container.decodeIfPresent(
Version.self,
forKey: CodingKeys.swiftTestingVersionForTestTemplate
) ?? InstalledSwiftPMConfiguration.defaultSwiftTestingVersionForTestTemplate
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.version, forKey: CodingKeys.version)
try container.encode(
self.swiftSyntaxVersionForMacroTemplate,
forKey: CodingKeys.swiftSyntaxVersionForMacroTemplate
)
try container.encode(
self.swiftTestingVersionForTestTemplate,
forKey: CodingKeys.swiftTestingVersionForTestTemplate
)
}
}