From 1bc9ddbce393be9466cb87124d3e34a19abb8e5d Mon Sep 17 00:00:00 2001 From: Seph Soliman Date: Tue, 9 Aug 2022 10:14:23 -0700 Subject: [PATCH] Enable Flipper for custom Xcode configurations (#34333) 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 https://github.com/facebook/react-native/issues/34332), it still wouldn't recognize the app due to missing C preprocessor flags, specifically it was missing `-DFB_SONARKIT_ENABLED=1`. ## Changelog [General] [Fixed] - Flipper now supports custom Xcode build configuration names Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- scripts/cocoapods/__tests__/flipper-test.rb | 12 +++++++----- .../cocoapods/__tests__/test_utils/InstallerMock.rb | 8 +++++++- scripts/cocoapods/flipper.rb | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/cocoapods/__tests__/flipper-test.rb b/scripts/cocoapods/__tests__/flipper-test.rb index feffeb5c49a..abea34a157e 100644 --- a/scripts/cocoapods/__tests__/flipper-test.rb +++ b/scripts/cocoapods/__tests__/flipper-test.rb @@ -85,7 +85,7 @@ class FlipperTests < Test::Unit::TestCase 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?) @@ -134,15 +134,17 @@ class FlipperTests < Test::Unit::TestCase 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), ] ) ] diff --git a/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb b/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb index e58cbbef716..f10a6109b69 100644 --- a/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb +++ b/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb @@ -174,10 +174,16 @@ end 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 diff --git a/scripts/cocoapods/flipper.rb b/scripts/cocoapods/flipper.rb index e2bfe76fdf6..5bf0d01c5b6 100644 --- a/scripts/cocoapods/flipper.rb +++ b/scripts/cocoapods/flipper.rb @@ -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