diff --git a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb index 47d6c632dbabb9..9c430ec9c213d8 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb @@ -179,11 +179,33 @@ def test_hasPod_whenInstallerHasPod_returnTrue # ============================ # # Test - Exclude Architectures # # ============================ # - def test_excludeArchitectures_whenHermesEngineIsNotIncluded_excludeNothing + def test_excludeArchitectures_whenHermesEngineIsNotIncluded_withNoValue_leaveUnset + # Arrange + user_project_mock = prepare_empty_user_project_mock() + pods_projects_mock = PodsProjectMock.new() + installer = InstallerMock.new(PodsProjectMock.new(), [ + AggregatedProjectMock.new(user_project_mock) + ]) + + # Act + ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer) + + # Assert + user_project_mock.build_configurations.each do |config| + assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], nil) + end + assert_equal(user_project_mock.save_invocation_count, 0) + assert_equal(pods_projects_mock.save_invocation_count, 0) + end + + def test_excludeArchitectures_whenHermesEngineIsNotIncluded_withExistingValue_preserveExistingValue # Arrange user_project_mock = prepare_empty_user_project_mock() + user_project_mock.build_configurations.each do |config| + config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" + end pods_projects_mock = PodsProjectMock.new() - installer = InstallerMock.new(PodsProjectMock.new(), [ + installer = InstallerMock.new(pods_projects_mock, [ AggregatedProjectMock.new(user_project_mock) ]) @@ -192,13 +214,14 @@ def test_excludeArchitectures_whenHermesEngineIsNotIncluded_excludeNothing # Assert user_project_mock.build_configurations.each do |config| - assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "") + assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "arm64") end - assert_equal(user_project_mock.save_invocation_count, 1) + + assert_equal(user_project_mock.save_invocation_count, 0) assert_equal(pods_projects_mock.save_invocation_count, 0) end - def test_excludeArchitectures_whenHermesEngineIsIncluded_excludeI386 + def test_excludeArchitectures_whenHermesEngineIsIncluded_withNoValue_onlyExcludeI386 # Arrange user_project_mock = prepare_empty_user_project_mock() pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}}) @@ -218,6 +241,29 @@ def test_excludeArchitectures_whenHermesEngineIsIncluded_excludeI386 assert_equal(pods_projects_mock.save_invocation_count, 1) end + def test_excludeArchitectures_whenHermesEngineIsIncluded_withExistingValue_appendI386 + # Arrange + user_project_mock = prepare_empty_user_project_mock() + user_project_mock.build_configurations.each do |config| + config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" + end + pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}}) + installer = InstallerMock.new(pods_projects_mock, [ + AggregatedProjectMock.new(user_project_mock) + ]) + + # Act + ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer) + + # Assert + user_project_mock.build_configurations.each do |config| + assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "arm64 i386") + end + + assert_equal(user_project_mock.save_invocation_count, 1) + assert_equal(pods_projects_mock.save_invocation_count, 1) + end + # ================= # # Test - Fix Config # # ================= # diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 3f1566d06a53ac..7221e81bf40529 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -54,18 +54,28 @@ def self.turn_off_resource_bundle_react_core(installer) end def self.exclude_i386_architecture_while_using_hermes(installer) - projects = self.extract_projects(installer) + is_using_hermes = self.has_pod(installer, 'hermes-engine') - # Hermes does not support `i386` architecture - excluded_archs_default = self.has_pod(installer, 'hermes-engine') ? "i386" : "" + if is_using_hermes + key = "EXCLUDED_ARCHS[sdk=iphonesimulator*]" - projects.each do |project| - project.build_configurations.each do |config| - config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = excluded_archs_default - end + projects = self.extract_projects(installer) - project.save() - end + projects.each do |project| + project.build_configurations.each do |config| + current_setting = config.build_settings[key] || "" + + excluded_archs_includes_I386 = current_setting.include?("i386") + + if !excluded_archs_includes_I386 + # Hermes does not support `i386` architecture + config.build_settings[key] = "#{current_setting} i386".strip + end + end + + project.save() + end + end end def self.set_node_modules_user_settings(installer, react_native_path)