Skip to content

Commit 4ca9d72

Browse files
benhandanyancipolleschi
authored andcommitted
Enable hermes debugger by configuration type instead of configuration name (#48174)
Summary: Fixes an [issue](#48168) where only iOS configurations with "Debug" in the name are configured to use the hermes debugger. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [IOS] [FIXED] - Enable hermes debugger by configuration type instead of configuration name Pull Request resolved: #48174 Test Plan: Added new test scenarios that all pass: ``` ruby -Itest packages/react-native/scripts/cocoapods/__tests__/utils-test.rb Loaded suite packages/react-native/scripts/cocoapods/__tests__/utils-test Started Finished in 0.336047 seconds. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 56 tests, 149 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 166.64 tests/s, 443.39 assertions/s ``` In a personal project with the following configurations: ``` project 'ReactNativeProject', { 'Local' => :debug, 'Development' => :release, 'Staging' => :release, 'Production' => :release, } ``` I added the following to my Podfile: ``` installer.pods_project.targets.each do |target| target.build_configurations.each do |config| puts "#{config.name} is debug? #{config.type == :debug}" end end ``` To confirm that my logic is correct: ``` Local is debug? true Development is debug? false Staging is debug? false Production is debug? false ``` Reviewed By: robhogan Differential Revision: D66962860 Pulled By: cipolleschi fbshipit-source-id: 7bd920e123c9064c8a1b5d45df546ff5d2a7d8be
1 parent ca3cddb commit 4ca9d72

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

packages/react-native/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ def initialize(name, build_settings = {}, is_debug: false)
197197
def debug?
198198
return @is_debug
199199
end
200+
201+
def type
202+
@is_debug ? :debug : :release
203+
end
200204
end
201205

202206
class TargetInstallationResultMock

packages/react-native/scripts/cocoapods/__tests__/utils-test.rb

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,24 @@ def test_SetGCCPreprocessorDefinitionForHermes_itSetsThePreprocessorForDebug
185185
react_hermes_name = "React-hermes"
186186
react_core_name = "React-Core"
187187
hermes_engine_name = "hermes-engine"
188-
react_hermes_debug_config = BuildConfigurationMock.new("Debug")
189-
react_hermes_release_config = BuildConfigurationMock.new("Release")
190-
react_core_debug_config = BuildConfigurationMock.new("Debug")
191-
react_core_release_config = BuildConfigurationMock.new("Release")
192-
hermes_engine_debug_config = BuildConfigurationMock.new("Debug")
193-
hermes_engine_release_config = BuildConfigurationMock.new("Release")
194-
react_hermes_target = TargetMock.new(react_hermes_name, [react_hermes_debug_config, react_hermes_release_config])
195-
react_core_target = TargetMock.new(react_core_name, [react_core_debug_config, react_core_release_config])
196-
hermes_engine_target = TargetMock.new(hermes_engine_name, [hermes_engine_debug_config, hermes_engine_release_config])
188+
189+
react_hermes_debug_config = BuildConfigurationMock.new("Debug", {}, is_debug: true)
190+
react_hermes_release_config = BuildConfigurationMock.new("Release", {}, is_debug: false)
191+
react_hermes_debug_config_rename = BuildConfigurationMock.new("Development", {}, is_debug: true)
192+
react_hermes_release_config_rename = BuildConfigurationMock.new("Production", {}, is_debug: false)
193+
react_hermes_target = TargetMock.new(react_hermes_name, [react_hermes_debug_config, react_hermes_release_config, react_hermes_debug_config_rename, react_hermes_release_config_rename])
194+
195+
react_core_debug_config = BuildConfigurationMock.new("Debug", {}, is_debug: true)
196+
react_core_release_config = BuildConfigurationMock.new("Release", {}, is_debug: false)
197+
react_core_debug_config_rename = BuildConfigurationMock.new("Development", {}, is_debug: true)
198+
react_core_release_config_rename = BuildConfigurationMock.new("Production", {}, is_debug: false)
199+
react_core_target = TargetMock.new(react_core_name, [react_core_debug_config, react_core_release_config, react_core_debug_config_rename, react_core_release_config_rename])
200+
201+
hermes_engine_debug_config = BuildConfigurationMock.new("Debug", {}, is_debug: true)
202+
hermes_engine_release_config = BuildConfigurationMock.new("Release", {}, is_debug: false)
203+
hermes_engine_debug_config_rename = BuildConfigurationMock.new("Development", {}, is_debug: true)
204+
hermes_engine_release_config_rename = BuildConfigurationMock.new("Production", {}, is_debug: false)
205+
hermes_engine_target = TargetMock.new(hermes_engine_name, [hermes_engine_debug_config, hermes_engine_release_config, hermes_engine_debug_config_rename, hermes_engine_release_config_rename])
197206

198207
installer = InstallerMock.new(
199208
:pod_target_installation_results => {
@@ -211,10 +220,18 @@ def test_SetGCCPreprocessorDefinitionForHermes_itSetsThePreprocessorForDebug
211220
expected_value = "$(inherited) HERMES_ENABLE_DEBUGGER=1"
212221
assert_equal(expected_value, react_hermes_debug_config.build_settings[build_setting])
213222
assert_nil(react_hermes_release_config.build_settings[build_setting])
223+
assert_equal(expected_value, react_hermes_debug_config_rename.build_settings[build_setting])
224+
assert_nil(react_hermes_release_config_rename.build_settings[build_setting])
225+
214226
assert_nil(react_core_debug_config.build_settings[build_setting])
215227
assert_nil(react_core_release_config.build_settings[build_setting])
228+
assert_nil(react_core_debug_config_rename.build_settings[build_setting])
229+
assert_nil(react_core_release_config_rename.build_settings[build_setting])
230+
216231
assert_equal(expected_value, hermes_engine_debug_config.build_settings[build_setting])
217232
assert_nil(hermes_engine_release_config.build_settings[build_setting])
233+
assert_equal(expected_value, hermes_engine_debug_config_rename.build_settings[build_setting])
234+
assert_nil(hermes_engine_release_config_rename.build_settings[build_setting])
218235
end
219236

220237
# ================= #

packages/react-native/scripts/cocoapods/utils.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def self.has_pod(installer, name)
4444
end
4545

4646
def self.set_gcc_preprocessor_definition_for_React_hermes(installer)
47-
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-hermes", "Debug")
48-
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-jsinspector", "Debug")
49-
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "hermes-engine", "Debug")
50-
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-RuntimeHermes", "Debug")
47+
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-hermes", :debug)
48+
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-jsinspector", :debug)
49+
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "hermes-engine", :debug)
50+
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-RuntimeHermes", :debug)
5151
end
5252

5353
def self.turn_off_resource_bundle_react_core(installer)
@@ -193,11 +193,11 @@ def self.apply_xcode_15_patch(installer, xcodebuild_manager: Xcodebuild)
193193

194194
private
195195

196-
def self.add_build_settings_to_pod(installer, settings_name, settings_value, target_pod_name, configuration)
196+
def self.add_build_settings_to_pod(installer, settings_name, settings_value, target_pod_name, configuration_type)
197197
installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result|
198198
if pod_name.to_s == target_pod_name
199199
target_installation_result.native_target.build_configurations.each do |config|
200-
if configuration == nil || (configuration != nil && config.name.include?(configuration))
200+
if configuration_type == nil || (configuration_type != nil && config.type == configuration_type)
201201
config.build_settings[settings_name] ||= '$(inherited) '
202202
config.build_settings[settings_name] << settings_value
203203
end

0 commit comments

Comments
 (0)