Skip to content

Commit 355025d

Browse files
cipolleschihuntie
authored andcommitted
Update Xcode 15 patches to be more robust (#39710)
Summary: Pull Request resolved: #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 # Conflicts: # packages/react-native/scripts/cocoapods/__tests__/utils-test.rb # packages/react-native/scripts/cocoapods/utils.rb
1 parent 3c4cc59 commit 355025d

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def test_applyXcode15Patch_whenXcodebuild15_correctlyAppliesNecessaryPatch
526526
# Assert
527527
user_project_mock.build_configurations.each do |config|
528528
assert_equal("$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION", config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"])
529-
assert_equal("$(inherited) -Wl -ld_classic ", config.build_settings["OTHER_LDFLAGS"])
529+
assert_equal("$(inherited) -Wl -ld_classic", config.build_settings["OTHER_LDFLAGS"])
530530
end
531531

532532
# User project and Pods project
@@ -576,7 +576,7 @@ def test_applyXcode15Patch_whenXcodebuild14ButProjectHasSettings_correctlyRemove
576576
# Assert
577577
user_project_mock.build_configurations.each do |config|
578578
assert_equal("$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION", config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"])
579-
assert_equal("$(inherited) ", config.build_settings["OTHER_LDFLAGS"])
579+
assert_equal("$(inherited)", config.build_settings["OTHER_LDFLAGS"])
580580
end
581581

582582
# User project and Pods project

Diff for: packages/react-native/scripts/cocoapods/utils.rb

+15-9
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,26 @@ def self.safe_init(config, setting_name)
298298

299299
def self.add_value_to_setting_if_missing(config, setting_name, value)
300300
old_config = config.build_settings[setting_name]
301-
if !old_config.include?(value)
302-
config.build_settings[setting_name] << value
301+
if old_config.is_a?(Array)
302+
old_config = old_config.join(" ")
303+
end
304+
305+
trimmed_value = value.strip()
306+
if !old_config.include?(trimmed_value)
307+
config.build_settings[setting_name] = "#{old_config.strip()} #{trimmed_value}".strip()
303308
end
304309
end
305310

306311
def self.remove_value_to_setting_if_present(config, setting_name, value)
307312
old_config = config.build_settings[setting_name]
308-
if old_config.include?(value)
309-
# Old config can be either an Array or a String
310-
if old_config.is_a?(Array)
311-
old_config = old_config.join(" ")
312-
end
313-
new_config = old_config.gsub(value, "")
314-
config.build_settings[setting_name] = new_config
313+
if old_config.is_a?(Array)
314+
old_config = old_config.join(" ")
315+
end
316+
317+
trimmed_value = value.strip()
318+
if old_config.include?(trimmed_value)
319+
new_config = old_config.gsub(trimmed_value, "")
320+
config.build_settings[setting_name] = new_config.strip()
315321
end
316322
end
317323

0 commit comments

Comments
 (0)