Skip to content

Commit

Permalink
Remove HERMES_BUILD_FROM_SOURCE flag (#35397)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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.

[iOS][Changed] - Remove `HERMES_BUILD_FROM_SOURCE` flag

Reviewed By: cortinico, dmytrorykun

Differential Revision: D41373439

fbshipit-source-id: ea4aafd187c0ca3ff5c0d79f8aeaaa46ad50f499
  • Loading branch information
cipolleschi authored and Riccardo Cipolleschi committed Nov 22, 2022
1 parent a7792da commit 8f2c7ff
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
18 changes: 18 additions & 0 deletions scripts/cocoapods/__tests__/jsengine-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setup
end

def teardown
ENV['HERMES_ENGINE_TARBALL_PATH'] = nil
Open3.reset()
Pod::Config.reset()
Pod::UI.reset()
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions scripts/cocoapods/jsengine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ def remove_copy_hermes_framework_script_phase(installer, react_native_path)
project.targets.first.shell_script_build_phases.delete_if { |phase| phase.name == phase_name }
project.save()
end

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
5 changes: 4 additions & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand Down

0 comments on commit 8f2c7ff

Please sign in to comment.