Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- **Breaking**: `fileGroups` are now relative paths when in included files, like other paths #1534 @shnhrrsn
- **Breaking**: Local package paths are now relative paths when in included files, like other paths #1498 @juri
- Optional groups are no longer skipped when missing and generating projects from a different directory #1529 @SSheldon
- Handle major.minor SPM packages versions #1546 @RomanPodymov

### Internal

Expand Down
51 changes: 33 additions & 18 deletions Sources/ProjectSpec/SwiftPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,39 @@ extension SwiftPackage: JSONEncodable {
extension SwiftPackage.VersionRequirement: JSONUtilities.JSONObjectConvertible {

public init(jsonDictionary: JSONDictionary) throws {
if jsonDictionary["exactVersion"] != nil {
self = try .exact(jsonDictionary.json(atKeyPath: "exactVersion"))
} else if jsonDictionary["version"] != nil {
self = try .exact(jsonDictionary.json(atKeyPath: "version"))
} else if jsonDictionary["revision"] != nil {
self = try .revision(jsonDictionary.json(atKeyPath: "revision"))
} else if jsonDictionary["branch"] != nil {
self = try .branch(jsonDictionary.json(atKeyPath: "branch"))
} else if jsonDictionary["minVersion"] != nil && jsonDictionary["maxVersion"] != nil {
let minimum: String = try jsonDictionary.json(atKeyPath: "minVersion")
let maximum: String = try jsonDictionary.json(atKeyPath: "maxVersion")
self = .range(from: minimum, to: maximum)
} else if jsonDictionary["minorVersion"] != nil {
self = try .upToNextMinorVersion(jsonDictionary.json(atKeyPath: "minorVersion"))
} else if jsonDictionary["majorVersion"] != nil {
self = try .upToNextMajorVersion(jsonDictionary.json(atKeyPath: "majorVersion"))
} else if jsonDictionary["from"] != nil {
self = try .upToNextMajorVersion(jsonDictionary.json(atKeyPath: "from"))
func json(atKeyPath keyPath: String) -> String? {
if jsonDictionary[keyPath] != nil {
do {
let value: String = try jsonDictionary.json(atKeyPath: .init(rawValue: keyPath))
return value
} catch {
do {
let value: Double = try jsonDictionary.json(atKeyPath: .init(rawValue: keyPath))
return String(value)
} catch {
return nil
}
}
}
return nil
}

if let exactVersion = json(atKeyPath: "exactVersion") {
self = .exact(exactVersion)
} else if let version = json(atKeyPath: "version") {
self = .exact(version)
} else if let revision = json(atKeyPath: "revision") {
self = .revision(revision)
} else if let branch = json(atKeyPath: "branch") {
self = .branch(branch)
} else if let minVersion = json(atKeyPath: "minVersion"), let maxVersion = json(atKeyPath: "maxVersion") {
self = .range(from: minVersion, to: maxVersion)
} else if let minorVersion = json(atKeyPath: "minorVersion") {
self = .upToNextMinorVersion(minorVersion)
} else if let majorVersion = json(atKeyPath: "majorVersion") {
self = .upToNextMajorVersion(majorVersion)
} else if let from = json(atKeyPath: "from") {
self = .upToNextMajorVersion(from)
} else {
throw SpecParsingError.unknownPackageRequirement(jsonDictionary)
}
Expand Down
25 changes: 21 additions & 4 deletions Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
/* Begin PBXBuildFile section */
23C6626698DE560017A89F2F /* XcodeGen in Frameworks */ = {isa = PBXBuildFile; productRef = 6F7DEA2D82649EDF903FBDBD /* XcodeGen */; };
2DA7998902987953B119E4CE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26F7EFEE613987D1E1258A60 /* AppDelegate.swift */; };
36CE2E6187D9709BAD9EF807 /* FooUI in Frameworks */ = {isa = PBXBuildFile; productRef = 927CB19D94339CC9960E930C /* FooUI */; };
36CE2E6187D9709BAD9EF807 /* FooDomain in Frameworks */ = {isa = PBXBuildFile; productRef = 8D2DC638BEF7FDF23907E134 /* FooDomain */; };
3986ED6965842721C46C0452 /* SwiftRoaringDynamic in Frameworks */ = {isa = PBXBuildFile; productRef = DC73B269C8B0C0BF6912842C /* SwiftRoaringDynamic */; };
4CC663B42B270404EF5FD037 /* libStaticLibrary.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CAB5625F6FEA668410ED5482 /* libStaticLibrary.a */; };
9AD886A88D3E4A1B5E900687 /* SPMTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7970A2253B14A9B27C307FAC /* SPMTests.swift */; };
9C4AD0711D706FD3ED0E436D /* StaticLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61C17B77601A9D1B7895AB42 /* StaticLibrary.swift */; };
AF8E362713B9D28EA9A5C9FC /* FooDomain in Frameworks */ = {isa = PBXBuildFile; productRef = 8D2DC638BEF7FDF23907E134 /* FooDomain */; };
AF8E362713B9D28EA9A5C9FC /* SwiftLocation in Frameworks */ = {isa = PBXBuildFile; productRef = 04F71F974C4771232AF4FEC2 /* SwiftLocation */; };
B89EA0F3859878A1DCF7BAFD /* SwiftRoaringDynamic in Embed Frameworks */ = {isa = PBXBuildFile; productRef = DC73B269C8B0C0BF6912842C /* SwiftRoaringDynamic */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
CE46CBA5671B951B546C8673 /* Codability in Frameworks */ = {isa = PBXBuildFile; productRef = 16E6FE01D5BD99F78D4A17E2 /* Codability */; settings = {ATTRIBUTES = (Weak, ); }; };
E368431019ABC696E4FFC0CF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4E22B8BCC18A29EFE1DE3BE4 /* Assets.xcassets */; };
ECC4F5F3B3D1391712A7AFE3 /* FooUI in Frameworks */ = {isa = PBXBuildFile; productRef = 927CB19D94339CC9960E930C /* FooUI */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -90,8 +91,9 @@
3986ED6965842721C46C0452 /* SwiftRoaringDynamic in Frameworks */,
4CC663B42B270404EF5FD037 /* libStaticLibrary.a in Frameworks */,
23C6626698DE560017A89F2F /* XcodeGen in Frameworks */,
AF8E362713B9D28EA9A5C9FC /* FooDomain in Frameworks */,
36CE2E6187D9709BAD9EF807 /* FooUI in Frameworks */,
AF8E362713B9D28EA9A5C9FC /* SwiftLocation in Frameworks */,
36CE2E6187D9709BAD9EF807 /* FooDomain in Frameworks */,
ECC4F5F3B3D1391712A7AFE3 /* FooUI in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -224,6 +226,7 @@
16E6FE01D5BD99F78D4A17E2 /* Codability */,
DC73B269C8B0C0BF6912842C /* SwiftRoaringDynamic */,
6F7DEA2D82649EDF903FBDBD /* XcodeGen */,
04F71F974C4771232AF4FEC2 /* SwiftLocation */,
8D2DC638BEF7FDF23907E134 /* FooDomain */,
927CB19D94339CC9960E930C /* FooUI */,
);
Expand Down Expand Up @@ -253,6 +256,7 @@
packageReferences = (
5BA91390AE78D2EE15C60091 /* XCRemoteSwiftPackageReference "Codability" */,
348C81C327DB1710B742C370 /* XCRemoteSwiftPackageReference "Prefire" */,
63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */,
E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */,
630A8CE9F2BE39704ED9D461 /* XCLocalSwiftPackageReference "FooFeature" */,
C6539B364583AE96C18CE377 /* XCLocalSwiftPackageReference "../../.." */,
Expand Down Expand Up @@ -669,6 +673,14 @@
minimumVersion = 0.2.1;
};
};
63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/malcommac/SwiftLocation";
requirement = {
kind = exactVersion;
version = 6.0;
};
};
E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/piotte13/SwiftRoaring";
Expand All @@ -680,6 +692,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
04F71F974C4771232AF4FEC2 /* SwiftLocation */ = {
isa = XCSwiftPackageProductDependency;
package = 63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */;
productName = SwiftLocation;
};
15DB49096E2978F6BCA8D604 /* FooUI */ = {
isa = XCSwiftPackageProductDependency;
productName = FooUI;
Expand Down
4 changes: 4 additions & 0 deletions Tests/Fixtures/SPM/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ packages:
Prefire:
url: https://github.com/BarredEwe/Prefire
majorVersion: 1.4.1
SwiftLocation:
url: https://github.com/malcommac/SwiftLocation
exactVersion: 6.0
XcodeGen:
path: ../../.. #XcodeGen itself
group: SPM
Expand Down Expand Up @@ -39,6 +42,7 @@ targets:
embed: true
- target: StaticLibrary
- package: XcodeGen
- package: SwiftLocation
- package: FooFeature
products:
- FooDomain
Expand Down