Skip to content

Commit

Permalink
Enable Flipper for custom Xcode configurations (#34333)
Browse files Browse the repository at this point in the history
Summary:
Fixed Flipper not recognizing app when using custom Xcode configuration names.

This fixes the problem that renaming the "Debug" Xcode configuration causes Flipper to not work. Despite using the recommended `:configurations` parameters and instructing Cocoapods that it was a debug build (see #34332), it still wouldn't recognize the app due to missing C preprocessor flags, specifically it was missing `-DFB_SONARKIT_ENABLED=1`.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Flipper now supports custom Xcode build configuration names

Pull Request resolved: #34333

Test Plan:
I applied the PR change to 0.68.2 (which work similarly but code was refactored since then). I then used `patch-package` to test the change and the fix worked on 2 separate projects.
Patch-package change equivalent:
```diff
 diff --git a/node_modules/react-native/scripts/react_native_pods.rb b/node_modules/react-native/scripts/react_native_pods.rb
index f2ceeda..2ea57d6 100644
 --- a/node_modules/react-native/scripts/react_native_pods.rb
+++ b/node_modules/react-native/scripts/react_native_pods.rb
@@ -180,7 +180,7 @@ def flipper_post_install(installer)
     # Enable flipper for React-Core Debug configuration
     if target.name == 'React-Core'
       target.build_configurations.each do |config|
-        if config.name == 'Debug'
+        if config.debug?
           config.build_settings['OTHER_CFLAGS'] = "$(inherited) -DFB_SONARKIT_ENABLED=1"
         end
       end
```

**Screen shot of Xcode after the patch has been applied, for RN v0.68.2:**
![Screen Shot 2022-08-02 at 14 31 49](https://user-images.githubusercontent.com/895369/182477178-387df1b2-d86c-4d82-859c-a2d1e6e6d1d0.jpg)

Reviewed By: dmitryrykun

Differential Revision: D38373812

Pulled By: cipolleschi

fbshipit-source-id: d2949927084160bf0c6f8af37a7966dd22fea9a6
  • Loading branch information
scarlac authored and facebook-github-bot committed Aug 9, 2022
1 parent 665b5be commit 1bc9ddb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
12 changes: 7 additions & 5 deletions scripts/cocoapods/__tests__/flipper-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_postInstall_updatesThePodCorrectly

reactCore_target = installer.target_with_name("React-Core")
reactCore_target.build_configurations.each do |config|
if config.name == 'Debug' then
if config.name == 'Debug' || config.name == 'CustomConfig' then
assert_equal(config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'], ['$(inherited)', 'FB_SONARKIT_ENABLED=1'])
else
assert_true(config.build_settings.empty?)
Expand Down Expand Up @@ -134,15 +134,17 @@ def prepare_mocked_installer
TargetMock.new(
"YogaKit",
[
BuildConfigurationMock.new("Debug"),
BuildConfigurationMock.new("Release"),
BuildConfigurationMock.new("Debug", is_debug: true),
BuildConfigurationMock.new("Release", is_debug: false),
BuildConfigurationMock.new("CustomConfig", is_debug: true),
]
),
TargetMock.new(
"React-Core",
[
BuildConfigurationMock.new("Debug"),
BuildConfigurationMock.new("Release"),
BuildConfigurationMock.new("Debug", is_debug: true),
BuildConfigurationMock.new("Release", is_debug: false),
BuildConfigurationMock.new("CustomConfig", is_debug: true),
]
)
]
Expand Down
8 changes: 7 additions & 1 deletion scripts/cocoapods/__tests__/test_utils/InstallerMock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,16 @@ def resolved_build_setting(key, resolve_against_xcconfig: false)
class BuildConfigurationMock
attr_reader :name
attr_reader :build_settings
@is_debug

def initialize(name, build_settings = {})
def initialize(name, build_settings = {}, is_debug: false)
@name = name
@build_settings = build_settings
@is_debug = is_debug
end

def debug?
return @is_debug
end
end

Expand Down
2 changes: 1 addition & 1 deletion scripts/cocoapods/flipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def flipper_post_install(installer)
# Enable flipper for React-Core Debug configuration
if target.name == 'React-Core'
target.build_configurations.each do |config|
if config.name == 'Debug'
if config.debug?
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['$(inherited)', 'FB_SONARKIT_ENABLED=1']
end
end
Expand Down

0 comments on commit 1bc9ddb

Please sign in to comment.