From 138af74e3f2aa429eedc8881c8feb6d4a7b5c253 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Mon, 21 Nov 2022 05:21:39 -0800 Subject: [PATCH] Remove `HERMES_BUILD_FROM_SOURCE` flag (#35397) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35397 This Diff removes the `HERMES_BUILD_FROM_SOURCE` that was not always propagated to the original script. This lead to some cases where hermesC was built during `pod install` and then removed by the `react_native_post_install`'s `else` branch. Basically, when the Pods are installed the first time, everything run smoothly. Subsequent invocations of `pod install`, to install other dependencies, for example, will incur in this problem because: 1. Cocoapods will see that hermes-engine is already installed 2. the podspec is not executed, given that the pod has been fetched from the cache 3. The env var is not set (given that the podspec is not executed) 4. the main script sees the env var as not set, `ENV['HERMES_BUILD_FROM_SOURCE'] == "1"` return false 5. The `else` branch is executed, and it removes the `hermesc_build_dir` and the `copy Hermes framework` script phase. ## Changelog: [iOS][Changed] - Remove `HERMES_BUILD_FROM_SOURCE` flag Reviewed By: cortinico, dmytrorykun Differential Revision: D41373439 fbshipit-source-id: ea4aafd187c0ca3ff5c0d79f8aeaaa46ad50f499 --- scripts/cocoapods/__tests__/jsengine-test.rb | 18 ++++++++++++++++++ scripts/cocoapods/jsengine.rb | 12 ++++++++++++ scripts/react_native_pods.rb | 5 ++++- sdks/hermes-engine/hermes-engine.podspec | 3 +-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/scripts/cocoapods/__tests__/jsengine-test.rb b/scripts/cocoapods/__tests__/jsengine-test.rb index 13ad540d5f25bf..303e99949dc9e0 100644 --- a/scripts/cocoapods/__tests__/jsengine-test.rb +++ b/scripts/cocoapods/__tests__/jsengine-test.rb @@ -19,6 +19,7 @@ def setup end def teardown + ENV['HERMES_ENGINE_TARBALL_PATH'] = nil Open3.reset() Pod::Config.reset() Pod::UI.reset() @@ -119,4 +120,21 @@ def test_setupHermes_installsPods_installsFabricSubspecWhenFabricEnabled assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes") assert_equal($podInvocation["libevent"][:version], "~> 2.1.12") end + + # ================================= # + # TEST - isBuildingHermesFromSource # + # ================================= # + def test_isBuildingHermesFromSource_whenTarballIsNilAndVersionIsNotNightly_returnTrue + assert_true(is_building_hermes_from_source("1000.0.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")) + end + + def test_isBuildingHermesFromSource_whenIsNigthly_returnsFalse + assert_false(is_building_hermes_from_source("0.0.0-")) + end + end diff --git a/scripts/cocoapods/jsengine.rb b/scripts/cocoapods/jsengine.rb index 345972449d8802..73030a8062a75e 100644 --- a/scripts/cocoapods/jsengine.rb +++ b/scripts/cocoapods/jsengine.rb @@ -63,3 +63,15 @@ def remove_copy_hermes_framework_script_phase(installer, react_native_path) def remove_hermesc_build_dir(react_native_path) %x(rm -rf #{react_native_path}/sdks/hermes-engine/build_host_hermesc) 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 + return false + end + + return true +end diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 074965bfbd63a6..910213464d0cce 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -202,7 +202,10 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re flipper_post_install(installer) end - if ReactNativePodsUtils.has_pod(installer, 'hermes-engine') && ENV['HERMES_BUILD_FROM_SOURCE'] == "1" + 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) add_copy_hermes_framework_script_phase(installer, react_native_path) else remove_copy_hermes_framework_script_phase(installer, react_native_path) diff --git a/sdks/hermes-engine/hermes-engine.podspec b/sdks/hermes-engine/hermes-engine.podspec index 47973a6f7f4943..9f3b90bf77e8b3 100644 --- a/sdks/hermes-engine/hermes-engine.podspec +++ b/sdks/hermes-engine/hermes-engine.podspec @@ -86,8 +86,6 @@ Pod::Spec.new do |spec| elsif source[:git] then - ENV['HERMES_BUILD_FROM_SOURCE'] = "1" - spec.subspec 'Hermes' do |ss| ss.source_files = '' ss.public_header_files = 'API/hermes/*.h' @@ -114,6 +112,7 @@ Pod::Spec.new do |spec| # Keep hermesc_path synchronized with .gitignore entry. ENV['REACT_NATIVE_PATH'] = react_native_path hermesc_path = "${REACT_NATIVE_PATH}/sdks/hermes-engine/build_host_hermesc" + # NOTE: Prepare command is not run if the pod is not downloaded. spec.prepare_command = ". #{react_native_path}/sdks/hermes-engine/utils/build-hermesc-xcode.sh #{hermesc_path}" end