Skip to content

Commit

Permalink
Update Xcode 15 patches to be more robust (facebook#39710)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#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.

[Internal] - Make the Xcode 15 workaround more robust.

Reviewed By: dmytrorykun

Differential Revision: D49748844

fbshipit-source-id: 34976d148f123c5aacba6487a500874bb938fe99
  • Loading branch information
cipolleschi authored and yayvery committed Oct 9, 2023
1 parent 821b4ef commit b4b9c0c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
4 changes: 2 additions & 2 deletions scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def test_applyXcode15Patch_whenXcodebuild15_correctlyAppliesNecessaryPatch

# 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
Expand Down Expand Up @@ -573,7 +573,7 @@ def test_applyXcode15Patch_whenXcodebuild14ButProjectHasSettings_correctlyRemove

# 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
Expand Down
46 changes: 35 additions & 11 deletions scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,26 @@ def self.turn_off_resource_bundle_react_core(installer)
def self.exclude_i386_architecture_while_using_hermes(installer)
projects = self.extract_projects(installer)

# Hermes does not support `i386` architecture
excluded_archs_default = self.has_pod(installer, 'hermes-engine') ? "i386" : ""
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_use_hermes_build_setting(installer, hermes_enabled)
Pod::UI.puts("Setting USE_HERMES build settings")
projects = self.extract_projects(installer)

projects.each do |project|
project.build_configurations.each do |config|
Expand Down Expand Up @@ -292,20 +310,26 @@ def self.safe_init(config, setting_name)

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_from_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

Expand Down

0 comments on commit b4b9c0c

Please sign in to comment.