Skip to content

Commit b325031

Browse files
authored
re-introduce Package.Dependency.Requirement::upToNextMajor and ::upToNextMinor (#3922)
motivation: preserve source compatibility changes: * re-introduce Package.Dependency.Requirement::upToNextMajor and ::upToNextMinor * mark Package.Dependency.Requirement::upToNextMajor and ::upToNextMinor as @_disfavoredOverload to disambiguate from the extension on Range * add relevant API docs * fix a few typos in docs rdar://86041332
1 parent c346c59 commit b325031

File tree

3 files changed

+51
-39
lines changed

3 files changed

+51
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Swift 5.6
1616

1717
* [#3641]
1818

19-
Soft deprecate `.package(name:, url:)` dependency syntax in favour of `.package(url:)`, given that an explicit `name` attribute is no longer needed for target depedendencies lookup.
19+
Soft deprecate `.package(name:, url:)` dependency syntax in favor of `.package(url:)`, given that an explicit `name` attribute is no longer needed for target dependencies lookup.
2020

2121
* [#3641]
2222

@@ -38,11 +38,11 @@ Swift 5.5
3838

3939
* [#3280]
4040

41-
A more intuitive `.product(name:, package:)` target depedendency syntax is now accepted, where `package` is the package identifier as defined by the package URL.
41+
A more intuitive `.product(name:, package:)` target dependency syntax is now accepted, where `package` is the package identifier as defined by the package URL.
4242

4343
* [#3316]
4444

45-
Test targets can now link against executable targets as if they were libraries, so that they can test any data strutures or algorithms in them. All the code in the executable except for the main entry point itself is available to the unit test. Separate executables are still linked, and can be tested as a subprocess in the same way as before. This feature is available to tests defined in packages that have a tools version of `5.5` or newer.
45+
Test targets can now link against executable targets as if they were libraries, so that they can test any data structures or algorithms in them. All the code in the executable except for the main entry point itself is available to the unit test. Separate executables are still linked, and can be tested as a subprocess in the same way as before. This feature is available to tests defined in packages that have a tools version of `5.5` or newer.
4646

4747
Swift 5.4
4848
-----------
@@ -54,7 +54,7 @@ Swift 5.4
5454

5555
[SR-13566] The Swift tools version specification in each manifest file now accepts any combination of _horizontal_ whitespace characters surrounding `swift-tools-version`, if and only if the specified version ≥ `5.4`. For example, `//swift-tools-version: 5.4` and `// swift-tools-version: 5.4` are valid.
5656

57-
All [Unicode line terminators](https://www.unicode.org/reports/tr14/) are now recognised in `Package` manifests. This ensures correctness in parsing manifests that are edited and/or built on many non-Unix-like platforms that use ASCII or Unicode encodings.
57+
All [Unicode line terminators](https://www.unicode.org/reports/tr14/) are now recognized in `Package` manifests. This ensures correctness in parsing manifests that are edited and/or built on many non-Unix-like platforms that use ASCII or Unicode encodings.
5858

5959
* API Removal
6060

Sources/PackageDescription/PackageDependency.swift

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,17 @@ extension Package.Dependency {
352352
/// The following example allows the Swift Package Manager to pick
353353
/// versions 1.2.3, 1.2.4, 1.2.5, as well as 1.2.6.
354354
///
355-
/// .package(url: "https://example.com/example-package.git", "1.2.3"..."1.2.6"),
355+
/// .package(url: "https://example.com/example-package.git", "1.2.3"..."1.2.6"),
356+
///
357+
/// The following example allows the Swift Package Manager to pick
358+
/// versions between 1.0.0 and 2.0.0
359+
///
360+
/// .package(url: "https://example.com/example-package.git", .upToNextMajor("1.0.0"),
361+
///
362+
/// The following example allows the Swift Package Manager to pick
363+
/// versions between 1.0.0 and 1.1.0
364+
///
365+
/// .package(url: "https://example.com/example-package.git", .upToNextMinor("1.0.0"),
356366
///
357367
/// - Parameters:
358368
/// - name: The name of the package, or `nil` to deduce it from the URL.
@@ -367,6 +377,18 @@ extension Package.Dependency {
367377
return .package(name: name, url: url, closedRange: range)
368378
}
369379

380+
/// Adds a package dependency starting with a specific minimum version, going
381+
/// up to and including a specific maximum version.
382+
///
383+
/// The following example allows the Swift Package Manager to pick
384+
/// versions 1.2.3, 1.2.4, 1.2.5, as well as 1.2.6.
385+
///
386+
/// .package(url: "https://example.com/example-package.git", "1.2.3"..."1.2.6"),
387+
///
388+
/// - Parameters:
389+
/// - name: The name of the package, or `nil` to deduce it from the URL.
390+
/// - url: The valid Git URL of the package.
391+
/// - range: The closed version range requirement.
370392
private static func package(
371393
name: String?,
372394
url: String,
@@ -504,7 +526,17 @@ extension Package.Dependency {
504526
/// The following example allows the Swift Package Manager to pick
505527
/// versions `1.2.3`, `1.2.4`, `1.2.5`, but not `1.2.6`.
506528
///
507-
/// .package(id: "scope.name", "1.2.3"..<"1.2.6"),
529+
/// .package(id: "scope.name", "1.2.3"..<"1.2.6"),
530+
///
531+
/// The following example allows the Swift Package Manager to pick
532+
/// versions between 1.0.0 and 2.0.0
533+
///
534+
/// .package(id: "scope.name", .upToNextMajor("1.0.0"),
535+
///
536+
/// The following example allows the Swift Package Manager to pick
537+
/// versions between 1.0.0 and 1.1.0
538+
///
539+
/// .package(id: "scope.name", .upToNextMinor("1.0.0"),
508540
///
509541
/// - Parameters:
510542
/// - id: The identity of the package.
@@ -523,7 +555,7 @@ extension Package.Dependency {
523555
/// The following example allows the Swift Package Manager to pick
524556
/// versions 1.2.3, 1.2.4, 1.2.5, as well as 1.2.6.
525557
///
526-
/// .package(id: "scope.name", "1.2.3"..."1.2.6"),
558+
/// .package(id: "scope.name", "1.2.3"..."1.2.6"),
527559
///
528560
/// - Parameters:
529561
/// - id: The identity of the package.

Sources/PackageDescription/PackageRequirement.swift

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ extension Package.Dependency {
183183
extension Package.Dependency {
184184
/// An enum that represents the requirement for a package dependency.
185185
///
186-
/// The dependency requirement can be defined as one of three different version requirements:
187-
///
188-
/// **A version-based requirement.**
189-
///
190186
/// Decide whether your project accepts updates to a package dependency up
191187
/// to the next major version or up to the next minor version. To be more
192188
/// restrictive, select a specific version range or an exact version.
@@ -195,34 +191,6 @@ extension Package.Dependency {
195191
/// The version rule requires Swift packages to conform to semantic
196192
/// versioning. To learn more about the semantic versioning standard,
197193
/// visit [semver.org](https://semver.org).
198-
///
199-
/// Selecting the version requirement is the recommended way to add a package dependency. It allows you to create a balance between restricting changes and obtaining improvements and features.
200-
///
201-
/// **A branch-based requirement**
202-
///
203-
/// Select the name of the branch for your package dependency to follow.
204-
/// Use branch-based dependencies when you're developing multiple packages
205-
/// in tandem or when you don't want to publish versions of your package dependencies.
206-
///
207-
/// Note that packages which use branch-based dependency requirements
208-
/// can't be added as dependencies to packages that use version-based dependency
209-
/// requirements; you should remove branch-based dependency requirements
210-
/// before publishing a version of your package.
211-
///
212-
/// **A commit-based requirement**
213-
///
214-
/// Select the commit hash for your package dependency to follow.
215-
/// Choosing this option isn't recommended, and should be limited to
216-
/// exceptional cases. While pinning your package dependency to a specific
217-
/// commit ensures that the package dependency doesn't change and your
218-
/// code remains stable, you don't receive any updates at all. If you worry about
219-
/// the stability of a remote package, consider one of the more
220-
/// restrictive options of the version-based requirement.
221-
///
222-
/// Note that packages which use commit-based dependency requirements
223-
/// can't be added as dependencies to packages that use version-based
224-
/// dependency requirements; you should remove commit-based dependency
225-
/// requirements before publishing a version of your package.
226194
@available(_PackageDescription, introduced: 999)
227195
public enum RegistryRequirement {
228196
case exact(Version)
@@ -250,3 +218,15 @@ extension Range {
250218
return version ..< Version(version.major, version.minor + 1, 0)
251219
}
252220
}
221+
222+
@available(_PackageDescription, deprecated: 5.6)
223+
extension Package.Dependency.Requirement {
224+
@_disfavoredOverload
225+
public static func upToNextMajor(from version: Version) -> Self {
226+
return .rangeItem(.upToNextMajor(from: version))
227+
}
228+
@_disfavoredOverload
229+
public static func upToNextMinor(from version: Version) -> Self {
230+
return .rangeItem(.upToNextMinor(from: version))
231+
}
232+
}

0 commit comments

Comments
 (0)