Skip to content

Commit 7bb1c4e

Browse files
alloyfacebook-github-bot
authored andcommitted
Enable with CocoaPods :configuration (#28796)
Summary: ~~⚠️ Depends on facebook/flipper#1086 and a new Flipper release.~~ Fixes 17f025b#commitcomment-38831234 Currently user’s are being told to add a definition of the `FB_SONARKIT_ENABLED` macro and examples, including those in stock React Native templates, set this for the user by making use of a `post_install` hook in the user’s `Podfile`. This leads to confusion, fragile code [when a user’s project dir structure deviates from vanilla], and is ultimately not necessary as CocoaPods already has dedicated mechanisms to: * specify build settings (through the `xcconfig` property); * and selectively include certain pods only in certain build configurations (e.g. debug). ## 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 --> [iOS] [Changed] - Entirely control Flipper being enabled through inclusion in Podfile and optionally limiting to certain build configurations using the `:configuration` directive. Pull Request resolved: #28796 Test Plan: Tested using the changes of facebook/flipper#1086 in a new app that uses RN `master`. Reviewed By: priteshrnandgaonkar Differential Revision: D21449754 Pulled By: passy fbshipit-source-id: 9ff7c7f4ffc32b364b1edd82b94e0b80c3997625
1 parent 26c120c commit 7bb1c4e

File tree

3 files changed

+5
-36
lines changed

3 files changed

+5
-36
lines changed

scripts/react_native_pods.rb

+3-30
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def use_react_native! (options={})
5858
end
5959

6060
def use_flipper!(versions = {})
61-
versions['Flipper'] ||= '~> 0.37.0'
62-
versions['DoubleConversion'] ||= '1.1.7'
61+
versions['Flipper'] ||= '~> 0.41.1'
62+
versions['Flipper-DoubleConversion'] ||= '1.1.7'
6363
versions['Flipper-Folly'] ||= '~> 2.2'
6464
versions['Flipper-Glog'] ||= '0.3.6'
6565
versions['Flipper-PeerTalk'] ||= '~> 0.0.4'
@@ -72,7 +72,7 @@ def use_flipper!(versions = {})
7272
# List all transitive dependencies for FlipperKit pods
7373
# to avoid them being linked in Release builds
7474
pod 'Flipper', versions['Flipper'], :configuration => 'Debug'
75-
pod 'Flipper-DoubleConversion', versions['DoubleConversion'], :configuration => 'Debug'
75+
pod 'Flipper-DoubleConversion', versions['Flipper-DoubleConversion'], :configuration => 'Debug'
7676
pod 'Flipper-Folly', versions['Flipper-Folly'], :configuration => 'Debug'
7777
pod 'Flipper-Glog', versions['Flipper-Glog'], :configuration => 'Debug'
7878
pod 'Flipper-PeerTalk', versions['Flipper-PeerTalk'], :configuration => 'Debug'
@@ -96,31 +96,4 @@ def flipper_post_install(installer)
9696
end
9797
end
9898
end
99-
file_name = Dir.glob("*.xcodeproj")[0]
100-
app_project = Xcodeproj::Project.open(file_name)
101-
app_project.native_targets.each do |target|
102-
target.build_configurations.each do |config|
103-
cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) '
104-
unless cflags.include? '-DFB_SONARKIT_ENABLED=1'
105-
puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'
106-
cflags << '-DFB_SONARKIT_ENABLED=1'
107-
end
108-
config.build_settings['OTHER_CFLAGS'] = cflags
109-
if (config.build_settings['OTHER_SWIFT_FLAGS'])
110-
unless config.build_settings['OTHER_SWIFT_FLAGS'].include? '-DFB_SONARKIT_ENABLED'
111-
puts 'Adding -DFB_SONARKIT_ENABLED ...'
112-
swift_flags = config.build_settings['OTHER_SWIFT_FLAGS']
113-
if swift_flags.split.last != '-Xcc'
114-
config.build_settings['OTHER_SWIFT_FLAGS'] << ' -Xcc'
115-
end
116-
config.build_settings['OTHER_SWIFT_FLAGS'] << ' -DFB_SONARKIT_ENABLED'
117-
end
118-
else
119-
puts 'OTHER_SWIFT_FLAGS does not exist thus assigning it to `$(inherited) -Xcc -DFB_SONARKIT_ENABLED`'
120-
config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -Xcc -DFB_SONARKIT_ENABLED'
121-
end
122-
app_project.save
123-
end
124-
end
125-
installer.pods_project.save
12699
end

template/ios/HelloWorld.xcodeproj/project.pbxproj

-4
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,6 @@
336336
CLANG_ENABLE_MODULES = YES;
337337
CURRENT_PROJECT_VERSION = 1;
338338
ENABLE_BITCODE = NO;
339-
GCC_PREPROCESSOR_DEFINITIONS = (
340-
"$(inherited)",
341-
"FB_SONARKIT_ENABLED=1",
342-
);
343339
INFOPLIST_FILE = HelloWorld/Info.plist;
344340
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
345341
OTHER_LDFLAGS = (

template/ios/HelloWorld/AppDelegate.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#import <React/RCTBundleURLProvider.h>
55
#import <React/RCTRootView.h>
66

7-
#if DEBUG
7+
#ifdef FB_SONARKIT_ENABLED
88
#import <FlipperKit/FlipperClient.h>
99
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
1010
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
@@ -27,7 +27,7 @@ @implementation AppDelegate
2727

2828
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2929
{
30-
#if DEBUG
30+
#ifdef FB_SONARKIT_ENABLED
3131
InitializeFlipper(application);
3232
#endif
3333

0 commit comments

Comments
 (0)