Skip to content

Commit c2ff291

Browse files
committed
Fix overriding EXCLUDED_ARCHS when installing Hermes. ref: #39060
1 parent 287482e commit c2ff291

File tree

2 files changed

+73
-14
lines changed

2 files changed

+73
-14
lines changed

scripts/cocoapods/__tests__/utils-test.rb

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,33 @@ def test_hasPod_whenInstallerHasPod_returnTrue
180180
# ============================ #
181181
# Test - Exclude Architectures #
182182
# ============================ #
183-
def test_excludeArchitectures_whenHermesEngineIsNotIncluded_excludeNothing
183+
def test_excludeArchitectures_whenHermesEngineIsNotIncluded_withNoValue_leaveUnset
184+
# Arrange
185+
user_project_mock = prepare_empty_user_project_mock()
186+
pods_projects_mock = PodsProjectMock.new()
187+
installer = InstallerMock.new(PodsProjectMock.new(), [
188+
AggregatedProjectMock.new(user_project_mock)
189+
])
190+
191+
# Act
192+
ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer)
193+
194+
# Assert
195+
user_project_mock.build_configurations.each do |config|
196+
assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], nil)
197+
end
198+
assert_equal(user_project_mock.save_invocation_count, 0)
199+
assert_equal(pods_projects_mock.save_invocation_count, 0)
200+
end
201+
202+
def test_excludeArchitectures_whenHermesEngineIsNotIncluded_withExistingValue_preserveExistingValue
184203
# Arrange
185204
user_project_mock = prepare_empty_user_project_mock()
205+
user_project_mock.build_configurations.each do |config|
206+
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
207+
end
186208
pods_projects_mock = PodsProjectMock.new()
187-
installer = InstallerMock.new(PodsProjectMock.new(), [
209+
installer = InstallerMock.new(pods_projects_mock, [
188210
AggregatedProjectMock.new(user_project_mock)
189211
])
190212

@@ -193,13 +215,14 @@ def test_excludeArchitectures_whenHermesEngineIsNotIncluded_excludeNothing
193215

194216
# Assert
195217
user_project_mock.build_configurations.each do |config|
196-
assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "")
218+
assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "arm64")
197219
end
198-
assert_equal(user_project_mock.save_invocation_count, 1)
220+
221+
assert_equal(user_project_mock.save_invocation_count, 0)
199222
assert_equal(pods_projects_mock.save_invocation_count, 0)
200223
end
201224

202-
def test_excludeArchitectures_whenHermesEngineIsIncluded_excludeI386
225+
def test_excludeArchitectures_whenHermesEngineIsIncluded_withNoValue_onlyExcludeI386
203226
# Arrange
204227
user_project_mock = prepare_empty_user_project_mock()
205228
pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}})
@@ -219,6 +242,29 @@ def test_excludeArchitectures_whenHermesEngineIsIncluded_excludeI386
219242
assert_equal(pods_projects_mock.save_invocation_count, 1)
220243
end
221244

245+
def test_excludeArchitectures_whenHermesEngineIsIncluded_withExistingValue_appendI386
246+
# Arrange
247+
user_project_mock = prepare_empty_user_project_mock()
248+
user_project_mock.build_configurations.each do |config|
249+
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
250+
end
251+
pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}})
252+
installer = InstallerMock.new(pods_projects_mock, [
253+
AggregatedProjectMock.new(user_project_mock)
254+
])
255+
256+
# Act
257+
ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer)
258+
259+
# Assert
260+
user_project_mock.build_configurations.each do |config|
261+
assert_equal(config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"], "arm64 i386")
262+
end
263+
264+
assert_equal(user_project_mock.save_invocation_count, 1)
265+
assert_equal(pods_projects_mock.save_invocation_count, 1)
266+
end
267+
222268
# ================= #
223269
# Test - Fix Config #
224270
# ================= #

scripts/cocoapods/utils.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,35 @@ def self.turn_off_resource_bundle_react_core(installer)
5353
end
5454
end
5555

56-
def self.exclude_i386_architecture_while_using_hermes(installer)
57-
projects = installer.aggregate_targets
56+
def self.extract_projects(installer)
57+
return installer.aggregate_targets
5858
.map{ |t| t.user_project }
5959
.uniq{ |p| p.path }
6060
.push(installer.pods_project)
61+
end
6162

63+
def self.exclude_i386_architecture_while_using_hermes(installer)
64+
is_using_hermes = self.has_pod(installer, 'hermes-engine')
6265

63-
# Hermes does not support 'i386' architecture
64-
excluded_archs_default = ReactNativePodsUtils.has_pod(installer, 'hermes-engine') ? "i386" : ""
66+
if is_using_hermes
67+
key = "EXCLUDED_ARCHS[sdk=iphonesimulator*]"
6568

66-
projects.each do |project|
67-
project.build_configurations.each do |config|
68-
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = excluded_archs_default
69-
end
69+
projects = self.extract_projects(installer)
7070

71-
project.save()
71+
projects.each do |project|
72+
project.build_configurations.each do |config|
73+
current_setting = config.build_settings[key] || ""
74+
75+
excluded_archs_includes_I386 = current_setting.include?("i386")
76+
77+
if !excluded_archs_includes_I386
78+
# Hermes does not support `i386` architecture
79+
config.build_settings[key] = "#{current_setting} i386".strip
80+
end
81+
end
82+
83+
project.save()
84+
end
7285
end
7386
end
7487

0 commit comments

Comments
 (0)