Skip to content

Commit 475247d

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Update Xcode 15 patches to be more robust
Summary: 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. Differential Revision: D49748844 fbshipit-source-id: f99ff72bb5326db88f1c332f356e916ea1fdcbb0
1 parent 8e36cc0 commit 475247d

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

packages/react-native/scripts/cocoapods/__tests__/utils-test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def test_applyXcode15Patch_whenXcodebuild15_correctlyAppliesNecessaryPatch
613613

614614
# Assert
615615
user_project_mock.build_configurations.each do |config|
616-
assert_equal("$(inherited) -Wl -ld_classic ", config.build_settings["OTHER_LDFLAGS"])
616+
assert_equal("$(inherited) -Wl -ld_classic", config.build_settings["OTHER_LDFLAGS"])
617617
end
618618

619619
# User project and Pods project
@@ -662,7 +662,7 @@ def test_applyXcode15Patch_whenXcodebuild14ButProjectHasSettings_correctlyRemove
662662

663663
# Assert
664664
user_project_mock.build_configurations.each do |config|
665-
assert_equal("$(inherited) ", config.build_settings["OTHER_LDFLAGS"])
665+
assert_equal("$(inherited)", config.build_settings["OTHER_LDFLAGS"])
666666
end
667667

668668
# User project and Pods project

packages/react-native/scripts/cocoapods/utils.rb

+16-10
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def self.exclude_i386_architecture_while_using_hermes(installer)
7676
excluded_archs_includes_I386 = current_setting.include?("i386")
7777

7878
if !excluded_archs_includes_I386
79-
# Hermes does not support `i386` architecture
79+
# Hermes does not support 'i386' architecture
8080
config.build_settings[key] = "#{current_setting} i386".strip
8181
end
8282
end
@@ -341,20 +341,26 @@ def self.safe_init(config, setting_name)
341341

342342
def self.add_value_to_setting_if_missing(config, setting_name, value)
343343
old_config = config.build_settings[setting_name]
344-
if !old_config.include?(value)
345-
config.build_settings[setting_name] << value
344+
if old_config.is_a?(Array)
345+
old_config = old_config.join(" ")
346+
end
347+
348+
trimmed_value = value.strip()
349+
if !old_config.include?(trimmed_value)
350+
config.build_settings[setting_name] = "#{old_config.strip()} #{trimmed_value}".strip()
346351
end
347352
end
348353

349354
def self.remove_value_from_setting_if_present(config, setting_name, value)
350355
old_config = config.build_settings[setting_name]
351-
if old_config.include?(value)
352-
# Old config can be either an Array or a String
353-
if old_config.is_a?(Array)
354-
old_config = old_config.join(" ")
355-
end
356-
new_config = old_config.gsub(value, "")
357-
config.build_settings[setting_name] = new_config
356+
if old_config.is_a?(Array)
357+
old_config = old_config.join(" ")
358+
end
359+
360+
trimmed_value = value.strip()
361+
if old_config.include?(trimmed_value)
362+
new_config = old_config.gsub(trimmed_value, "")
363+
config.build_settings[setting_name] = new_config.strip()
358364
end
359365
end
360366

0 commit comments

Comments
 (0)