From 29639e7b9529941a19e6c4488f94d7e46cc3b157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Thu, 7 May 2020 08:34:07 -0700 Subject: [PATCH] Enable with CocoaPods `:configuration` (#28796) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: ~~⚠️ Depends on https://github.com/facebook/flipper/pull/1086 and a new Flipper release.~~ Fixes https://github.com/facebook/react-native/commit/17f025bc26da13da795845a3f7daee65563420c0#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 [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: https://github.com/facebook/react-native/pull/28796 Test Plan: Tested using the changes of https://github.com/facebook/flipper/pull/1086 in a new app that uses RN `master`. Reviewed By: priteshrnandgaonkar Differential Revision: D21449754 Pulled By: passy fbshipit-source-id: 9ff7c7f4ffc32b364b1edd82b94e0b80c3997625 --- scripts/react_native_pods.rb | 33 ++----------------- .../ios/HelloWorld.xcodeproj/project.pbxproj | 4 --- template/ios/HelloWorld/AppDelegate.m | 4 +-- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 5a2726e0d85354..86afd7ff5a0653 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -58,8 +58,8 @@ def use_react_native! (options={}) end def use_flipper!(versions = {}) - versions['Flipper'] ||= '~> 0.37.0' - versions['DoubleConversion'] ||= '1.1.7' + versions['Flipper'] ||= '~> 0.41.1' + versions['Flipper-DoubleConversion'] ||= '1.1.7' versions['Flipper-Folly'] ||= '~> 2.2' versions['Flipper-Glog'] ||= '0.3.6' versions['Flipper-PeerTalk'] ||= '~> 0.0.4' @@ -72,7 +72,7 @@ def use_flipper!(versions = {}) # List all transitive dependencies for FlipperKit pods # to avoid them being linked in Release builds pod 'Flipper', versions['Flipper'], :configuration => 'Debug' - pod 'Flipper-DoubleConversion', versions['DoubleConversion'], :configuration => 'Debug' + pod 'Flipper-DoubleConversion', versions['Flipper-DoubleConversion'], :configuration => 'Debug' pod 'Flipper-Folly', versions['Flipper-Folly'], :configuration => 'Debug' pod 'Flipper-Glog', versions['Flipper-Glog'], :configuration => 'Debug' pod 'Flipper-PeerTalk', versions['Flipper-PeerTalk'], :configuration => 'Debug' @@ -96,31 +96,4 @@ def flipper_post_install(installer) end end end - file_name = Dir.glob("*.xcodeproj")[0] - app_project = Xcodeproj::Project.open(file_name) - app_project.native_targets.each do |target| - target.build_configurations.each do |config| - cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) ' - unless cflags.include? '-DFB_SONARKIT_ENABLED=1' - puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...' - cflags << '-DFB_SONARKIT_ENABLED=1' - end - config.build_settings['OTHER_CFLAGS'] = cflags - if (config.build_settings['OTHER_SWIFT_FLAGS']) - unless config.build_settings['OTHER_SWIFT_FLAGS'].include? '-DFB_SONARKIT_ENABLED' - puts 'Adding -DFB_SONARKIT_ENABLED ...' - swift_flags = config.build_settings['OTHER_SWIFT_FLAGS'] - if swift_flags.split.last != '-Xcc' - config.build_settings['OTHER_SWIFT_FLAGS'] << ' -Xcc' - end - config.build_settings['OTHER_SWIFT_FLAGS'] << ' -DFB_SONARKIT_ENABLED' - end - else - puts 'OTHER_SWIFT_FLAGS does not exist thus assigning it to `$(inherited) -Xcc -DFB_SONARKIT_ENABLED`' - config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -Xcc -DFB_SONARKIT_ENABLED' - end - app_project.save - end - end - installer.pods_project.save end diff --git a/template/ios/HelloWorld.xcodeproj/project.pbxproj b/template/ios/HelloWorld.xcodeproj/project.pbxproj index 7416f98214a3e6..789b1a777b48ef 100644 --- a/template/ios/HelloWorld.xcodeproj/project.pbxproj +++ b/template/ios/HelloWorld.xcodeproj/project.pbxproj @@ -495,10 +495,6 @@ CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; ENABLE_BITCODE = NO; - GCC_PREPROCESSOR_DEFINITIONS = ( - "$(inherited)", - "FB_SONARKIT_ENABLED=1", - ); INFOPLIST_FILE = HelloWorld/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( diff --git a/template/ios/HelloWorld/AppDelegate.m b/template/ios/HelloWorld/AppDelegate.m index c680572d44cce3..91737c5d5bed69 100644 --- a/template/ios/HelloWorld/AppDelegate.m +++ b/template/ios/HelloWorld/AppDelegate.m @@ -4,7 +4,7 @@ #import #import -#if DEBUG +#ifdef FB_SONARKIT_ENABLED #import #import #import @@ -27,7 +27,7 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { -#if DEBUG +#ifdef FB_SONARKIT_ENABLED InitializeFlipper(application); #endif