forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CocoaPods: Consolidate Hermes and JSC Engine configuration in jsengin…
…e.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
- Loading branch information
1 parent
1e5a5cb
commit 508dbcf
Showing
7 changed files
with
176 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# 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. | ||
|
||
require "test/unit" | ||
require_relative "../jsengine.rb" | ||
require_relative "./test_utils/podSpy.rb" | ||
require_relative "./test_utils/PodMock.rb" | ||
require_relative "./test_utils/Open3Mock.rb" | ||
|
||
class JSEngineTests < Test::Unit::TestCase | ||
|
||
:react_native_path | ||
|
||
def setup | ||
@react_native_path = "../.." | ||
podSpy_cleanUp() | ||
end | ||
|
||
def teardown | ||
Open3.reset() | ||
Pod::Config.reset() | ||
Pod::UI.reset() | ||
podSpy_cleanUp() | ||
ENV['USE_HERMES'] = '1' | ||
end | ||
|
||
# =============== # | ||
# TEST - setupJsc # | ||
# =============== # | ||
def test_setupJsc_installsPods | ||
# Arrange | ||
fabric_enabled = false | ||
|
||
# Act | ||
setup_jsc!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) | ||
|
||
# Assert | ||
assert_equal($podInvocationCount, 2) | ||
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") | ||
assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") | ||
end | ||
|
||
def test_setupJsc_installsPods_installsFabricSubspecWhenFabricEnabled | ||
# Arrange | ||
fabric_enabled = true | ||
|
||
# Act | ||
setup_jsc!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) | ||
|
||
# Assert | ||
assert_equal($podInvocationCount, 3) | ||
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") | ||
assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") | ||
assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsi") | ||
end | ||
|
||
# ================== # | ||
# TEST - setupHermes # | ||
# ================== # | ||
def test_setupHermes_whenHermesScriptFails_abort | ||
# Arrange | ||
fabric_enabled = false | ||
Pod::Config.instance.installation_root.set_installation_root("Pods/") | ||
Open3.set_returned_status(1) | ||
Open3.set_returned_text("This test\nshould fail") | ||
|
||
# Act | ||
assert_raises { | ||
setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) | ||
} | ||
|
||
# Assert | ||
assert_equal(Open3.collected_commands, ["node scripts/hermes/prepare-hermes-for-build"]) | ||
assert_equal(Open3.collected_dirs, ["Pods/../.."]) | ||
assert_equal(Pod::UI.collected_infoes, ["This test", "should fail"]) | ||
assert_equal($podInvocationCount, 0) | ||
assert_equal($podInvocation, {}) | ||
end | ||
|
||
def test_setupHermes_whenHermesScriptSucceeds_installsPods | ||
# Arrange | ||
fabric_enabled = false | ||
Pod::Config.instance.installation_root.set_installation_root("Pods/") | ||
Open3.set_returned_status(0) | ||
Open3.set_returned_text("This is\nthe text\nreturned by\nprepare-hermes-for-build") | ||
|
||
# Act | ||
setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) | ||
|
||
# Assert | ||
assert_equal(Open3.collected_commands, ["node scripts/hermes/prepare-hermes-for-build"]) | ||
assert_equal(Open3.collected_dirs, ["Pods/../.."]) | ||
assert_equal(Pod::UI.collected_infoes, [ | ||
"This is", | ||
"the text", | ||
"returned by", | ||
"prepare-hermes-for-build", | ||
]) | ||
assert_equal($podInvocationCount, 5) | ||
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") | ||
assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes") | ||
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12") | ||
assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec") | ||
end | ||
|
||
def test_setupHermes_installsPods_installsFabricSubspecWhenFabricEnabled | ||
# Arrange | ||
fabric_enabled = true | ||
|
||
# Act | ||
setup_hermes!(:react_native_path => @react_native_path, :fabric_enabled => fabric_enabled) | ||
|
||
# Assert | ||
assert_equal($podInvocationCount, 6) | ||
assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") | ||
assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") | ||
assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsi") | ||
assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec") | ||
assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes") | ||
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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. | ||
|
||
require_relative './utils.rb' | ||
|
||
# It sets up the JavaScriptCore and JSI pods. | ||
# | ||
# @parameter react_native_path: relative path to react-native | ||
# @parameter fabric_enabled: whether Fabirc is enabled | ||
def setup_jsc!(react_native_path: "../node_modules/react-native", fabric_enabled: false) | ||
pod 'React-jsi', :path => "#{react_native_path}/ReactCommon/jsi" | ||
pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsi" | ||
if fabric_enabled | ||
pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsi" | ||
end | ||
end | ||
|
||
# It sets up the Hermes and JSI pods. | ||
# | ||
# @parameter react_native_path: relative path to react-native | ||
# @parameter fabric_enabled: whether Fabirc is enabled | ||
def setup_hermes!(react_native_path: "../node_modules/react-native", fabric_enabled: false) | ||
# The following captures the output of prepare_hermes for use in tests | ||
prepare_hermes = 'node scripts/hermes/prepare-hermes-for-build' | ||
react_native_dir = Pod::Config.instance.installation_root.join(react_native_path) | ||
prep_output, prep_status = Open3.capture2e(prepare_hermes, :chdir => react_native_dir) | ||
prep_output.split("\n").each { |line| Pod::UI.info line } | ||
abort unless prep_status == 0 | ||
|
||
pod 'React-jsi', :path => "#{react_native_path}/ReactCommon/jsi" | ||
pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsi" | ||
if fabric_enabled | ||
pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsi" | ||
end | ||
pod 'hermes-engine', :podspec => "#{react_native_path}/sdks/hermes/hermes-engine.podspec" | ||
pod 'React-hermes', :path => "#{react_native_path}/ReactCommon/hermes" | ||
pod 'libevent', '~> 2.1.12' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters