Skip to content

Commit 8b3a683

Browse files
RomanPodymovgiginetRyu0118yonaskolbkirillyakimovich
authored
Handle major.minor for SPM (#1546)
* Custom error handler * Check for error reason and expected type * Improvements * Update CHANGELOG.md * Update master (#1) * Update CI equipments and drop Xcode 15 support (#1548) * Add validation to ensure that settings.configs values are dictionaries, in order to prevent misuse (#1547) * Add validation to ensure settings.configs values are dictionaries to prevent misuse * Add tests for invalid settings.configs value formats * Replaced with filter and split into a function * Rename invalidConfigsFormat to invalidConfigsMappingFormat * Add comments to explain invalid fixture * Rename test fixture * Update CHANGELOG.md * Correct grammer * Use KeyPath instead of closure * Rename validateMappingStyleInConfig to extractValidConfigs * Add a document comment for extractValidConfigs(from:) * Use old testing api and remove EquatableErrorBox * Rename test case to use "mapping" instead of "dictionary" * Add ValidSettingsExtractor to encapsulate the logic for converting a dictionary to Settings * Add settings validation for both Target and AggregateTarget * Add tests for invalid settings.configs in Target and AggregateTarget * Add document comments for ValidSettingsExtractor * Rename ValidSettingsExtractor to BuildSettingsExtractor * Add settings validation for settingGroups * Add tests for settingGroups * Rename extract to parse * Refactor * Update Tests/ProjectSpecTests/InvalidConfigsFormatTests.swift --------- Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com> * Synced folders (#1541) * update xcodeproj to 8.27.7 * add syncedFolder source type * drop xcode 15 support * Rely on fileReference instead of adding new synchronizedRootGroup (#1557) * fix: don't include untracked children in cache --------- Co-authored-by: Kirill Yakimovich <kirill.yakimovich@gmail.com> * Use USER env var instead of LOGNAME (#1559) During user switch with su/sudo in system LOGNAME may not be initialised, but USER env var is always exist. * Address Sanitizer options in run/test schemes (#1550) * Expose address sanitizer flags in run and test BuildActions in Schemes * Update testJSONEncodable to test the new fields * Also test the asan setting values for run scheme * Update changelog --------- Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com> * Update to 2.44.0 # Conflicts: # CHANGELOG.md --------- Co-authored-by: Kohki Miki <giginet.net@gmail.com> Co-authored-by: Ryu <87907656+Ryu0118@users.noreply.github.com> Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com> Co-authored-by: Kirill Yakimovich <kirill.yakimovich@gmail.com> Co-authored-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com> Co-authored-by: Himanshu Kumar <7786778+hi-kumar@users.noreply.github.com> * Revert * Refactoring started * func json(atKeyPath keyPath: String) -> String? * All cases --------- Co-authored-by: Kohki Miki <giginet.net@gmail.com> Co-authored-by: Ryu <87907656+Ryu0118@users.noreply.github.com> Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com> Co-authored-by: Kirill Yakimovich <kirill.yakimovich@gmail.com> Co-authored-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com> Co-authored-by: Himanshu Kumar <7786778+hi-kumar@users.noreply.github.com>
1 parent 3251691 commit 8b3a683

File tree

4 files changed

+59
-22
lines changed

4 files changed

+59
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- **Breaking**: `fileGroups` are now relative paths when in included files, like other paths #1534 @shnhrrsn
3636
- **Breaking**: Local package paths are now relative paths when in included files, like other paths #1498 @juri
3737
- Optional groups are no longer skipped when missing and generating projects from a different directory #1529 @SSheldon
38+
- Handle major.minor SPM packages versions #1546 @RomanPodymov
3839

3940
### Internal
4041

Sources/ProjectSpec/SwiftPackage.swift

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,39 @@ extension SwiftPackage: JSONEncodable {
105105
extension SwiftPackage.VersionRequirement: JSONUtilities.JSONObjectConvertible {
106106

107107
public init(jsonDictionary: JSONDictionary) throws {
108-
if jsonDictionary["exactVersion"] != nil {
109-
self = try .exact(jsonDictionary.json(atKeyPath: "exactVersion"))
110-
} else if jsonDictionary["version"] != nil {
111-
self = try .exact(jsonDictionary.json(atKeyPath: "version"))
112-
} else if jsonDictionary["revision"] != nil {
113-
self = try .revision(jsonDictionary.json(atKeyPath: "revision"))
114-
} else if jsonDictionary["branch"] != nil {
115-
self = try .branch(jsonDictionary.json(atKeyPath: "branch"))
116-
} else if jsonDictionary["minVersion"] != nil && jsonDictionary["maxVersion"] != nil {
117-
let minimum: String = try jsonDictionary.json(atKeyPath: "minVersion")
118-
let maximum: String = try jsonDictionary.json(atKeyPath: "maxVersion")
119-
self = .range(from: minimum, to: maximum)
120-
} else if jsonDictionary["minorVersion"] != nil {
121-
self = try .upToNextMinorVersion(jsonDictionary.json(atKeyPath: "minorVersion"))
122-
} else if jsonDictionary["majorVersion"] != nil {
123-
self = try .upToNextMajorVersion(jsonDictionary.json(atKeyPath: "majorVersion"))
124-
} else if jsonDictionary["from"] != nil {
125-
self = try .upToNextMajorVersion(jsonDictionary.json(atKeyPath: "from"))
108+
func json(atKeyPath keyPath: String) -> String? {
109+
if jsonDictionary[keyPath] != nil {
110+
do {
111+
let value: String = try jsonDictionary.json(atKeyPath: .init(rawValue: keyPath))
112+
return value
113+
} catch {
114+
do {
115+
let value: Double = try jsonDictionary.json(atKeyPath: .init(rawValue: keyPath))
116+
return String(value)
117+
} catch {
118+
return nil
119+
}
120+
}
121+
}
122+
return nil
123+
}
124+
125+
if let exactVersion = json(atKeyPath: "exactVersion") {
126+
self = .exact(exactVersion)
127+
} else if let version = json(atKeyPath: "version") {
128+
self = .exact(version)
129+
} else if let revision = json(atKeyPath: "revision") {
130+
self = .revision(revision)
131+
} else if let branch = json(atKeyPath: "branch") {
132+
self = .branch(branch)
133+
} else if let minVersion = json(atKeyPath: "minVersion"), let maxVersion = json(atKeyPath: "maxVersion") {
134+
self = .range(from: minVersion, to: maxVersion)
135+
} else if let minorVersion = json(atKeyPath: "minorVersion") {
136+
self = .upToNextMinorVersion(minorVersion)
137+
} else if let majorVersion = json(atKeyPath: "majorVersion") {
138+
self = .upToNextMajorVersion(majorVersion)
139+
} else if let from = json(atKeyPath: "from") {
140+
self = .upToNextMajorVersion(from)
126141
} else {
127142
throw SpecParsingError.unknownPackageRequirement(jsonDictionary)
128143
}

Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525
/* Begin PBXBuildFile section */
2626
23C6626698DE560017A89F2F /* XcodeGen in Frameworks */ = {isa = PBXBuildFile; productRef = 6F7DEA2D82649EDF903FBDBD /* XcodeGen */; };
2727
2DA7998902987953B119E4CE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26F7EFEE613987D1E1258A60 /* AppDelegate.swift */; };
28-
36CE2E6187D9709BAD9EF807 /* FooUI in Frameworks */ = {isa = PBXBuildFile; productRef = 927CB19D94339CC9960E930C /* FooUI */; };
28+
36CE2E6187D9709BAD9EF807 /* FooDomain in Frameworks */ = {isa = PBXBuildFile; productRef = 8D2DC638BEF7FDF23907E134 /* FooDomain */; };
2929
3986ED6965842721C46C0452 /* SwiftRoaringDynamic in Frameworks */ = {isa = PBXBuildFile; productRef = DC73B269C8B0C0BF6912842C /* SwiftRoaringDynamic */; };
3030
4CC663B42B270404EF5FD037 /* libStaticLibrary.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CAB5625F6FEA668410ED5482 /* libStaticLibrary.a */; };
3131
9AD886A88D3E4A1B5E900687 /* SPMTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7970A2253B14A9B27C307FAC /* SPMTests.swift */; };
3232
9C4AD0711D706FD3ED0E436D /* StaticLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61C17B77601A9D1B7895AB42 /* StaticLibrary.swift */; };
33-
AF8E362713B9D28EA9A5C9FC /* FooDomain in Frameworks */ = {isa = PBXBuildFile; productRef = 8D2DC638BEF7FDF23907E134 /* FooDomain */; };
33+
AF8E362713B9D28EA9A5C9FC /* SwiftLocation in Frameworks */ = {isa = PBXBuildFile; productRef = 04F71F974C4771232AF4FEC2 /* SwiftLocation */; };
3434
B89EA0F3859878A1DCF7BAFD /* SwiftRoaringDynamic in Embed Frameworks */ = {isa = PBXBuildFile; productRef = DC73B269C8B0C0BF6912842C /* SwiftRoaringDynamic */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3535
CE46CBA5671B951B546C8673 /* Codability in Frameworks */ = {isa = PBXBuildFile; productRef = 16E6FE01D5BD99F78D4A17E2 /* Codability */; settings = {ATTRIBUTES = (Weak, ); }; };
3636
E368431019ABC696E4FFC0CF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4E22B8BCC18A29EFE1DE3BE4 /* Assets.xcassets */; };
37+
ECC4F5F3B3D1391712A7AFE3 /* FooUI in Frameworks */ = {isa = PBXBuildFile; productRef = 927CB19D94339CC9960E930C /* FooUI */; };
3738
/* End PBXBuildFile section */
3839

3940
/* Begin PBXContainerItemProxy section */
@@ -90,8 +91,9 @@
9091
3986ED6965842721C46C0452 /* SwiftRoaringDynamic in Frameworks */,
9192
4CC663B42B270404EF5FD037 /* libStaticLibrary.a in Frameworks */,
9293
23C6626698DE560017A89F2F /* XcodeGen in Frameworks */,
93-
AF8E362713B9D28EA9A5C9FC /* FooDomain in Frameworks */,
94-
36CE2E6187D9709BAD9EF807 /* FooUI in Frameworks */,
94+
AF8E362713B9D28EA9A5C9FC /* SwiftLocation in Frameworks */,
95+
36CE2E6187D9709BAD9EF807 /* FooDomain in Frameworks */,
96+
ECC4F5F3B3D1391712A7AFE3 /* FooUI in Frameworks */,
9597
);
9698
runOnlyForDeploymentPostprocessing = 0;
9799
};
@@ -224,6 +226,7 @@
224226
16E6FE01D5BD99F78D4A17E2 /* Codability */,
225227
DC73B269C8B0C0BF6912842C /* SwiftRoaringDynamic */,
226228
6F7DEA2D82649EDF903FBDBD /* XcodeGen */,
229+
04F71F974C4771232AF4FEC2 /* SwiftLocation */,
227230
8D2DC638BEF7FDF23907E134 /* FooDomain */,
228231
927CB19D94339CC9960E930C /* FooUI */,
229232
);
@@ -253,6 +256,7 @@
253256
packageReferences = (
254257
5BA91390AE78D2EE15C60091 /* XCRemoteSwiftPackageReference "Codability" */,
255258
348C81C327DB1710B742C370 /* XCRemoteSwiftPackageReference "Prefire" */,
259+
63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */,
256260
E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */,
257261
630A8CE9F2BE39704ED9D461 /* XCLocalSwiftPackageReference "FooFeature" */,
258262
C6539B364583AE96C18CE377 /* XCLocalSwiftPackageReference "../../.." */,
@@ -669,6 +673,14 @@
669673
minimumVersion = 0.2.1;
670674
};
671675
};
676+
63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */ = {
677+
isa = XCRemoteSwiftPackageReference;
678+
repositoryURL = "https://github.com/malcommac/SwiftLocation";
679+
requirement = {
680+
kind = exactVersion;
681+
version = 6.0;
682+
};
683+
};
672684
E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */ = {
673685
isa = XCRemoteSwiftPackageReference;
674686
repositoryURL = "https://github.com/piotte13/SwiftRoaring";
@@ -680,6 +692,11 @@
680692
/* End XCRemoteSwiftPackageReference section */
681693

682694
/* Begin XCSwiftPackageProductDependency section */
695+
04F71F974C4771232AF4FEC2 /* SwiftLocation */ = {
696+
isa = XCSwiftPackageProductDependency;
697+
package = 63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */;
698+
productName = SwiftLocation;
699+
};
683700
15DB49096E2978F6BCA8D604 /* FooUI */ = {
684701
isa = XCSwiftPackageProductDependency;
685702
productName = FooUI;

Tests/Fixtures/SPM/project.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ packages:
99
Prefire:
1010
url: https://github.com/BarredEwe/Prefire
1111
majorVersion: 1.4.1
12+
SwiftLocation:
13+
url: https://github.com/malcommac/SwiftLocation
14+
exactVersion: 6.0
1215
XcodeGen:
1316
path: ../../.. #XcodeGen itself
1417
group: SPM
@@ -39,6 +42,7 @@ targets:
3942
embed: true
4043
- target: StaticLibrary
4144
- package: XcodeGen
45+
- package: SwiftLocation
4246
- package: FooFeature
4347
products:
4448
- FooDomain

0 commit comments

Comments
 (0)