From c9c589c5eef4f151a1a52a78be66da794cbe57ac Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Mon, 25 Sep 2017 13:23:47 +0200 Subject: [PATCH] add optional replace syntax when merging includes --- Fixtures/include_test.yml | 4 +++- Fixtures/included.yml | 4 ++++ Sources/XcodeGenKit/SpecLoader.swift | 5 ++++- Tests/XcodeGenKitTests/SpecLoadingTests.swift | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Fixtures/include_test.yml b/Fixtures/include_test.yml index 02fa473e..dcfb4df8 100644 --- a/Fixtures/include_test.yml +++ b/Fixtures/include_test.yml @@ -6,6 +6,8 @@ settingGroups: MY_SETTING3: VALUE3 new: MY_SETTING: VALUE + toReplace:REPLACE: + MY_SETTING2: VALUE2 targets: NewTarget: type: application @@ -13,4 +15,4 @@ targets: IncludedTarget: name: IncludedTargetNew platform: tvOS - sources: Target + sources:REPLACE: NewSource diff --git a/Fixtures/included.yml b/Fixtures/included.yml index 1619d813..b82d395c 100644 --- a/Fixtures/included.yml +++ b/Fixtures/included.yml @@ -3,7 +3,11 @@ settingGroups: test: MY_SETTING1: VALUE1 MY_SETTING2: VALUE2 + toReplace: + MY_SETTING1: VALUE1 targets: IncludedTarget: type: application platform: iOS + sources: + - Target diff --git a/Sources/XcodeGenKit/SpecLoader.swift b/Sources/XcodeGenKit/SpecLoader.swift index 4ecab1fe..043b59ca 100644 --- a/Sources/XcodeGenKit/SpecLoader.swift +++ b/Sources/XcodeGenKit/SpecLoader.swift @@ -52,7 +52,10 @@ public struct SpecLoader { var merged = base for (key, value) in dictionary { - if let dictionary = value as? JSONDictionary, let base = merged[key] as? JSONDictionary { + if key.hasSuffix(":REPLACE") { + let newKey = key.replacingOccurrences(of: ":REPLACE", with: "") + merged[newKey] = value + } else if let dictionary = value as? JSONDictionary, let base = merged[key] as? JSONDictionary { merged[key] = merge(dictionary: dictionary, onto: base) } else if let array = value as? [Any], let base = merged[key] as? [Any] { merged[key] = base + array diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index 8a10deaf..7679ad31 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -39,9 +39,10 @@ func specLoadingTests() { try expect(spec.settingGroups) == [ "test": Settings(dictionary: ["MY_SETTING1": "NEW VALUE", "MY_SETTING2": "VALUE2", "MY_SETTING3": "VALUE3"]), "new": Settings(dictionary: ["MY_SETTING": "VALUE"]), + "toReplace": Settings(dictionary: ["MY_SETTING2": "VALUE2"]), ] try expect(spec.targets) == [ - Target(name: "IncludedTargetNew", type: .application, platform: .tvOS, sources: ["Target"]), + Target(name: "IncludedTargetNew", type: .application, platform: .tvOS, sources: ["NewSource"]), Target(name: "NewTarget", type: .application, platform: .iOS), ] }