From 299f652a4a9e42a03da48a870630e07faab60766 Mon Sep 17 00:00:00 2001 From: Sergii Khliustin <51409210+sergeykhliustin@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:12:09 +0100 Subject: [PATCH] Add ability to override 'objc_defines' via --user-options (#125) --- README.md | 4 ++-- .../Analyzer/Analyzers/BuildSettingsAnalyzer.swift | 12 ++++++------ Sources/BazelPodsCore/Core/UserOption.swift | 4 ++++ Sources/BazelPodsCore/Patches/UserOptionsPatch.swift | 9 +++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2d4b39f..986f7cc 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ OPTIONS: If 'user_options' not specified, but --user_options exist, user_options patch are applied automatically. --user-options User extra options. - Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic', 'data', 'runner', 'test_host', 'timeout'. + Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic', 'data', 'objc_defines', 'runner', 'test_host', 'timeout'. Supported operators: '+=' (append), '-=' (delete), ':=' (replace). Example: 'SomePod.sdk_dylibs += something,something' @@ -139,7 +139,7 @@ OPTIONS: If 'user_options' not specified, but --user_options exist, user_options patch are applied automatically. --user-options User extra options. - Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic', 'data', 'runner', 'test_host', 'timeout'. + Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic', 'data', 'objc_defines', 'runner', 'test_host', 'timeout'. Supported operators: '+=' (append), '-=' (delete), ':=' (replace). Example: 'SomePod.sdk_dylibs += something,something' diff --git a/Sources/BazelPodsCore/Analyzer/Analyzers/BuildSettingsAnalyzer.swift b/Sources/BazelPodsCore/Analyzer/Analyzers/BuildSettingsAnalyzer.swift index aa06c39..82e7bea 100644 --- a/Sources/BazelPodsCore/Analyzer/Analyzers/BuildSettingsAnalyzer.swift +++ b/Sources/BazelPodsCore/Analyzer/Analyzers/BuildSettingsAnalyzer.swift @@ -9,12 +9,12 @@ import Foundation struct BuildSettingsAnalyzer { struct Result { - let swiftCopts: [String] - let objcCopts: [String] - let ccCopts: [String] - let linkOpts: [String] - let objcDefines: [String] - let xcconfig: [String: StarlarkNode] + var swiftCopts: [String] + var objcCopts: [String] + var ccCopts: [String] + var linkOpts: [String] + var objcDefines: [String] + var xcconfig: [String: StarlarkNode] } private let platform: Platform private let spec: S diff --git a/Sources/BazelPodsCore/Core/UserOption.swift b/Sources/BazelPodsCore/Core/UserOption.swift index 2e36732..aa16412 100644 --- a/Sources/BazelPodsCore/Core/UserOption.swift +++ b/Sources/BazelPodsCore/Core/UserOption.swift @@ -54,6 +54,7 @@ public struct UserOption { case testonly(Bool) case link_dynamic(Bool) case data([String]) + case objc_defines([String]) case runner(String) case test_host(String) case timeout(TestsTimeout) @@ -68,6 +69,7 @@ public struct UserOption { case testonly case link_dynamic case data + case objc_defines case runner case test_host case timeout @@ -175,6 +177,8 @@ public struct UserOption { attribute = .link_dynamic(bool) case .data: attribute = .data(value) + case .objc_defines: + attribute = .objc_defines(value) case .runner: guard opt == .replace else { log_error("Incorrect option for \(string). '\(keyPath)' supports only \(Opt.replace.rawValue) operator. Skipping...") diff --git a/Sources/BazelPodsCore/Patches/UserOptionsPatch.swift b/Sources/BazelPodsCore/Patches/UserOptionsPatch.swift index fa7dfbb..3f3b788 100644 --- a/Sources/BazelPodsCore/Patches/UserOptionsPatch.swift +++ b/Sources/BazelPodsCore/Patches/UserOptionsPatch.swift @@ -91,6 +91,15 @@ struct UserOptionsPatch: Patch, TestSpecSpecificPatch { case .replace: resources.resources = value } + case .objc_defines(let value): + switch option.opt { + case .append: + buildSettings.objcDefines += value.filter({ !buildSettings.objcDefines.contains($0) }) + case .delete: + buildSettings.objcDefines.removeAll(where: { value.contains($0) }) + case .replace: + buildSettings.objcDefines = value + } case .runner: // test spec specific option break