From 5ae777efd0337b87b3f9e8f56e6dfe0006709806 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 29 Jun 2022 14:50:02 +0100 Subject: [PATCH] fix: backport FlipperConfiguration from main --- package.json | 3 ++- packages/rn-tester/Podfile | 10 ++++---- scripts/cocoapods/FlipperConfiguration.rb | 31 +++++++++++++++++++++++ scripts/react_native_pods.rb | 11 +++++++- template/ios/Podfile | 10 +++----- 5 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 scripts/cocoapods/FlipperConfiguration.rb diff --git a/package.json b/package.json index 2a1d3e0e477420..bee8825bd6fb8b 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "scripts/react_native_pods_utils/script_phases.rb", "scripts/react_native_pods_utils/script_phases.sh", "scripts/react_native_pods.rb", + "scripts/cocoapods", "scripts/react-native-xcode.sh", "sdks/.hermesversion", "sdks/hermes-engine", @@ -188,4 +189,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index b2d0ff24c0420e..da290080cd933a 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -8,6 +8,8 @@ platform :ios, '12.4' install! 'cocoapods', :deterministic_uuids => false USE_FRAMEWORKS = ENV['USE_FRAMEWORKS'] == '1' +IN_CI = ENV['CI'] == 'true' + @prefix_path = "../.." if USE_FRAMEWORKS @@ -15,7 +17,7 @@ if USE_FRAMEWORKS use_frameworks! end -def pods(options = {}) +def pods(options = {}, use_flipper: false) project 'RNTesterPods.xcodeproj' fabric_enabled = true @@ -31,6 +33,7 @@ def pods(options = {}) path: @prefix_path, fabric_enabled: fabric_enabled, hermes_enabled: hermes_enabled, + flipper_configuration: use_flipper ? FlipperConfiguration.enabled : FlipperConfiguration.disabled, app_path: "#{Dir.pwd}", config_file_dir: "#{Dir.pwd}/node_modules", ) @@ -46,10 +49,7 @@ def pods(options = {}) end target 'RNTester' do - pods() - if !USE_FRAMEWORKS - use_flipper! - end + pods({}, :use_flipper => !IN_CI && !USE_FRAMEWORKS) end target 'RNTesterUnitTests' do diff --git a/scripts/cocoapods/FlipperConfiguration.rb b/scripts/cocoapods/FlipperConfiguration.rb new file mode 100644 index 00000000000000..a75383488dbafe --- /dev/null +++ b/scripts/cocoapods/FlipperConfiguration.rb @@ -0,0 +1,31 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Helper class to configure flipper +class FlipperConfiguration + attr_reader :flipper_enabled + attr_reader :configurations + attr_reader :versions + + def initialize(flipper_enabled, configurations, versions) + @flipper_enabled = flipper_enabled + @configurations = configurations + @versions = versions + end + + def self.enabled(configurations = ["Debug"], versions = {}) + FlipperConfiguration.new(true, configurations, versions) + end + + def self.disabled + FlipperConfiguration.new(false, [], {}) + end + + def == (other) + return @flipper_enabled == other.flipper_enabled && + @configurations == other.configurations && + @versions == other.versions + end + end diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 7f6ebab8820075..265fff1b649543 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -6,6 +6,7 @@ require 'json' require 'open3' require 'pathname' +require_relative './cocoapods/FlipperConfiguration.rb' require_relative './react_native_pods_utils/script_phases.rb' $CODEGEN_OUTPUT_DIR = 'build/generated/ios' @@ -29,6 +30,9 @@ def use_react_native! (options={}) # Include Hermes dependencies hermes_enabled = options[:hermes_enabled] ||= false + # Extract Flipper configuration + flipper_configuration = options[:flipper_configuration] ||= FlipperConfiguration.disabled + # Codegen Discovery is required when enabling new architecture. if ENV['RCT_NEW_ARCH_ENABLED'] == '1' Pod::UI.puts 'Setting USE_CODEGEN_DISCOVERY=1' @@ -61,8 +65,13 @@ def use_react_native! (options={}) pod 'React-RCTVibration', :path => "#{prefix}/Libraries/Vibration" pod 'React-Core/RCTWebSocket', :path => "#{prefix}/" - unless production + # CocoaPods `configurations` option ensures that the target is copied only for the specified configurations, + # but those dependencies are still built. + # Flipper doesn't currently compile for release https://github.com/facebook/react-native/issues/33764 + # Setting the production flag to true when build for production make sure that we don't install Flipper in the app in the first place. + if flipper_configuration.flipper_enabled && !production pod 'React-Core/DevSupport', :path => "#{prefix}/" + use_flipper!(flipper_configuration.versions, :configurations => flipper_configuration.configurations) end pod 'React-bridging', :path => "#{prefix}/ReactCommon" diff --git a/template/ios/Podfile b/template/ios/Podfile index 06a02f936c61a0..921942216be27c 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -4,6 +4,8 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ platform :ios, '12.4' install! 'cocoapods', :deterministic_uuids => false +production = ENV["PRODUCTION"] == "1" + target 'HelloWorld' do config = use_native_modules! @@ -13,8 +15,10 @@ target 'HelloWorld' do use_react_native!( :path => config[:reactNativePath], # to enable hermes on iOS, change `false` to `true` and then install pods + :production => production, :hermes_enabled => flags[:hermes_enabled], :fabric_enabled => flags[:fabric_enabled], + :flipper_configuration => FlipperConfiguration.enabled, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) @@ -24,12 +28,6 @@ target 'HelloWorld' do # Pods for testing end - # Enables Flipper. - # - # Note that if you have use_frameworks! enabled, Flipper will not work and - # you should disable the next line. - use_flipper!() - post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer)