Skip to content

Commit 8dd0202

Browse files
authored
initial implementation of dependencies coming from registry (#3635)
motivation: with SE-0292 accepted, we can start implementing the SwiftPM side of it the scope of this work only includes basic infrastructure to parse dependencies coming from registry, follow up work is required to complete the feature changes: * add manifest support for dependencies coming from registry * add manifest parsing support for dependencies coming from registry * separate out registry requirement from source control requirement * refactor manifest encoding and parsing to more clearly define dependency type and associated metadata * make .upToNextMajor and .upToNextMinor extensions on Range<Version> to reuse across new requirement types * non-functional manifest api cleanup, mostly moving serialization to one place * adjust tests
1 parent 490618e commit 8dd0202

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2059
-1200
lines changed

Sources/Commands/Describe.swift

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,54 @@ 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: PackageDependencyDescription.Requirement?
107-
108-
init(from dependency: PackageDependencyDescription) {
109-
self.identity = dependency.identity
110-
self.name = dependency.explicitNameForTargetDependencyResolutionOnly
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)
106+
107+
init(from dependency: PackageDependency) {
111108
switch dependency {
112-
case .local(let data):
113-
self.url = data.path.pathString
114-
self.requirement = nil
115-
case .scm(let data):
116-
self.url = data.location
117-
self.requirement = data.requirement
109+
case .fileSystem(let settings):
110+
self = .fileSystem(name: dependency.explicitNameForTargetDependencyResolutionOnly, path: settings.path)
111+
case .sourceControl(let settings):
112+
self = .sourceControl(name: dependency.explicitNameForTargetDependencyResolutionOnly, location: settings.location, requirement: settings.requirement)
113+
case .registry(let settings):
114+
self = .registry(identity: settings.identity, requirement: settings.requirement)
115+
}
116+
}
117+
118+
private enum CodingKeys: CodingKey {
119+
case type
120+
case name
121+
case path
122+
case url
123+
case requirement
124+
case identity
125+
}
126+
127+
private enum Kind: String, Codable {
128+
case fileSystem
129+
case sourceControl
130+
case registry
131+
}
132+
133+
public func encode(to encoder: Encoder) throws {
134+
var container = encoder.container(keyedBy: CodingKeys.self)
135+
switch self {
136+
case .fileSystem(let name, let path):
137+
try container.encode(Kind.fileSystem, forKey: .type)
138+
try container.encode(name, forKey: .name)
139+
try container.encode(path, forKey: .path)
140+
case .sourceControl(let name, let location, let requirement):
141+
try container.encode(Kind.sourceControl, forKey: .type)
142+
try container.encode(name, forKey: .name)
143+
try container.encode(location, forKey: .url)
144+
try container.encode(requirement, forKey: .requirement)
145+
case .registry(let identity, let requirement):
146+
try container.encode(Kind.registry, forKey: .type)
147+
try container.encode(identity, forKey: .identity)
148+
try container.encode(requirement, forKey: .requirement)
149+
118150
}
119151
}
120152
}

Sources/PackageDescription/BuildSettings.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
/*
22
This source file is part of the Swift.org open source project
3-
3+
44
Copyright (c) 2018 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
6-
6+
77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9-
*/
9+
*/
1010

1111
/// The build configuration such as debug or release.
1212
public struct BuildConfiguration: Encodable {
1313
private let config: String
14-
14+
1515
private init(_ config: String) {
1616
self.config = config
1717
}
18-
18+
1919
/// The debug build configuration.
2020
public static let debug: BuildConfiguration = BuildConfiguration("debug")
21-
21+
2222
/// The release build configuration.
2323
public static let release: BuildConfiguration = BuildConfiguration("release")
2424
}
@@ -49,15 +49,15 @@ public struct BuildConfiguration: Encodable {
4949
/// ]
5050
/// ),
5151
public struct BuildSettingCondition: Encodable {
52-
52+
5353
private let platforms: [Platform]?
5454
private let config: BuildConfiguration?
55-
55+
5656
private init(platforms: [Platform]?, config: BuildConfiguration?) {
5757
self.platforms = platforms
5858
self.config = config
5959
}
60-
60+
6161
/// Creates a build setting condition.
6262
///
6363
/// At least one parameter is mandatory.
@@ -77,25 +77,25 @@ public struct BuildSettingCondition: Encodable {
7777

7878
/// The underlying build setting data.
7979
fileprivate struct BuildSettingData: Encodable {
80-
80+
8181
/// The name of the build setting.
8282
let name: String
83-
83+
8484
/// The value of the build setting.
8585
let value: [String]
86-
86+
8787
/// A condition that restricts the application of the build setting.
8888
let condition: BuildSettingCondition?
8989
}
9090

9191
/// A C-language build setting.
9292
public struct CSetting: Encodable {
9393
private let data: BuildSettingData
94-
94+
9595
private init(name: String, value: [String], condition: BuildSettingCondition?) {
9696
self.data = BuildSettingData(name: name, value: value, condition: condition)
9797
}
98-
98+
9999
/// Provides a header search path relative to the target's directory.
100100
///
101101
/// Use this setting to add a search path for headers within your target.
@@ -112,7 +112,7 @@ public struct CSetting: Encodable {
112112
public static func headerSearchPath(_ path: String, _ condition: BuildSettingCondition? = nil) -> CSetting {
113113
return CSetting(name: "headerSearchPath", value: [path], condition: condition)
114114
}
115-
115+
116116
/// Defines a value for a macro.
117117
///
118118
/// If you don't specify a value, the macro's default value is 1.
@@ -130,7 +130,7 @@ public struct CSetting: Encodable {
130130
}
131131
return CSetting(name: "define", value: [settingValue], condition: condition)
132132
}
133-
133+
134134
/// Sets unsafe flags to pass arbitrary command-line flags to the corresponding build tool.
135135
///
136136
/// As the usage of the word "unsafe" implies, the Swift Package Manager
@@ -155,11 +155,11 @@ public struct CSetting: Encodable {
155155
/// A CXX-language build setting.
156156
public struct CXXSetting: Encodable {
157157
private let data: BuildSettingData
158-
158+
159159
private init(name: String, value: [String], condition: BuildSettingCondition?) {
160160
self.data = BuildSettingData(name: name, value: value, condition: condition)
161161
}
162-
162+
163163
/// Provides a header search path relative to the target's directory.
164164
///
165165
/// Use this setting to add a search path for headers within your target.
@@ -176,7 +176,7 @@ public struct CXXSetting: Encodable {
176176
public static func headerSearchPath(_ path: String, _ condition: BuildSettingCondition? = nil) -> CXXSetting {
177177
return CXXSetting(name: "headerSearchPath", value: [path], condition: condition)
178178
}
179-
179+
180180
/// Defines a value for a macro.
181181
///
182182
/// If you don't specify a value, the macro's default value is 1.
@@ -194,7 +194,7 @@ public struct CXXSetting: Encodable {
194194
}
195195
return CXXSetting(name: "define", value: [settingValue], condition: condition)
196196
}
197-
197+
198198
/// Sets unsafe flags to pass arbitrary command-line flags to the corresponding build tool.
199199
///
200200
/// As the usage of the word "unsafe" implies, the Swift Package Manager
@@ -218,11 +218,11 @@ public struct CXXSetting: Encodable {
218218
/// A Swift language build setting.
219219
public struct SwiftSetting: Encodable {
220220
private let data: BuildSettingData
221-
221+
222222
private init(name: String, value: [String], condition: BuildSettingCondition?) {
223223
self.data = BuildSettingData(name: name, value: value, condition: condition)
224224
}
225-
225+
226226
/// Defines a compilation condition.
227227
///
228228
/// Use compilation conditions to only compile statements if a certain condition is true.
@@ -244,7 +244,7 @@ public struct SwiftSetting: Encodable {
244244
public static func define(_ name: String, _ condition: BuildSettingCondition? = nil) -> SwiftSetting {
245245
return SwiftSetting(name: "define", value: [name], condition: condition)
246246
}
247-
247+
248248
/// Sets unsafe flags to pass arbitrary command-line flags to the corresponding build tool.
249249
///
250250
/// As the usage of the word "unsafe" implies, the Swift Package Manager
@@ -268,11 +268,11 @@ public struct SwiftSetting: Encodable {
268268
/// A linker build setting.
269269
public struct LinkerSetting: Encodable {
270270
private let data: BuildSettingData
271-
271+
272272
private init(name: String, value: [String], condition: BuildSettingCondition?) {
273273
self.data = BuildSettingData(name: name, value: value, condition: condition)
274274
}
275-
275+
276276
/// Declares linkage to a system library.
277277
///
278278
/// This setting is most useful when the library can't be linked
@@ -287,7 +287,7 @@ public struct LinkerSetting: Encodable {
287287
public static func linkedLibrary(_ library: String, _ condition: BuildSettingCondition? = nil) -> LinkerSetting {
288288
return LinkerSetting(name: "linkedLibrary", value: [library], condition: condition)
289289
}
290-
290+
291291
/// Declares linkage to a system framework.
292292
///
293293
/// This setting is most useful when the framework can't be linked
@@ -302,7 +302,7 @@ public struct LinkerSetting: Encodable {
302302
public static func linkedFramework(_ framework: String, _ condition: BuildSettingCondition? = nil) -> LinkerSetting {
303303
return LinkerSetting(name: "linkedFramework", value: [framework], condition: condition)
304304
}
305-
305+
306306
/// Sets unsafe flags to pass arbitrary command-line flags to the corresponding build tool.
307307
///
308308
/// As the usage of the word "unsafe" implies, the Swift Package Manager

Sources/PackageDescription/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_library(PackageDescription
1010
BuildSettings.swift
1111
LanguageStandardSettings.swift
1212
PackageDescription.swift
13+
PackageDescriptionSerialization.swift
1314
PackageDependency.swift
1415
PackageRequirement.swift
1516
Product.swift

Sources/PackageDescription/LanguageStandardSettings.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -163,26 +163,3 @@ public enum SwiftVersion {
163163
/// The value is passed as-is to the Swift compiler's `-swift-version` flag.
164164
case version(String)
165165
}
166-
167-
extension SwiftVersion: Encodable {
168-
169-
public func encode(to encoder: Encoder) throws {
170-
let value: String
171-
172-
switch self {
173-
case .v3:
174-
value = "3"
175-
case .v4:
176-
value = "4"
177-
case .v4_2:
178-
value = "4.2"
179-
case .v5:
180-
value = "5"
181-
case .version(let v):
182-
value = v
183-
}
184-
185-
var container = encoder.singleValueContainer()
186-
try container.encode(value)
187-
}
188-
}

0 commit comments

Comments
 (0)