Skip to content

Commit

Permalink
[LOCAL] Update Xcode 15 patches to be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
cipolleschi committed Oct 12, 2023
1 parent 964872d commit 735d06c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 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 @@ -566,7 +566,7 @@ def test_applyXcode15Patch_whenXcodebuild15_correctlyAppliesNecessaryPatch
# Assert
user_project_mock.build_configurations.each do |config|
assert_equal("$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION", config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"])
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 @@ -616,7 +616,7 @@ def test_applyXcode15Patch_whenXcodebuild14ButProjectHasSettings_correctlyRemove
# Assert
user_project_mock.build_configurations.each do |config|
assert_equal("$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION", config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"])
assert_equal("$(inherited) ", config.build_settings["OTHER_LDFLAGS"])
assert_equal("$(inherited)", config.build_settings["OTHER_LDFLAGS"])
end

# User project and Pods project
Expand Down
30 changes: 18 additions & 12 deletions scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.exclude_i386_architecture_while_using_hermes(installer)
.push(installer.pods_project)


# Hermes does not support `i386` architecture
# Hermes does not support 'i386' architecture
excluded_archs_default = ReactNativePodsUtils.has_pod(installer, 'hermes-engine') ? "i386" : ""

projects.each do |project|
Expand Down Expand Up @@ -174,7 +174,7 @@ def self.apply_xcode_15_patch(installer, xcodebuild_manager: Xcodebuild)
if self.is_using_xcode15_or_greter(:xcodebuild_manager => xcodebuild_manager)
self.add_value_to_setting_if_missing(config, other_ld_flags_key, xcode15_compatibility_flags)
else
self.remove_value_to_setting_if_present(config, other_ld_flags_key, xcode15_compatibility_flags)
self.remove_value_from_setting_if_present(config, other_ld_flags_key, xcode15_compatibility_flags)
end
end
project.save()
Expand Down Expand Up @@ -255,20 +255,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_to_setting_if_present(config, setting_name, value)
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 735d06c

Please sign in to comment.