Skip to content

Commit 23accbf

Browse files
author
Riccardo
authored
[fix] backport FlipperConfiguration from main (#34098)
1 parent 587eb4e commit 23accbf

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"scripts/react_native_pods_utils/script_phases.rb",
5757
"scripts/react_native_pods_utils/script_phases.sh",
5858
"scripts/react_native_pods.rb",
59+
"scripts/cocoapods",
5960
"scripts/react-native-xcode.sh",
6061
"sdks/.hermesversion",
6162
"sdks/hermes-engine",
@@ -188,4 +189,4 @@
188189
}
189190
]
190191
}
191-
}
192+
}

packages/rn-tester/Podfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ platform :ios, '12.4'
88
install! 'cocoapods', :deterministic_uuids => false
99

1010
USE_FRAMEWORKS = ENV['USE_FRAMEWORKS'] == '1'
11+
IN_CI = ENV['CI'] == 'true'
12+
1113
@prefix_path = "../.."
1214

1315
if USE_FRAMEWORKS
1416
puts "Installing pods with use_frameworks!"
1517
use_frameworks!
1618
end
1719

18-
def pods(options = {})
20+
def pods(options = {}, use_flipper: false)
1921
project 'RNTesterPods.xcodeproj'
2022

2123
fabric_enabled = true
@@ -31,6 +33,7 @@ def pods(options = {})
3133
path: @prefix_path,
3234
fabric_enabled: fabric_enabled,
3335
hermes_enabled: hermes_enabled,
36+
flipper_configuration: use_flipper ? FlipperConfiguration.enabled : FlipperConfiguration.disabled,
3437
app_path: "#{Dir.pwd}",
3538
config_file_dir: "#{Dir.pwd}/node_modules",
3639
)
@@ -46,10 +49,7 @@ def pods(options = {})
4649
end
4750

4851
target 'RNTester' do
49-
pods()
50-
if !USE_FRAMEWORKS
51-
use_flipper!
52-
end
52+
pods({}, :use_flipper => !IN_CI && !USE_FRAMEWORKS)
5353
end
5454

5555
target 'RNTesterUnitTests' do
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
# Helper class to configure flipper
7+
class FlipperConfiguration
8+
attr_reader :flipper_enabled
9+
attr_reader :configurations
10+
attr_reader :versions
11+
12+
def initialize(flipper_enabled, configurations, versions)
13+
@flipper_enabled = flipper_enabled
14+
@configurations = configurations
15+
@versions = versions
16+
end
17+
18+
def self.enabled(configurations = ["Debug"], versions = {})
19+
FlipperConfiguration.new(true, configurations, versions)
20+
end
21+
22+
def self.disabled
23+
FlipperConfiguration.new(false, [], {})
24+
end
25+
26+
def == (other)
27+
return @flipper_enabled == other.flipper_enabled &&
28+
@configurations == other.configurations &&
29+
@versions == other.versions
30+
end
31+
end

scripts/react_native_pods.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'json'
77
require 'open3'
88
require 'pathname'
9+
require_relative './cocoapods/FlipperConfiguration.rb'
910
require_relative './react_native_pods_utils/script_phases.rb'
1011

1112
$CODEGEN_OUTPUT_DIR = 'build/generated/ios'
@@ -29,6 +30,9 @@ def use_react_native! (options={})
2930
# Include Hermes dependencies
3031
hermes_enabled = options[:hermes_enabled] ||= false
3132

33+
# Extract Flipper configuration
34+
flipper_configuration = options[:flipper_configuration] ||= FlipperConfiguration.disabled
35+
3236
# Codegen Discovery is required when enabling new architecture.
3337
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
3438
Pod::UI.puts 'Setting USE_CODEGEN_DISCOVERY=1'
@@ -61,8 +65,13 @@ def use_react_native! (options={})
6165
pod 'React-RCTVibration', :path => "#{prefix}/Libraries/Vibration"
6266
pod 'React-Core/RCTWebSocket', :path => "#{prefix}/"
6367

64-
unless production
68+
# CocoaPods `configurations` option ensures that the target is copied only for the specified configurations,
69+
# but those dependencies are still built.
70+
# Flipper doesn't currently compile for release https://github.com/facebook/react-native/issues/33764
71+
# 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.
72+
if flipper_configuration.flipper_enabled && !production
6573
pod 'React-Core/DevSupport', :path => "#{prefix}/"
74+
use_flipper!(flipper_configuration.versions, :configurations => flipper_configuration.configurations)
6675
end
6776

6877
pod 'React-bridging', :path => "#{prefix}/ReactCommon"

template/ios/Podfile

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ
44
platform :ios, '12.4'
55
install! 'cocoapods', :deterministic_uuids => false
66

7+
production = ENV["PRODUCTION"] == "1"
8+
79
target 'HelloWorld' do
810
config = use_native_modules!
911

@@ -13,8 +15,10 @@ target 'HelloWorld' do
1315
use_react_native!(
1416
:path => config[:reactNativePath],
1517
# to enable hermes on iOS, change `false` to `true` and then install pods
18+
:production => production,
1619
:hermes_enabled => flags[:hermes_enabled],
1720
:fabric_enabled => flags[:fabric_enabled],
21+
:flipper_configuration => FlipperConfiguration.enabled,
1822
# An absolute path to your application root.
1923
:app_path => "#{Pod::Config.instance.installation_root}/.."
2024
)
@@ -24,12 +28,6 @@ target 'HelloWorld' do
2428
# Pods for testing
2529
end
2630

27-
# Enables Flipper.
28-
#
29-
# Note that if you have use_frameworks! enabled, Flipper will not work and
30-
# you should disable the next line.
31-
use_flipper!()
32-
3331
post_install do |installer|
3432
react_native_post_install(installer)
3533
__apply_Xcode_12_5_M1_post_install_workaround(installer)

0 commit comments

Comments
 (0)