-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
PackageDependency.swift
264 lines (247 loc) · 11.5 KB
/
PackageDependency.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
This source file is part of the Swift.org open source project
Copyright (c) 2018 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 Swift project authors
*/
extension Package.Dependency {
/// Create a package dependency that uses the version requirement, starting with the given minimum version,
/// going up to the next major version.
///
/// This is the recommended way to specify a remote package dependency.
/// It allows you to specify the minimum version you require, allows updates that include bug fixes
/// and backward-compatible feature updates, but requires you to explicitly update to a new major version of the dependency.
/// This approach provides the maximum flexibility on which version to use,
/// while making sure you don't update to a version with breaking changes,
/// and helps to prevent conflicts in your dependency graph.
///
/// The following example allows the Swift package manager to select a version
/// like a `1.2.3`, `1.2.4`, or `1.3.0`, but not `2.0.0`.
///
/// .package(url: "https://example.com/example-package.git", from: "1.2.3"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - version: The minimum version requirement.
@available(_PackageDescription, obsoleted: 5.2)
public static func package(
url: String,
from version: Version
) -> Package.Dependency {
return .init(name: nil, url: url, requirement: .upToNextMajor(from: version))
}
/// Create a package dependency that uses the version requirement, starting with the given minimum version,
/// going up to the next major version.
///
/// This is the recommended way to specify a remote package dependency.
/// It allows you to specify the minimum version you require, allows updates that include bug fixes
/// and backward-compatible feature updates, but requires you to explicitly update to a new major version of the dependency.
/// This approach provides the maximum flexibility on which version to use,
/// while making sure you don't update to a version with breaking changes,
/// and helps to prevent conflicts in your dependency graph.
///
/// The following example allows the Swift package manager to select a version
/// like a `1.2.3`, `1.2.4`, or `1.3.0`, but not `2.0.0`.
///
/// .package(url: "https://example.com/example-package.git", from: "1.2.3"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - version: The minimum version requirement.
@available(_PackageDescription, introduced: 5.2)
public static func package(
name: String? = nil,
url: String,
from version: Version
) -> Package.Dependency {
return .init(name: name, url: url, requirement: .upToNextMajor(from: version))
}
/// Add a remote package dependency given a version requirement.
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - requirement: A dependency requirement. See static methods on `Package.Dependency.Requirement` for available options.
@available(_PackageDescription, obsoleted: 5.2)
public static func package(
url: String,
_ requirement: Package.Dependency.Requirement
) -> Package.Dependency {
precondition(!requirement.isLocalPackage, "Use `.package(path:)` API to declare a local package dependency")
return .init(name: nil, url: url, requirement: requirement)
}
/// Add a remote package dependency given a version requirement.
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - requirement: A dependency requirement. See static methods on `Package.Dependency.Requirement` for available options.
@available(_PackageDescription, introduced: 5.2)
public static func package(
name: String? = nil,
url: String,
_ requirement: Package.Dependency.Requirement
) -> Package.Dependency {
precondition(!requirement.isLocalPackage, "Use `.package(path:)` API to declare a local package dependency")
return .init(name: name, url: url, requirement: requirement)
}
/// Add a package dependency starting with a specific minimum version, up to
/// but not including a specified maximum version.
///
/// The following example allows the Swift package manager to pick
/// versions `1.2.3`, `1.2.4`, `1.2.5`, but not `1.2.6`.
///
/// .package(url: "https://example.com/example-package.git", "1.2.3"..<"1.2.6"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - range: The custom version range requirement.
@available(_PackageDescription, obsoleted: 5.2)
public static func package(
url: String,
_ range: Range<Version>
) -> Package.Dependency {
#if PACKAGE_DESCRIPTION_4
return .init(name: nil, url: url, requirement: .rangeItem(range))
#else
return .init(name: nil, url: url, requirement: ._rangeItem(range))
#endif
}
/// Add a package dependency starting with a specific minimum version, up to
/// but not including a specified maximum version.
///
/// The following example allows the Swift package manager to pick
/// versions `1.2.3`, `1.2.4`, `1.2.5`, but not `1.2.6`.
///
/// .package(url: "https://example.com/example-package.git", "1.2.3"..<"1.2.6"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - range: The custom version range requirement.
@available(_PackageDescription, introduced: 5.2)
public static func package(
name: String? = nil,
url: String,
_ range: Range<Version>
) -> Package.Dependency {
#if PACKAGE_DESCRIPTION_4
return .init(name: name, url: url, requirement: .rangeItem(range))
#else
return .init(name: name, url: url, requirement: ._rangeItem(range))
#endif
}
/// Add a package dependency starting with a specific minimum version, going
/// up to and including a specific maximum version.
///
/// The following example allows the Swift package manager to pick
/// versions 1.2.3, 1.2.4, 1.2.5, as well as 1.2.6.
///
/// .package(url: "https://example.com/example-package.git", "1.2.3"..."1.2.6"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - range: The closed version range requirement.
@available(_PackageDescription, obsoleted: 5.2)
public static func package(
url: String,
_ range: ClosedRange<Version>
) -> Package.Dependency {
// Increase upperbound's patch version by one.
let upper = range.upperBound
let upperBound = Version(
upper.major, upper.minor, upper.patch + 1,
prereleaseIdentifiers: upper.prereleaseIdentifiers,
buildMetadataIdentifiers: upper.buildMetadataIdentifiers)
#if PACKAGE_DESCRIPTION_4
return .init(name: nil, url: url, requirement: .rangeItem(range.lowerBound..<upperBound))
#else
return .init(name: nil, url: url, requirement: ._rangeItem(range.lowerBound..<upperBound))
#endif
}
/// Add a package dependency starting with a specific minimum version, going
/// up to and including a specific maximum version.
///
/// The following example allows the Swift package manager to pick
/// versions 1.2.3, 1.2.4, 1.2.5, as well as 1.2.6.
///
/// .package(url: "https://example.com/example-package.git", "1.2.3"..."1.2.6"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - range: The closed version range requirement.
@available(_PackageDescription, introduced: 5.2)
public static func package(
name: String? = nil,
url: String,
_ range: ClosedRange<Version>
) -> Package.Dependency {
// Increase upperbound's patch version by one.
let upper = range.upperBound
let upperBound = Version(
upper.major, upper.minor, upper.patch + 1,
prereleaseIdentifiers: upper.prereleaseIdentifiers,
buildMetadataIdentifiers: upper.buildMetadataIdentifiers)
#if PACKAGE_DESCRIPTION_4
return .init(name: name, url: url, requirement: .rangeItem(range.lowerBound..<upperBound))
#else
return .init(name: name, url: url, requirement: ._rangeItem(range.lowerBound..<upperBound))
#endif
}
#if !PACKAGE_DESCRIPTION_4
/// Add a dependency to a local package on the filesystem.
///
/// The Swift Package Manager uses the package dependency as-is
/// and does not perform any source control access. Local package dependencies
/// are especially useful during development of a new package or when working
/// on multiple tightly coupled packages.
///
/// - Parameter path: The path of the package.
@available(_PackageDescription, obsoleted: 5.2)
public static func package(
path: String
) -> Package.Dependency {
return .init(name: nil, url: path, requirement: ._localPackageItem)
}
/// Add a dependency to a local package on the filesystem.
///
/// The Swift Package Manager uses the package dependency as-is
/// and does not perform any source control access. Local package dependencies
/// are especially useful during development of a new package or when working
/// on multiple tightly coupled packages.
///
/// - Parameter path: The path of the package.
@available(_PackageDescription, introduced: 5.2)
public static func package(
name: String? = nil,
path: String
) -> Package.Dependency {
return .init(name: name, url: path, requirement: ._localPackageItem)
}
#endif
}
// Mark common APIs used by mistake as unavailable to provide better error messages.
extension Package.Dependency {
@available(*, unavailable, message: "use package(url:_:) with the .exact(Version) initializer instead")
public static func package(url: String, version: Version) -> Package.Dependency {
fatalError()
}
@available(*, unavailable, message: "use package(url:_:) with the .branch(String) initializer instead")
public static func package(url: String, branch: String) -> Package.Dependency {
fatalError()
}
@available(*, unavailable, message: "use package(url:_:) with the .revision(String) initializer instead")
public static func package(url: String, revision: String) -> Package.Dependency {
fatalError()
}
@available(*, unavailable, message: "use package(url:_:) without the range label instead")
public static func package(url: String, range: Range<Version>) -> Package.Dependency {
fatalError()
}
}