From 3d76d2268491fec9483102be9dbb0bc659b84c84 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Fri, 9 May 2025 15:43:39 +0200 Subject: [PATCH 1/4] Custom error handler --- Sources/ProjectSpec/Project.swift | 11 ++++++++++- Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj | 9 +++++++++ Tests/Fixtures/SPM/project.yml | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index 72daf0324..e9f969b26 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -193,7 +193,16 @@ extension Project { attributes = jsonDictionary.json(atKeyPath: "attributes") ?? [:] include = jsonDictionary.json(atKeyPath: "include") ?? [] if jsonDictionary["packages"] != nil { - packages = try jsonDictionary.json(atKeyPath: "packages", invalidItemBehaviour: .fail) + packages = try jsonDictionary.json(atKeyPath: "packages", invalidItemBehaviour: .custom({ error in + var pairs = [(String, Any)]() + for item in error.dictionary { + pairs.append(( + item.key as? String ?? "", + (item.value as? Double).map { String($0) + ".0" } ?? item.value + )) + } + return (try? .value(.init(jsonDictionary: .init(uniqueKeysWithValues: pairs)))) ?? .fail + })) } else { packages = [:] } diff --git a/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj b/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj index 59311f725..cc6228054 100644 --- a/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj +++ b/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj @@ -255,6 +255,7 @@ packageReferences = ( 5BA91390AE78D2EE15C60091 /* XCRemoteSwiftPackageReference "Codability" */, 348C81C327DB1710B742C370 /* XCRemoteSwiftPackageReference "Prefire" */, + 63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */, E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */, 630A8CE9F2BE39704ED9D461 /* XCLocalSwiftPackageReference "FooFeature" */, C6539B364583AE96C18CE377 /* XCLocalSwiftPackageReference "../../.." */, @@ -671,6 +672,14 @@ minimumVersion = 0.2.1; }; }; + 63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/malcommac/SwiftLocation"; + requirement = { + kind = exactVersion; + version = 6.0.0; + }; + }; E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/piotte13/SwiftRoaring"; diff --git a/Tests/Fixtures/SPM/project.yml b/Tests/Fixtures/SPM/project.yml index 266f102e7..50c52d677 100644 --- a/Tests/Fixtures/SPM/project.yml +++ b/Tests/Fixtures/SPM/project.yml @@ -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 From e73d50b2369983d9a86a570c4d96c9005cf34e37 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Sat, 10 May 2025 13:42:10 +0200 Subject: [PATCH 2/4] Check for error reason and expected type --- Sources/ProjectSpec/Project.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index e9f969b26..1cca5b7cf 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -194,11 +194,14 @@ extension Project { include = jsonDictionary.json(atKeyPath: "include") ?? [] if jsonDictionary["packages"] != nil { packages = try jsonDictionary.json(atKeyPath: "packages", invalidItemBehaviour: .custom({ error in + guard error.reason == .incorrectType && type(of: error.expectedType.self) == String.Type.self else { + return .fail + } var pairs = [(String, Any)]() for item in error.dictionary { pairs.append(( item.key as? String ?? "", - (item.value as? Double).map { String($0) + ".0" } ?? item.value + (item.value as? Double).map { String($0) } ?? item.value )) } return (try? .value(.init(jsonDictionary: .init(uniqueKeysWithValues: pairs)))) ?? .fail From 89f8a7937be62cd52fba59e799451c96cebfa73d Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Sat, 10 May 2025 13:51:56 +0200 Subject: [PATCH 3/4] Improvements --- Sources/ProjectSpec/Project.swift | 2 +- .../Fixtures/SPM/SPM.xcodeproj/project.pbxproj | 18 +++++++++++++----- Tests/Fixtures/SPM/project.yml | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index 1cca5b7cf..39b24e806 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -201,7 +201,7 @@ extension Project { for item in error.dictionary { pairs.append(( item.key as? String ?? "", - (item.value as? Double).map { String($0) } ?? item.value + (item.value as? LosslessStringConvertible).map { String($0) } ?? item.value )) } return (try? .value(.init(jsonDictionary: .init(uniqueKeysWithValues: pairs)))) ?? .fail diff --git a/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj b/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj index cc6228054..4a9e2964c 100644 --- a/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj +++ b/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj @@ -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 */ @@ -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; }; @@ -224,6 +226,7 @@ 16E6FE01D5BD99F78D4A17E2 /* Codability */, DC73B269C8B0C0BF6912842C /* SwiftRoaringDynamic */, 6F7DEA2D82649EDF903FBDBD /* XcodeGen */, + 04F71F974C4771232AF4FEC2 /* SwiftLocation */, 8D2DC638BEF7FDF23907E134 /* FooDomain */, 927CB19D94339CC9960E930C /* FooUI */, ); @@ -677,7 +680,7 @@ repositoryURL = "https://github.com/malcommac/SwiftLocation"; requirement = { kind = exactVersion; - version = 6.0.0; + version = 6.0; }; }; E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */ = { @@ -691,6 +694,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 04F71F974C4771232AF4FEC2 /* SwiftLocation */ = { + isa = XCSwiftPackageProductDependency; + package = 63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */; + productName = SwiftLocation; + }; 15DB49096E2978F6BCA8D604 /* FooUI */ = { isa = XCSwiftPackageProductDependency; productName = FooUI; diff --git a/Tests/Fixtures/SPM/project.yml b/Tests/Fixtures/SPM/project.yml index 50c52d677..7e8b3b064 100644 --- a/Tests/Fixtures/SPM/project.yml +++ b/Tests/Fixtures/SPM/project.yml @@ -42,6 +42,7 @@ targets: embed: true - target: StaticLibrary - package: XcodeGen + - package: SwiftLocation - package: FooFeature products: - FooDomain From 2d4a094be4b6950deb91140671fe5cc46d72036c Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Sat, 10 May 2025 14:02:31 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 059ad11b3..8881613c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,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