Skip to content

Commit

Permalink
Fix overriding EXCLUDED_ARCHS when installing Hermes on RN v0.71 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ken0nek authored Dec 19, 2023
1 parent bdc0ef3 commit 16a605b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 14 deletions.
56 changes: 51 additions & 5 deletions scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,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 @@ -193,13 +215,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 @@ -219,6 +242,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
31 changes: 22 additions & 9 deletions scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,35 @@ def self.turn_off_resource_bundle_react_core(installer)
end
end

def self.exclude_i386_architecture_while_using_hermes(installer)
projects = installer.aggregate_targets
def self.extract_projects(installer)
return installer.aggregate_targets
.map{ |t| t.user_project }
.uniq{ |p| p.path }
.push(installer.pods_project)
end

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

# Hermes does not support 'i386' architecture
excluded_archs_default = ReactNativePodsUtils.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()
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

Expand Down

0 comments on commit 16a605b

Please sign in to comment.