Skip to content

Commit e6edecf

Browse files
committed
* seperate out registry requirement from source control requirement
* refactor manifet encoding and parsing to more clearly define dependency type and associated metadata * make .upToNextMajor and .upToNextMinor extensions on Range<Version> to reuse across new requirment types * adjust tests
1 parent 7846174 commit e6edecf

14 files changed

+768
-372
lines changed

Sources/Commands/Describe.swift

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,19 @@ fileprivate struct DescribedPackage: Encodable {
9999
}
100100

101101
/// Represents a package dependency for the sole purpose of generating a description.
102-
struct DescribedPackageDependency: Encodable {
103-
let identity: PackageIdentity
104-
let name: String?
105-
let url: String?
106-
let requirement: PackageDependency.Requirement?
102+
enum DescribedPackageDependency: Encodable {
103+
case fileSystem(name: String?, path: AbsolutePath)
104+
case sourceControl(name: String?, location: String, requirement: PackageDependency.SourceControl.Requirement)
105+
case registry(identity: PackageIdentity, requirement: PackageDependency.Registry.Requirement)
107106

108107
init(from dependency: PackageDependency) {
109-
self.identity = dependency.identity
110-
self.name = dependency.explicitNameForTargetDependencyResolutionOnly
111108
switch dependency {
112109
case .fileSystem(let settings):
113-
self.url = settings.path.pathString
114-
self.requirement = nil
110+
self = .fileSystem(name: dependency.explicitNameForTargetDependencyResolutionOnly, path: settings.path)
115111
case .sourceControl(let settings):
116-
self.url = settings.location
117-
self.requirement = settings.requirement
112+
self = .sourceControl(name: dependency.explicitNameForTargetDependencyResolutionOnly, location: settings.location, requirement: settings.requirement)
118113
case .registry(let settings):
119-
self.url = nil
120-
self.requirement = settings.requirement
114+
self = .registry(identity: settings.identity, requirement: settings.requirement)
121115
}
122116
}
123117
}

Sources/PackageDescription/PackageDependency.swift

Lines changed: 207 additions & 49 deletions
Large diffs are not rendered by default.

Sources/PackageDescription/PackageDescription.swift

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -65,111 +65,6 @@ import Foundation
6565
/// without having to update your package manifest and without losing access to
6666
/// existing packages.
6767
public final class Package {
68-
69-
/// A package dependency of a Swift package.
70-
///
71-
/// A package dependency consists of a Git URL to the source of the package,
72-
/// and a requirement for the version of the package.
73-
///
74-
/// The Swift Package Manager performs a process called *dependency resolution* to
75-
/// figure out the exact version of the package dependencies that an app or other
76-
/// Swift package can use. The `Package.resolved` file records the results of the
77-
/// dependency resolution and lives in the top-level directory of a Swift package.
78-
/// If you add the Swift package as a package dependency to an app for an Apple platform,
79-
/// you can find the `Package.resolved` file inside your `.xcodeproj` or `.xcworkspace`.
80-
public class Dependency: Encodable {
81-
82-
/// An enum that represents the requirement for a package dependency.
83-
///
84-
/// The dependency requirement can be defined as one of three different version requirements:
85-
///
86-
/// **A version-based requirement.**
87-
///
88-
/// Decide whether your project accepts updates to a package dependency up
89-
/// to the next major version or up to the next minor version. To be more
90-
/// restrictive, select a specific version range or an exact version.
91-
/// Major versions tend to have more significant changes than minor
92-
/// versions, and may require you to modify your code when they update.
93-
/// The version rule requires Swift packages to conform to semantic
94-
/// versioning. To learn more about the semantic versioning standard,
95-
/// visit [semver.org](https://semver.org).
96-
///
97-
/// 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.
98-
///
99-
/// **A branch-based requirement**
100-
///
101-
/// Select the name of the branch for your package dependency to follow.
102-
/// Use branch-based dependencies when you're developing multiple packages
103-
/// in tandem or when you don't want to publish versions of your package dependencies.
104-
///
105-
/// Note that packages which use branch-based dependency requirements
106-
/// can't be added as dependencies to packages that use version-based dependency
107-
/// requirements; you should remove branch-based dependency requirements
108-
/// before publishing a version of your package.
109-
///
110-
/// **A commit-based requirement**
111-
///
112-
/// Select the commit hash for your package dependency to follow.
113-
/// Choosing this option isn't recommended, and should be limited to
114-
/// exceptional cases. While pinning your package dependency to a specific
115-
/// commit ensures that the package dependency doesn't change and your
116-
/// code remains stable, you don't receive any updates at all. If you worry about
117-
/// the stability of a remote package, consider one of the more
118-
/// restrictive options of the version-based requirement.
119-
///
120-
/// Note that packages which use commit-based dependency requirements
121-
/// can't be added as dependencies to packages that use version-based
122-
/// dependency requirements; you should remove commit-based dependency
123-
/// requirements before publishing a version of your package.
124-
public enum Requirement {
125-
case exactItem(Version)
126-
case rangeItem(Range<Version>)
127-
case revisionItem(String)
128-
case branchItem(String)
129-
case localPackageItem
130-
131-
var isLocalPackage: Bool {
132-
if case .localPackageItem = self { return true }
133-
return false
134-
}
135-
}
136-
137-
/// The name of the package, or `nil` to deduce the name using the package's Git URL.
138-
public let name: String?
139-
140-
/// The location of the package dependency.
141-
public let location: String?
142-
143-
@available(*, deprecated, renamed: "location")
144-
public var url: String? {
145-
get {
146-
return self.location
147-
}
148-
}
149-
150-
/// The registry identity of package dependency.
151-
public let identity: String?
152-
153-
/// The dependency requirement of the package dependency.
154-
public let requirement: Requirement
155-
156-
/// Initializes and returns a newly allocated requirement with the specified url and requirements.
157-
init(name: String?, url: String, requirement: Requirement) {
158-
self.name = name
159-
self.location = url
160-
self.requirement = requirement
161-
self.identity = nil
162-
}
163-
164-
/// Initializes and returns a newly allocated requirement with the specified identity and requirements.
165-
init(identity: String, requirement: Requirement) {
166-
self.identity = identity
167-
self.requirement = requirement
168-
self.location = nil
169-
self.name = nil
170-
}
171-
}
172-
17368
/// The name of the Swift package.
17469
public var name: String
17570

0 commit comments

Comments
 (0)