Skip to content

Commit

Permalink
Enable hermes debugger by configuration type instead of configuration…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
benhandanyan authored and facebook-github-bot committed Dec 9, 2024
1 parent 0916d53 commit eda4f18
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def initialize(name, build_settings = {}, is_debug: false)
def debug?
return @is_debug
end

def type
@is_debug ? :debug : :release
end
end

class TargetInstallationResultMock
Expand Down
35 changes: 26 additions & 9 deletions packages/react-native/scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,24 @@ def test_SetGCCPreprocessorDefinitionForHermes_itSetsThePreprocessorForDebug
react_hermes_name = "React-hermes"
react_core_name = "React-Core"
hermes_engine_name = "hermes-engine"
react_hermes_debug_config = BuildConfigurationMock.new("Debug")
react_hermes_release_config = BuildConfigurationMock.new("Release")
react_core_debug_config = BuildConfigurationMock.new("Debug")
react_core_release_config = BuildConfigurationMock.new("Release")
hermes_engine_debug_config = BuildConfigurationMock.new("Debug")
hermes_engine_release_config = BuildConfigurationMock.new("Release")
react_hermes_target = TargetMock.new(react_hermes_name, [react_hermes_debug_config, react_hermes_release_config])
react_core_target = TargetMock.new(react_core_name, [react_core_debug_config, react_core_release_config])
hermes_engine_target = TargetMock.new(hermes_engine_name, [hermes_engine_debug_config, hermes_engine_release_config])

react_hermes_debug_config = BuildConfigurationMock.new("Debug", {}, is_debug: true)
react_hermes_release_config = BuildConfigurationMock.new("Release", {}, is_debug: false)
react_hermes_debug_config_rename = BuildConfigurationMock.new("Development", {}, is_debug: true)
react_hermes_release_config_rename = BuildConfigurationMock.new("Production", {}, is_debug: false)
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])

react_core_debug_config = BuildConfigurationMock.new("Debug", {}, is_debug: true)
react_core_release_config = BuildConfigurationMock.new("Release", {}, is_debug: false)
react_core_debug_config_rename = BuildConfigurationMock.new("Development", {}, is_debug: true)
react_core_release_config_rename = BuildConfigurationMock.new("Production", {}, is_debug: false)
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])

hermes_engine_debug_config = BuildConfigurationMock.new("Debug", {}, is_debug: true)
hermes_engine_release_config = BuildConfigurationMock.new("Release", {}, is_debug: false)
hermes_engine_debug_config_rename = BuildConfigurationMock.new("Development", {}, is_debug: true)
hermes_engine_release_config_rename = BuildConfigurationMock.new("Production", {}, is_debug: false)
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])

installer = InstallerMock.new(
:pod_target_installation_results => {
Expand All @@ -211,10 +220,18 @@ def test_SetGCCPreprocessorDefinitionForHermes_itSetsThePreprocessorForDebug
expected_value = "$(inherited) HERMES_ENABLE_DEBUGGER=1"
assert_equal(expected_value, react_hermes_debug_config.build_settings[build_setting])
assert_nil(react_hermes_release_config.build_settings[build_setting])
assert_equal(expected_value, react_hermes_debug_config_rename.build_settings[build_setting])
assert_nil(react_hermes_release_config_rename.build_settings[build_setting])

assert_nil(react_core_debug_config.build_settings[build_setting])
assert_nil(react_core_release_config.build_settings[build_setting])
assert_nil(react_core_debug_config_rename.build_settings[build_setting])
assert_nil(react_core_release_config_rename.build_settings[build_setting])

assert_equal(expected_value, hermes_engine_debug_config.build_settings[build_setting])
assert_nil(hermes_engine_release_config.build_settings[build_setting])
assert_equal(expected_value, hermes_engine_debug_config_rename.build_settings[build_setting])
assert_nil(hermes_engine_release_config_rename.build_settings[build_setting])
end

# ================= #
Expand Down
12 changes: 6 additions & 6 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def self.has_pod(installer, name)
end

def self.set_gcc_preprocessor_definition_for_React_hermes(installer)
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-hermes", "Debug")
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-jsinspector", "Debug")
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "hermes-engine", "Debug")
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-RuntimeHermes", "Debug")
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-hermes", :debug)
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-jsinspector", :debug)
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "hermes-engine", :debug)
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "HERMES_ENABLE_DEBUGGER=1", "React-RuntimeHermes", :debug)
end

def self.turn_off_resource_bundle_react_core(installer)
Expand Down Expand Up @@ -193,11 +193,11 @@ def self.apply_xcode_15_patch(installer, xcodebuild_manager: Xcodebuild)

private

def self.add_build_settings_to_pod(installer, settings_name, settings_value, target_pod_name, configuration)
def self.add_build_settings_to_pod(installer, settings_name, settings_value, target_pod_name, configuration_type)
installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result|
if pod_name.to_s == target_pod_name
target_installation_result.native_target.build_configurations.each do |config|
if configuration == nil || (configuration != nil && config.name.include?(configuration))
if configuration_type == nil || (configuration_type != nil && config.type == configuration_type)
config.build_settings[settings_name] ||= '$(inherited) '
config.build_settings[settings_name] << settings_value
end
Expand Down

0 comments on commit eda4f18

Please sign in to comment.