From 67ebc7c7d5e04405d59b8cd29dd6cf7d33115cd5 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Fri, 29 Sep 2023 10:22:36 -0700 Subject: [PATCH] Update Xcode 15 patches to be more robust (#39710) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39710 Last week Apple released Xcode 15, which required us to ship a workaround for the new linker. Unfortunately, the previous fix was not good enough and there were some edge cases that were not covered. For example, in some occasions the flags are read as an array and the `-Wl` and the `-ld_classic` flags were separated and not properly removed when moving from Xcode 15 to Xcpde 14.3.1. This change fixes those edge cases, with a more robust solution where: - We convert the flags to a string. - We trim the string and the values properly. - We add the flags when running `pod install` with Xcode 15 as the default iOS toolchain. - We remove the flags when running `pod install` with Xcode <15 as the default iOS toolchain. ## Changelog: [Internal] - Make the Xcode 15 workaround more robust. Reviewed By: dmytrorykun Differential Revision: D49748844 fbshipit-source-id: 34976d148f123c5aacba6487a500874bb938fe99 --- .../scripts/cocoapods/__tests__/utils-test.rb | 4 +-- .../react-native/scripts/cocoapods/utils.rb | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb index 89de036c170..4c57727fa8f 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb @@ -613,7 +613,7 @@ class UtilsTests < Test::Unit::TestCase # Assert user_project_mock.build_configurations.each do |config| - assert_equal("$(inherited) -Wl -ld_classic ", config.build_settings["OTHER_LDFLAGS"]) + assert_equal("$(inherited) -Wl -ld_classic", config.build_settings["OTHER_LDFLAGS"]) end # User project and Pods project @@ -662,7 +662,7 @@ class UtilsTests < Test::Unit::TestCase # Assert user_project_mock.build_configurations.each do |config| - assert_equal("$(inherited) ", config.build_settings["OTHER_LDFLAGS"]) + assert_equal("$(inherited)", config.build_settings["OTHER_LDFLAGS"]) end # User project and Pods project diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index d034f40ac4c..cf396cfcb21 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -76,7 +76,7 @@ class ReactNativePodsUtils excluded_archs_includes_I386 = current_setting.include?("i386") if !excluded_archs_includes_I386 - # Hermes does not support `i386` architecture + # Hermes does not support 'i386' architecture config.build_settings[key] = "#{current_setting} i386".strip end end @@ -341,20 +341,26 @@ class ReactNativePodsUtils def self.add_value_to_setting_if_missing(config, setting_name, value) old_config = config.build_settings[setting_name] - if !old_config.include?(value) - config.build_settings[setting_name] << value + if old_config.is_a?(Array) + old_config = old_config.join(" ") + end + + trimmed_value = value.strip() + if !old_config.include?(trimmed_value) + config.build_settings[setting_name] = "#{old_config.strip()} #{trimmed_value}".strip() end end def self.remove_value_to_setting_if_present(config, setting_name, value) old_config = config.build_settings[setting_name] - if old_config.include?(value) - # Old config can be either an Array or a String - if old_config.is_a?(Array) - old_config = old_config.join(" ") - end - new_config = old_config.gsub(value, "") - config.build_settings[setting_name] = new_config + if old_config.is_a?(Array) + old_config = old_config.join(" ") + end + + trimmed_value = value.strip() + if old_config.include?(trimmed_value) + new_config = old_config.gsub(trimmed_value, "") + config.build_settings[setting_name] = new_config.strip() end end