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:

<!-- Help reviewers and the release process by writing your own changelog entry.
Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[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
This commit is contained in:
MasGaNo
2024-09-17 09:11:26 -07:00
committed by Facebook GitHub Bot
parent 7cdb87eb19
commit 1e59f2e3f8
2 changed files with 30 additions and 2 deletions
@@ -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")
@@ -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