From 94e08a78b57d1db9b97a1b5bfea76fcd7a91194e Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Fri, 22 Mar 2019 17:26:17 +1100 Subject: [PATCH 1/2] Fix multi-platform target templates --- CHANGELOG.md | 1 + Sources/ProjectSpec/Project.swift | 2 +- Tests/XcodeGenKitTests/SpecLoadingTests.swift | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83a313a7..764358a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Fixed error when `optional` path is missing [#527](https://github.com/yonaskolb/XcodeGen/pull/527) @yonaskolb - Fixed excludes within included spec [#535](https://github.com/yonaskolb/XcodeGen/pull/535) @yonaskolb - Fixed paths in target templates within included files not being relative [#537](https://github.com/yonaskolb/XcodeGen/pull/537) @yonaskolb +- Fix multi-platform target templates [#541](https://github.com/yonaskolb/XcodeGen/pull/541) @yonaskolb ## 2.2.0 diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index d445f706..b2ec4a3f 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -171,8 +171,8 @@ extension Project { static func resolveProject(jsonDictionary: JSONDictionary) throws -> JSONDictionary { var jsonDictionary = jsonDictionary - jsonDictionary = try Target.resolveMultiplatformTargets(jsonDictionary: jsonDictionary) jsonDictionary = try Target.resolveTargetTemplates(jsonDictionary: jsonDictionary) + jsonDictionary = try Target.resolveMultiplatformTargets(jsonDictionary: jsonDictionary) return jsonDictionary } } diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index f9252455..3c511e01 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -590,6 +590,28 @@ class SpecLoadingTests: XCTestCase { try expect(target.sources) == ["nestedTemplateSource2", "nestedTemplateSource1", "templateSource", "targetSource"] // merges array in order try expect(target.configFiles["debug"]) == "Configs/Framework/debug.xcconfig" // replaces $target_name } + + $0.it("parses cross platform target templates") { + + let project = try getProjectSpec([ + "targets": [ + "Framework": [ + "type": "framework", + "templates": ["temp"], + ] + ], + "targetTemplates": [ + "temp": [ + "platform": ["iOS", "tvOS"], + ] + ], + ]) + + let iOSTarget = project.targets.first { $0.platform == .iOS } + let tvOSTarget = project.targets.first { $0.platform == .tvOS } + try expect(iOSTarget?.type) == .framework + try expect(tvOSTarget?.type) == .framework + } $0.it("parses aggregate targets") { let dictionary: [String: Any] = [ From c9de56564111c5016d53896162de8ff22682e310 Mon Sep 17 00:00:00 2001 From: yonaskolb Date: Sun, 24 Mar 2019 17:24:55 +1100 Subject: [PATCH 2/2] make sure to still handle platform specific templates --- Sources/ProjectSpec/Project.swift | 5 ++++ Tests/XcodeGenKitTests/SpecLoadingTests.swift | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index b2ec4a3f..7eb90873 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -171,8 +171,13 @@ extension Project { static func resolveProject(jsonDictionary: JSONDictionary) throws -> JSONDictionary { var jsonDictionary = jsonDictionary + + // resolve multiple times so that we support both multi-platform templates, + // as well as platform specific templates in multi-platform targets + jsonDictionary = try Target.resolveMultiplatformTargets(jsonDictionary: jsonDictionary) jsonDictionary = try Target.resolveTargetTemplates(jsonDictionary: jsonDictionary) jsonDictionary = try Target.resolveMultiplatformTargets(jsonDictionary: jsonDictionary) + return jsonDictionary } } diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index 3c511e01..8a4fc56e 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -613,6 +613,32 @@ class SpecLoadingTests: XCTestCase { try expect(tvOSTarget?.type) == .framework } + $0.it("parses platform specific templates") { + + let project = try getProjectSpec([ + "targets": [ + "Framework": [ + "type": "framework", + "platform": ["iOS", "tvOS"], + "templates": ["$platform"], + ] + ], + "targetTemplates": [ + "iOS": [ + "sources": "A", + ], + "tvOS": [ + "sources": "B", + ] + ], + ]) + + let iOSTarget = project.targets.first { $0.platform == .iOS } + let tvOSTarget = project.targets.first { $0.platform == .tvOS } + try expect(iOSTarget?.sources) == ["A"] + try expect(tvOSTarget?.sources) == ["B"] + } + $0.it("parses aggregate targets") { let dictionary: [String: Any] = [ "targets": ["target_1", "target_2"],