Skip to content

Commit

Permalink
Use the right logic to decide when we build Hermes from source (#35469)
Browse files Browse the repository at this point in the history
Summary:
This PR backports the changes in 0.71 to apply the same logic to decide when we have to build Hermes from source in both the `hermes-engine.podspec`
and in the `react_native_pods.rb` script.

## Changelog

[iOS] [Fixed] - Use the right logic to decide when we have to build from source

Pull Request resolved: #35469

Test Plan: Working on RC2

Reviewed By: cortinico

Differential Revision: D41529539

Pulled By: cipolleschi

fbshipit-source-id: 879522c2187df28f40f6bc699057e9ecfb7e25fb
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Nov 25, 2022
1 parent 2d1d61a commit 67d0264
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
20 changes: 17 additions & 3 deletions scripts/cocoapods/__tests__/jsengine-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class JSEngineTests < Test::Unit::TestCase
:react_native_path

def setup
File.enable_testing_mode!
@react_native_path = "../.."
podSpy_cleanUp()

end

def teardown
Expand All @@ -25,6 +27,8 @@ def teardown
Pod::UI.reset()
podSpy_cleanUp()
ENV['USE_HERMES'] = '1'
ENV['CI'] = nil
File.reset()
end

# =============== #
Expand Down Expand Up @@ -125,16 +129,26 @@ def test_setupHermes_installsPods_installsFabricSubspecWhenFabricEnabled
# TEST - isBuildingHermesFromSource #
# ================================= #
def test_isBuildingHermesFromSource_whenTarballIsNilAndVersionIsNotNightly_returnTrue
assert_true(is_building_hermes_from_source("1000.0.0"))
assert_true(is_building_hermes_from_source("1000.0.0", '../..'))
end

def test_isBuildingHermesFromSource_whenTarballIsNilAndInReleaseBranch_returnTrue
ENV['CI'] = 'true'
File.mocked_existing_files(['../../sdks/.hermesversion'])
assert_true(is_building_hermes_from_source("0.999.0", '../..'))
end

def test_isBuildingHermesFromSource_whenTarballIsNotNil_returnFalse
ENV['HERMES_ENGINE_TARBALL_PATH'] = "~/Downloads/hermes-ios-debug.tar.gz"
assert_false(is_building_hermes_from_source("1000.0.0"))
assert_false(is_building_hermes_from_source("1000.0.0", '../..'))
end

def test_isBuildingHermesFromSource_whenIsNigthly_returnsFalse
assert_false(is_building_hermes_from_source("0.0.0-"))
assert_false(is_building_hermes_from_source("0.0.0-", '../..'))
end

def test_isBuildingHermesFromSource_whenIsStbleRelease_returnsFalse
assert_false(is_building_hermes_from_source("0.71.0", '../..'))
end

end
19 changes: 12 additions & 7 deletions scripts/cocoapods/jsengine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ def remove_copy_hermes_framework_script_phase(installer, react_native_path)
project.save()
end

def is_building_hermes_from_source(react_native_version)
is_nightly = react_native_version.start_with?('0.0.0-')
has_tarball = ENV['HERMES_ENGINE_TARBALL_PATH'] != nil

# this is the same logic in the hermes-engine.podspec
if has_tarball || is_nightly
# TODO: Use this same function in the `hermes-engine.podspec` somehow
def is_building_hermes_from_source(react_native_version, react_native_path)
if ENV['HERMES_ENGINE_TARBALL_PATH'] != nil
return false
end

return true
isInMain = react_native_version.include?('1000.0.0')

hermestag_file = File.join(react_native_path, "sdks", ".hermesversion")
isInCI = ENV['CI'] === 'true'

isReleaseBranch = File.exist?(hermestag_file) && isInCI


return isInMain || isReleaseBranch
end
2 changes: 1 addition & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))
version = package['version']

if ReactNativePodsUtils.has_pod(installer, 'hermes-engine') && is_building_hermes_from_source(version)
if ReactNativePodsUtils.has_pod(installer, 'hermes-engine') && is_building_hermes_from_source(version, react_native_path)
add_copy_hermes_framework_script_phase(installer, react_native_path)
else
remove_copy_hermes_framework_script_phase(installer, react_native_path)
Expand Down

0 comments on commit 67d0264

Please sign in to comment.