From 1e59f2e3f8f0ab3ee4173bddaa089bbecf61d1eb Mon Sep 17 00:00:00 2001 From: MasGaNo Date: Tue, 17 Sep 2024 09:11:26 -0700 Subject: [PATCH] fix(ios): allow pods mixte type settings on post-install (#46536) Summary: Following the discussion on https://github.com/facebook/react-native/issues/46505, this PR aims to allow mixte type configuration (String and/or Array of String) during the post installation of pods. ## Changelog: [IOS] [FIXED] - allow pods mixte type settings on post-install Pull Request resolved: https://github.com/facebook/react-native/pull/46536 Test Plan: `packages/react-native/scripts/cocoapods/__tests__/utils-test.rb` test suits was updated to support array and works as expected Reviewed By: shwanton Differential Revision: D62870582 Pulled By: cipolleschi fbshipit-source-id: c0ace6d9d20e6609ceae5aafd236d97fc9e86ddf --- .../scripts/cocoapods/__tests__/utils-test.rb | 20 +++++++++++++++++++ .../react-native/scripts/cocoapods/utils.rb | 12 +++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb index a2358cf8336..92c472f7929 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb @@ -1116,6 +1116,26 @@ class UtilsTests < Test::Unit::TestCase assert_equal("$(inherited)" + test_flag, twiceProcessed_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"]) end + def test_add_flag_to_map_with_inheritance_whenUsedWithArrayAttributes + # Arrange + initialized_xcconfig = XCConfigMock.new("InitializedConfig", attributes: { + "OTHER_CPLUSPLUSFLAGS" => ["INIT_FLAG"] + }) + twiceProcessed_xcconfig = XCConfigMock.new("TwiceProcessedConfig", attributes: { + "OTHER_CPLUSPLUSFLAGS" => [] + }) + test_flag = " -DTEST_FLAG=1" + + # Act + ReactNativePodsUtils.add_flag_to_map_with_inheritance(initialized_xcconfig.attributes, "OTHER_CPLUSPLUSFLAGS", test_flag) + ReactNativePodsUtils.add_flag_to_map_with_inheritance(twiceProcessed_xcconfig.attributes, "OTHER_CPLUSPLUSFLAGS", test_flag) + ReactNativePodsUtils.add_flag_to_map_with_inheritance(twiceProcessed_xcconfig.attributes, "OTHER_CPLUSPLUSFLAGS", test_flag) + + # Assert + assert_equal(["$(inherited)", "INIT_FLAG", test_flag], initialized_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"]) + assert_equal(["$(inherited)", test_flag], twiceProcessed_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"]) + end + def test_add_ndebug_flag_to_pods_in_release # Arrange xcconfig = XCConfigMock.new("Config") diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 480818ec16e..3274fe1b79a 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -696,10 +696,18 @@ class ReactNativePodsUtils map[field] = "$(inherited)" + flag else unless map[field].include?(flag) - map[field] = map[field] + flag + if map[field].instance_of? String + map[field] = map[field] + flag + elsif map[field].instance_of? Array + map[field].push(flag) + end end unless map[field].include?("$(inherited)") - map[field] = "$(inherited) " + map[field] + if map[field].instance_of? String + map[field] = "$(inherited) " + map[field] + elsif map[field].instance_of? Array + map[field].unshift("$(inherited)") + end end end end