Skip to content

Commit 0bd5239

Browse files
f-melonifacebook-github-bot
authored andcommitted
Move use_flipper logic inside use_react_native and simplify the Flipper dependencies logic (#33882)
Summary: This PR tries to simplify the `use_flipper` logic: - makes `use_flipper` a configuration inside `use_react_native`'s options - uses the already present `production` flag in the `use_react_native`'s options to decide if add or not the Flipper pods - Simplifies the logic to download the flipper dependencies This PR also adds a workaround for #33764 ## 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] - Move `use_flipper` logic inside `use_react_native` and simplify the Flipper dependencies logic Pull Request resolved: #33882 Test Plan: Executed a pod install with and without flipper and with isProduction true Reviewed By: cipolleschi Differential Revision: D36592338 Pulled By: f-meloni fbshipit-source-id: 3c3f773151513e27e251f18865986e942a96ffd9
1 parent 9596bf0 commit 0bd5239

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

packages/rn-tester/Podfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ def pods(options = {})
3232
path: @prefix_path,
3333
fabric_enabled: fabric_enabled,
3434
hermes_enabled: hermes_enabled,
35+
flipper_configuration: USE_FRAMEWORKS ? FlipperConfiguration.disabled : FlipperConfiguration.enabled,
3536
app_path: "#{Dir.pwd}",
3637
config_file_dir: "#{Dir.pwd}/node_modules",
38+
production: !ENV['PRODUCTION'].nil?
3739
)
3840
pod 'ReactCommon/turbomodule/samples', :path => "#{@prefix_path}/ReactCommon"
3941

@@ -48,9 +50,6 @@ end
4850

4951
target 'RNTester' do
5052
pods()
51-
if !USE_FRAMEWORKS
52-
use_flipper!
53-
end
5453
end
5554

5655
target 'RNTesterUnitTests' do

scripts/cocoapods/__tests__/flipper-test.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,15 @@ def setup
1616
# =========================== #
1717
# TEST - Install Dependencies #
1818
# =========================== #
19-
def test_installFlipperDependencies_whenProductionIsFalse_installDependencies
19+
def test_installFlipperDependencies_installDependencies
2020
# Act
21-
install_flipper_dependencies(false, '../..')
21+
install_flipper_dependencies('../..')
2222

2323
# Assert
2424
assert_equal($podInvocationCount, 1)
2525
assert_equal($podInvocation['React-Core/DevSupport'][:path], "../../" )
2626
end
2727

28-
def test_installFlipperDependencies_whenProductionIsTrue_skipDependencies
29-
# Act
30-
install_flipper_dependencies(true, '../..')
31-
32-
# Assert
33-
assert_equal($podInvocationCount, 0)
34-
assert_true($podInvocation.empty?)
35-
end
36-
3728
# ======================= #
3829
# TEST - Use Flipper Pods #
3930
# ======================= #

scripts/cocoapods/flipper.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
#
2323
# @parameter production: a boolean that indicates whether we are in production or not.
2424
# @parameter pathToReactNative: the path to the React Native installation
25-
def install_flipper_dependencies(production, pathToReactNative)
26-
unless production
27-
pod 'React-Core/DevSupport', :path => "#{pathToReactNative}/"
28-
end
25+
def install_flipper_dependencies(pathToReactNative)
26+
pod 'React-Core/DevSupport', :path => "#{pathToReactNative}/"
2927
end
3028

3129

@@ -92,3 +90,23 @@ def flipper_post_install(installer)
9290
end
9391
end
9492
end
93+
94+
class FlipperConfiguration
95+
attr_reader :flipper_enabled
96+
attr_reader :configurations
97+
attr_reader :versions
98+
99+
def initialize(flipper_enabled, configurations, versions)
100+
@flipper_enabled = flipper_enabled
101+
@configurations = configurations
102+
@versions = versions
103+
end
104+
105+
def self.enabled(configurations = ["Debug"], versions = {})
106+
return FlipperConfiguration.new(true, configurations, versions)
107+
end
108+
109+
def self.disabled
110+
return FlipperConfiguration.new(false, [], {})
111+
end
112+
end

scripts/react_native_pods.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def use_react_native! (options={})
3636
# Include Hermes dependencies
3737
hermes_enabled = options[:hermes_enabled] ||= false
3838

39+
flipper_configuration = options[:flipper_configuration] ||= FlipperConfiguration.disabled
40+
3941
if `/usr/sbin/sysctl -n hw.optional.arm64 2>&1`.to_i == 1 && !RUBY_PLATFORM.include?('arm64')
4042
Pod::UI.warn 'Do not use "pod install" from inside Rosetta2 (x86_64 emulation on arm64).'
4143
Pod::UI.warn ' - Emulated x86_64 is slower than native arm64'
@@ -62,8 +64,6 @@ def use_react_native! (options={})
6264
pod 'React-RCTVibration', :path => "#{prefix}/Libraries/Vibration"
6365
pod 'React-Core/RCTWebSocket', :path => "#{prefix}/"
6466

65-
install_flipper_dependencies(production, prefix)
66-
6767
pod 'React-bridging', :path => "#{prefix}/ReactCommon/react/bridging"
6868
pod 'React-cxxreact', :path => "#{prefix}/ReactCommon/cxxreact"
6969
pod 'React-jsi', :path => "#{prefix}/ReactCommon/jsi"
@@ -128,6 +128,11 @@ def use_react_native! (options={})
128128

129129
end
130130

131+
if flipper_configuration.flipper_enabled && !production
132+
install_flipper_dependencies(prefix)
133+
use_flipper_pods(flipper_configuration.versions, :configurations => flipper_configuration.configurations)
134+
end
135+
131136
pods_to_update = LocalPodspecPatch.pods_to_update(options)
132137
if !pods_to_update.empty?
133138
if Pod::Lockfile.public_instance_methods.include?(:detect_changes_with_podfile)
@@ -142,6 +147,7 @@ def get_default_flags()
142147
flags = {
143148
:fabric_enabled => false,
144149
:hermes_enabled => false,
150+
:flipper_configuration => FlipperConfiguration.disabled
145151
}
146152

147153
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
@@ -153,6 +159,7 @@ def get_default_flags()
153159
end
154160

155161
def use_flipper!(versions = {}, configurations: ['Debug'])
162+
Pod::UI.warn "use_flipper is deprecated, use the flipper_configuration option in the use_react_native function"
156163
use_flipper_pods(versions, :configurations => configurations)
157164
end
158165

template/ios/Podfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ target 'HelloWorld' do
1616
# You can enabled/disable it manually by replacing `flags[:hermes_enabled]` with `true` or `false`.
1717
:hermes_enabled => flags[:hermes_enabled],
1818
:fabric_enabled => flags[:fabric_enabled],
19+
# Enables Flipper.
20+
#
21+
# Note that if you have use_frameworks! enabled, Flipper will not work and
22+
# you should disable the next line.
23+
:flipper_configuration => FlipperConfiguration.enabled,
1924
# An absolute path to your application root.
2025
:app_path => "#{Pod::Config.instance.installation_root}/.."
2126
)
@@ -25,12 +30,6 @@ target 'HelloWorld' do
2530
# Pods for testing
2631
end
2732

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

0 commit comments

Comments
 (0)