Skip to content

Commit

Permalink
[fix] backport FlipperConfiguration from main (#34098)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo authored Jul 7, 2022
1 parent 587eb4e commit 23accbf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -188,4 +189,4 @@
}
]
}
}
}
10 changes: 5 additions & 5 deletions packages/rn-tester/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ 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
puts "Installing pods with use_frameworks!"
use_frameworks!
end

def pods(options = {})
def pods(options = {}, use_flipper: false)
project 'RNTesterPods.xcodeproj'

fabric_enabled = true
Expand All @@ -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",
)
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions scripts/cocoapods/FlipperConfiguration.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 4 additions & 6 deletions template/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand All @@ -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}/.."
)
Expand All @@ -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)
Expand Down

0 comments on commit 23accbf

Please sign in to comment.