add github helper for swift package url (#1029)

This commit is contained in:
Yonas Kolb 2021-02-24 21:23:21 +11:00 committed by GitHub
parent 05ea968f70
commit e8237903ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 7 deletions

View File

@ -2,6 +2,9 @@
## Next Version
#### Added
- Allow specifying a `github` name like `JohnSundell/Ink` instead of a full `url` for Swift Packages [#1029](https://github.com/yonaskolb/XcodeGen/pull/1029) @yonaskolb
#### Fixed
- Fixed regression on **.storekit** configuration files' default build phase. [#1026](https://github.com/yonaskolb/XcodeGen/pull/1026) @jcolicchio

View File

@ -936,6 +936,7 @@ Swift packages are defined at a project level, and then linked to individual tar
- `minVersion: 1.0.0, maxVersion: 1.2.9`
- `branch: master`
- `revision: xxxxxx`
- [ ] **github** : **String**- this is an optional helper you can use for github repos. Instead of specifying the full url in `url` you can just specify the github org and repo
### Local Package
@ -946,13 +947,11 @@ packages:
Yams:
url: https://github.com/jpsim/Yams
from: 2.0.0
Yams:
github: JohnSundell/Ink
from: 0.5.0
RxClient:
path: ../RxClient
targets:
App:
dependencies:
- package: Yams
- package: RxClient
```
## Project Reference

View File

@ -7,6 +7,8 @@ public enum SwiftPackage: Equatable {
public typealias VersionRequirement = XCRemoteSwiftPackageReference.VersionRequirement
static let githubPrefix = "https://github.com/"
case remote(url: String, versionRequirement: VersionRequirement)
case local(path: String)
@ -26,7 +28,14 @@ extension SwiftPackage: JSONObjectConvertible {
} else {
let versionRequirement: VersionRequirement = try VersionRequirement(jsonDictionary: jsonDictionary)
try Self.validateVersion(versionRequirement: versionRequirement)
self = .remote(url: try jsonDictionary.json(atKeyPath: "url"), versionRequirement: versionRequirement)
let url: String
if jsonDictionary["github"] != nil {
let github: String = try jsonDictionary.json(atKeyPath: "github")
url = "\(Self.githubPrefix)\(github)"
} else {
url = try jsonDictionary.json(atKeyPath: "url")
}
self = .remote(url: url, versionRequirement: versionRequirement)
}
}
@ -58,7 +67,11 @@ extension SwiftPackage: JSONEncodable {
var dictionary: JSONDictionary = [:]
switch self {
case .remote(let url, let versionRequirement):
dictionary["url"] = url
if url.hasPrefix(Self.githubPrefix) {
dictionary["github"] = url.replacingOccurrences(of: Self.githubPrefix, with: "")
} else {
dictionary["url"] = url
}
switch versionRequirement {

View File

@ -1175,6 +1175,7 @@ class SpecLoadingTests: XCTestCase {
"package7": .remote(url: "package.git", versionRequirement: .exact("1.2.2")),
"package8": .remote(url: "package.git", versionRequirement: .upToNextMajorVersion("4.0.0-beta.5")),
"package9": .local(path: "package/package"),
"package10": .remote(url: "https://github.com/yonaskolb/XcodeGen", versionRequirement: .exact("1.2.2")),
"XcodeGen": .local(path: "../XcodeGen"),
], options: .init(localPackagesGroup: "MyPackages"))
@ -1193,6 +1194,7 @@ class SpecLoadingTests: XCTestCase {
"package7": ["url": "package.git", "version": "1.2.2"],
"package8": ["url": "package.git", "majorVersion": "4.0.0-beta.5"],
"package9": ["path": "package/package"],
"package10": ["github": "yonaskolb/XcodeGen", "exactVersion": "1.2.2"],
],
"localPackages": ["../XcodeGen"],
]