Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/react-native/scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,52 @@ def test_excludeArchitectures_whenHermesEngineIsIncluded_excludeI386
assert_equal(pods_projects_mock.save_invocation_count, 1)
end

def test_excludeArchitectures_whenHermesEngineIsNotIncluded_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(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")
end

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

def test_excludeArchitectures_whenHermesEngineIsIncluded_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
18 changes: 14 additions & 4 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,24 @@ def self.turn_off_resource_bundle_react_core(installer)
end

def self.exclude_i386_architecture_while_using_hermes(installer)
projects = self.extract_projects(installer)
isUsingHermes = self.has_pod(installer, 'hermes-engine')
key = "EXCLUDED_ARCHS[sdk=iphonesimulator*]"

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

projects.each do |project|
project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = excluded_archs_default
current_setting = config.build_settings[key] || ""

excludesI386 = current_setting.include?("i386")

if isUsingHermes and !excludesI386
# Hermes does not support `i386` architecture
config.build_settings[key] = "#{current_setting} i386".strip
else
# leave EXCLUDED_ARCHS unchanged or set it to "" if it doesn't already exist
config.build_settings[key] = current_setting
end
end

project.save()
Expand Down