Skip to content

Commit

Permalink
fix(ios): allow pods mixte type settings on post-install (#46536)
Browse files Browse the repository at this point in the history
Summary:
Following the discussion on #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: #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
  • Loading branch information
MasGaNo authored and facebook-github-bot committed Sep 17, 2024
1 parent 7cdb87e commit 1e59f2e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/react-native/scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,26 @@ def test_add_flag_to_map_with_inheritance_whenUsedWithXCConfigAttributes
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")
Expand Down
12 changes: 10 additions & 2 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,18 @@ def self.add_flag_to_map_with_inheritance(map, field, flag)
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
Expand Down

0 comments on commit 1e59f2e

Please sign in to comment.