Skip to content

Commit 22e4bdf

Browse files
hramosfacebook-github-bot
authored andcommitted
CocoaPods: Consolidate Hermes and JSC Engine configuration in jsengine.rb
Summary: Move JSC and Hermes CocoaPods configuration to scripts/cocoapods/jsengine.rb. This file provides a setup_jsc! function and a setup_hermes! function that will configure the necessary pod dependencies for each of the supported JavaScript engines. Currently, the JSI and JSC pods are installed in both cases. This will likely change in upcoming changes to how Hermes and JSC are configured. Changelog: [internal] Reviewed By: dmytrorykun Differential Revision: D40459234 fbshipit-source-id: d6c89c7f650b1efcce5622594db7fd726eafc2bc
1 parent 5aeb99e commit 22e4bdf

File tree

7 files changed

+176
-117
lines changed

7 files changed

+176
-117
lines changed

scripts/cocoapods/__tests__/fabric-test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@ def test_setupFabric_installsPods
2626
prefix = "../.."
2727

2828
# Act
29-
setup_fabric!(prefix)
29+
setup_fabric!(:react_native_path => prefix)
3030

3131
# Assert
3232
check_installed_pods(prefix)
3333
end
3434

3535
def check_installed_pods(prefix)
36-
assert_equal($podInvocationCount, 6)
36+
assert_equal($podInvocationCount, 5)
3737

3838
check_pod("React-Fabric", :path => "#{prefix}/ReactCommon")
3939
check_pod("React-rncore", :path => "#{prefix}/ReactCommon")
4040
check_pod("React-graphics", :path => "#{prefix}/ReactCommon/react/renderer/graphics")
41-
check_pod("React-jsc/Fabric", :path => "#{prefix}/ReactCommon/jsi")
4241
check_pod("React-RCTFabric", :path => "#{prefix}/React", :modular_headers => true)
4342
check_pod("RCT-Folly/Fabric", :podspec => "#{prefix}/third-party-podspecs/RCT-Folly.podspec")
4443
end

scripts/cocoapods/__tests__/hermes-test.rb

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
require "test/unit"
7+
require_relative "../jsengine.rb"
8+
require_relative "./test_utils/podSpy.rb"
9+
require_relative "./test_utils/PodMock.rb"
10+
require_relative "./test_utils/Open3Mock.rb"
11+
12+
class JSEngineTests < Test::Unit::TestCase
13+
14+
:react_native_path
15+
16+
def setup
17+
@react_native_path = "../.."
18+
podSpy_cleanUp()
19+
end
20+
21+
def teardown
22+
Open3.reset()
23+
Pod::Config.reset()
24+
Pod::UI.reset()
25+
podSpy_cleanUp()
26+
ENV['USE_HERMES'] = '1'
27+
end
28+
29+
# =============== #
30+
# TEST - setupJsc #
31+
# =============== #
32+
def test_setupJsc_installsPods
33+
# Arrange
34+
fabric_enabled = false
35+
36+
# Act
37+
setup_jsc!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled)
38+
39+
# Assert
40+
assert_equal($podInvocationCount, 2)
41+
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi")
42+
assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi")
43+
end
44+
45+
def test_setupJsc_installsPods_installsFabricSubspecWhenFabricEnabled
46+
# Arrange
47+
fabric_enabled = true
48+
49+
# Act
50+
setup_jsc!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled)
51+
52+
# Assert
53+
assert_equal($podInvocationCount, 3)
54+
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi")
55+
assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi")
56+
assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsi")
57+
end
58+
59+
# ================== #
60+
# TEST - setupHermes #
61+
# ================== #
62+
def test_setupHermes_whenHermesScriptFails_abort
63+
# Arrange
64+
fabric_enabled = false
65+
Pod::Config.instance.installation_root.set_installation_root("Pods/")
66+
Open3.set_returned_status(1)
67+
Open3.set_returned_text("This test\nshould fail")
68+
69+
# Act
70+
assert_raises {
71+
setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled)
72+
}
73+
74+
# Assert
75+
assert_equal(Open3.collected_commands, ["node scripts/hermes/prepare-hermes-for-build"])
76+
assert_equal(Open3.collected_dirs, ["Pods/../.."])
77+
assert_equal(Pod::UI.collected_infoes, ["This test", "should fail"])
78+
assert_equal($podInvocationCount, 0)
79+
assert_equal($podInvocation, {})
80+
end
81+
82+
def test_setupHermes_whenHermesScriptSucceeds_installsPods
83+
# Arrange
84+
fabric_enabled = false
85+
Pod::Config.instance.installation_root.set_installation_root("Pods/")
86+
Open3.set_returned_status(0)
87+
Open3.set_returned_text("This is\nthe text\nreturned by\nprepare-hermes-for-build")
88+
89+
# Act
90+
setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled)
91+
92+
# Assert
93+
assert_equal(Open3.collected_commands, ["node scripts/hermes/prepare-hermes-for-build"])
94+
assert_equal(Open3.collected_dirs, ["Pods/../.."])
95+
assert_equal(Pod::UI.collected_infoes, [
96+
"This is",
97+
"the text",
98+
"returned by",
99+
"prepare-hermes-for-build",
100+
])
101+
assert_equal($podInvocationCount, 5)
102+
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi")
103+
assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes")
104+
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12")
105+
assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec")
106+
end
107+
108+
def test_setupHermes_installsPods_installsFabricSubspecWhenFabricEnabled
109+
# Arrange
110+
fabric_enabled = true
111+
112+
# Act
113+
setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled)
114+
115+
# Assert
116+
assert_equal($podInvocationCount, 6)
117+
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi")
118+
assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi")
119+
assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsi")
120+
assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec")
121+
assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes")
122+
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12")
123+
end
124+
end

