From 4cda0bff5cf2e4a9d07cafae892a0f42af02e904 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 9 Sep 2019 15:28:08 +0900 Subject: [PATCH 1/3] Expand template variable in Array of Any --- Sources/ProjectSpec/SpecFile.swift | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Sources/ProjectSpec/SpecFile.swift b/Sources/ProjectSpec/SpecFile.swift index 2261ce31..6983f0ab 100644 --- a/Sources/ProjectSpec/SpecFile.swift +++ b/Sources/ProjectSpec/SpecFile.swift @@ -158,18 +158,25 @@ extension Dictionary where Key == String, Value: Any { func replaceString(_ template: String, with replacement: String) -> JSONDictionary { var replaced: JSONDictionary = self for (key, value) in self { - switch value { - case let dictionary as JSONDictionary: - replaced[key] = dictionary.replaceString(template, with: replacement) - case let string as String: - replaced[key] = string.replacingOccurrences(of: template, with: replacement) - case let array as [JSONDictionary]: - replaced[key] = array.map { $0.replaceString(template, with: replacement) } - case let array as [String]: - replaced[key] = array.map { $0.replacingOccurrences(of: template, with: replacement) } - default: break - } + replaced[key] = replace(value: value, template, with: replacement) } return replaced } + + func replace(value: Any, _ template: String, with replacement: String) -> Any { + switch value { + case let dictionary as JSONDictionary: + return dictionary.replaceString(template, with: replacement) + case let string as String: + return string.replacingOccurrences(of: template, with: replacement) + case let array as [JSONDictionary]: + return array.map { $0.replaceString(template, with: replacement) } + case let array as [String]: + return array.map { $0.replacingOccurrences(of: template, with: replacement) } + case let anyArray as [Any]: + return anyArray.map { self.replace(value: $0, template, with: replacement) } + default: + return value + } + } } From da7b13c78c4a330d918b3dafbfb3ab2dc72ed38d Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 10 Sep 2019 22:53:45 +0900 Subject: [PATCH 2/3] Add test case for template expansion in [Any] --- Tests/XcodeGenKitTests/SpecLoadingTests.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index dfa177c1..3c9f3892 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -463,7 +463,10 @@ class SpecLoadingTests: XCTestCase { "targetTemplates": [ "temp": [ "platform": "iOS", - "sources": ["templateSource"], + "sources": [ + "templateSource", + ["path": "Sources/${target_name}"] + ], ], "temp2": [ "type": "framework", @@ -482,7 +485,7 @@ class SpecLoadingTests: XCTestCase { try expect(target.type) == .framework // uses value try expect(target.platform) == .iOS // uses latest value try expect(target.deploymentTarget) == Version("1.2.0") // keeps value - try expect(target.sources) == ["replacedSource", "templateSource", "targetSource"] // merges array in order + try expect(target.sources) == ["replacedSource", "templateSource", "Sources/Framework", "targetSource"] // merges array in order and replace ${target_name} try expect(target.configFiles["debug"]) == "Configs/Framework/debug.xcconfig" // replaces $target_name try expect(target.configFiles["release"]) == "Configs/Framework/release.xcconfig" // replaces ${target_name} } From e3b2414adbd3b50efdd8fa25d42264f9c60f8153 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 10 Sep 2019 22:56:00 +0900 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2540e466..642d8bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Added `includes` to `sources` for a Target. This follows the same glob-style as `excludes` but functions as a way to only include files that match a specified pattern. Useful if you only want a certain file type, for example specifying `**/*.swift`. [#637](https://github.com/yonaskolb/XcodeGen/pull/637) @bclymer +#### Fixed + +- Expand template variable in Array of Any [#651](https://github.com/yonaskolb/XcodeGen/pull/651) @kateinoigakukun + ## 2.7.0 #### Added