Skip to content

Commit

Permalink
Fix overriding EXCLUDED_ARCHS when installing Hermes on RN v0.72 (#43002
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ken0nek authored Feb 16, 2024
1 parent 5de1d4f commit a4282a9
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 14 deletions.
56 changes: 51 additions & 5 deletions packages/react-native/scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,33 @@ def test_hasPod_whenInstallerHasPod_returnTrue
# ============================ #
# Test - Exclude Architectures #
# ============================ #
def test_excludeArchitectures_whenHermesEngineIsNotIncluded_excludeNothing
def test_excludeArchitectures_whenHermesEngineIsNotIncluded_withNoValue_leaveUnset
# Arrange
user_project_mock = prepare_empty_user_project_mock()
pods_projects_mock = PodsProjectMock.new()
installer = InstallerMock.new(PodsProjectMock.new(), [
AggregatedProjectMock.new(user_project_mock)
])

# Act
ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer)

# Assert
user_project_mock.build_configurations.each do |config|
assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], nil)
end
assert_equal(user_project_mock.save_invocation_count, 0)
assert_equal(pods_projects_mock.save_invocation_count, 0)
end

def test_excludeArchitectures_whenHermesEngineIsNotIncluded_withExistingValue_preserveExistingValue
# Arrange
user_project_mock = prepare_empty_user_project_mock()
user_project_mock.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
pods_projects_mock = PodsProjectMock.new()
installer = InstallerMock.new(PodsProjectMock.new(), [
installer = InstallerMock.new(pods_projects_mock, [
AggregatedProjectMock.new(user_project_mock)
])

Expand All @@ -192,13 +214,14 @@ def test_excludeArchitectures_whenHermesEngineIsNotIncluded_excludeNothing

# Assert
user_project_mock.build_configurations.each do |config|
assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "")
assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "arm64")
end
assert_equal(user_project_mock.save_invocation_count, 1)

assert_equal(user_project_mock.save_invocation_count, 0)
assert_equal(pods_projects_mock.save_invocation_count, 0)
end

def test_excludeArchitectures_whenHermesEngineIsIncluded_excludeI386
def test_excludeArchitectures_whenHermesEngineIsIncluded_withNoValue_onlyExcludeI386
# Arrange
user_project_mock = prepare_empty_user_project_mock()
pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}})
Expand All @@ -218,6 +241,29 @@ def test_excludeArchitectures_whenHermesEngineIsIncluded_excludeI386
assert_equal(pods_projects_mock.save_invocation_count, 1)
end

def test_excludeArchitectures_whenHermesEngineIsIncluded_withExistingValue_appendI386
# Arrange
user_project_mock = prepare_empty_user_project_mock()
user_project_mock.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}})
installer = InstallerMock.new(pods_projects_mock, [
AggregatedProjectMock.new(user_project_mock)
])

# Act
ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer)

# Assert
user_project_mock.build_configurations.each do |config|
assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "arm64 i386")
end

assert_equal(user_project_mock.save_invocation_count, 1)
assert_equal(pods_projects_mock.save_invocation_count, 1)
end

# ================= #
# Test - Fix Config #
# ================= #
Expand Down
28 changes: 19 additions & 9 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,28 @@ def self.turn_off_resource_bundle_react_core(installer)
end

def self.exclude_i386_architecture_while_using_hermes(installer)
projects = self.extract_projects(installer)
is_using_hermes = self.has_pod(installer, 'hermes-engine')

# Hermes does not support `i386` architecture
excluded_archs_default = self.has_pod(installer, 'hermes-engine') ? "i386" : ""
if is_using_hermes
key = "EXCLUDED_ARCHS[sdk=iphonesimulator*]"

projects.each do |project|
project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = excluded_archs_default
end
projects = self.extract_projects(installer)

project.save()
end
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_node_modules_user_settings(installer, react_native_path)
Expand Down

0 comments on commit a4282a9

Please sign in to comment.