scripts/cocoapods/fabric.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
# It sets up the Fabric dependencies.
88
#
99
# @parameter react_native_path: relative path to react-native
10-
def setup_fabric!(react_native_path)
10+
def setup_fabric!(react_native_path: "../node_modules/react-native")
1111
pod 'React-Fabric', :path => "#{react_native_path}/ReactCommon"
1212
pod 'React-rncore', :path => "#{react_native_path}/ReactCommon"
1313
pod 'React-graphics', :path => "#{react_native_path}/ReactCommon/react/renderer/graphics"
14-
pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsi"
1514
pod 'React-RCTFabric', :path => "#{react_native_path}/React", :modular_headers => true
1615
pod 'RCT-Folly/Fabric', :podspec => "#{react_native_path}/third-party-podspecs/RCT-Folly.podspec"
1716
end

scripts/cocoapods/hermes.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.

scripts/cocoapods/jsengine.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
require_relative './utils.rb'
7+
8+
# It sets up the JavaScriptCore and JSI pods.
9+
#
10+
# @parameter react_native_path: relative path to react-native
11+
# @parameter fabric_enabled: whether Fabirc is enabled
12+
def setup_jsc!(react_native_path: "../node_modules/react-native", fabric_enabled: false)
13+
pod 'React-jsi', :path => "#{react_native_path}/ReactCommon/jsi"
14+
pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsi"
15+
if fabric_enabled
16+
pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsi"
17+
end
18+
end
19+
20+
# It sets up the Hermes and JSI pods.
21+
#
22+
# @parameter react_native_path: relative path to react-native
23+
# @parameter fabric_enabled: whether Fabirc is enabled
24+
def setup_hermes!(react_native_path: "../node_modules/react-native", fabric_enabled: false)
25+
# The following captures the output of prepare_hermes for use in tests
26+
prepare_hermes = 'node scripts/hermes/prepare-hermes-for-build'
27+
react_native_dir = Pod::Config.instance.installation_root.join(react_native_path)
28+
prep_output, prep_status = Open3.capture2e(prepare_hermes, :chdir => react_native_dir)
29+
prep_output.split("\n").each { |line| Pod::UI.info line }
30+
abort unless prep_status == 0
31+
32+
pod 'React-jsi', :path => "#{react_native_path}/ReactCommon/jsi"
33+
pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsi"
34+
if fabric_enabled
35+
pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsi"
36+
end
37+
pod 'hermes-engine', :podspec => "#{react_native_path}/sdks/hermes/hermes-engine.podspec"
38+
pod 'React-hermes', :path => "#{react_native_path}/ReactCommon/hermes"
39+
pod 'libevent', '~> 2.1.12'
40+
end

scripts/react_native_pods.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
require 'open3'
88
require 'pathname'
99
require_relative './react_native_pods_utils/script_phases.rb'
10-
require_relative './cocoapods/hermes.rb'
10+
require_relative './cocoapods/jsengine.rb'
1111
require_relative './cocoapods/flipper.rb'
1212
require_relative './cocoapods/fabric.rb'
1313
require_relative './cocoapods/codegen.rb'
@@ -95,11 +95,16 @@ def use_react_native! (
9595

9696
pod 'React-bridging', :path => "#{prefix}/ReactCommon"
9797
pod 'React-cxxreact', :path => "#{prefix}/ReactCommon/cxxreact"
98-
pod 'React-jsi', :path => "#{prefix}/ReactCommon/jsi"
99-
pod 'React-jsc', :path => "#{prefix}/ReactCommon/jsi"
98+
99+
if hermes_enabled
100+
setup_hermes!(:react_native_path => prefix, :fabric_enabled => fabric_enabled)
101+
else
102+
setup_jsc!(:react_native_path => prefix, :fabric_enabled => fabric_enabled)
103+
end
100104
pod 'React-jsidynamic', :path => "#{prefix}/ReactCommon/jsi"
101105
pod 'React-jsiexecutor', :path => "#{prefix}/ReactCommon/jsiexecutor"
102106
pod 'React-jsinspector', :path => "#{prefix}/ReactCommon/jsinspector"
107+
103108
pod 'React-callinvoker', :path => "#{prefix}/ReactCommon/callinvoker"
104109
pod 'React-runtimeexecutor', :path => "#{prefix}/ReactCommon/runtimeexecutor"
105110
pod 'React-perflogger', :path => "#{prefix}/ReactCommon/reactperflogger"
@@ -128,11 +133,9 @@ def use_react_native! (
128133

129134
if fabric_enabled
130135
checkAndGenerateEmptyThirdPartyProvider!(prefix, new_arch_enabled, $CODEGEN_OUTPUT_DIR)
131-
setup_fabric!(prefix)
136+
setup_fabric!(:react_native_path => prefix)
132137
end
133138

134-
install_hermes_if_enabled(hermes_enabled, prefix)
135-
136139
# CocoaPods `configurations` option ensures that the target is copied only for the specified configurations,
137140
# but those dependencies are still built.
138141
# Flipper doesn't currently compile for release https://github.com/facebook/react-native/issues/33764

0 commit comments

Comments
 (0)