diff --git a/scripts/cocoapods/__tests__/utils-test.rb b/scripts/cocoapods/__tests__/utils-test.rb index 422e3a551b5769..7e2ede25ad39db 100644 --- a/scripts/cocoapods/__tests__/utils-test.rb +++ b/scripts/cocoapods/__tests__/utils-test.rb @@ -180,11 +180,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) ]) @@ -193,13 +215,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" => {}}) @@ -219,6 +242,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/scripts/cocoapods/utils.rb b/scripts/cocoapods/utils.rb index 2713bcaa64ea66..154ba3eb3ccdd1 100644 --- a/scripts/cocoapods/utils.rb +++ b/scripts/cocoapods/utils.rb @@ -53,22 +53,35 @@ def self.turn_off_resource_bundle_react_core(installer) end end - def self.exclude_i386_architecture_while_using_hermes(installer) - projects = installer.aggregate_targets + def self.extract_projects(installer) + return installer.aggregate_targets .map{ |t| t.user_project } .uniq{ |p| p.path } .push(installer.pods_project) + end + def self.exclude_i386_architecture_while_using_hermes(installer) + is_using_hermes = self.has_pod(installer, 'hermes-engine') - # Hermes does not support 'i386' architecture - excluded_archs_default = ReactNativePodsUtils.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() + 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