Files
react-native/scripts/cocoapods/jsengine.rb
T
Riccardo Cipolleschi 8f2c7ff9f2 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.

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

Reviewed By: cortinico, dmytrorykun

Differential Revision: D41373439

fbshipit-source-id: ea4aafd187c0ca3ff5c0d79f8aeaaa46ad50f499
2022-11-22 15:57:12 +00:00

73 lines
3.0 KiB
Ruby

# 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 '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
def add_copy_hermes_framework_script_phase(installer, react_native_path)
utils_dir = File.join(react_native_path, "sdks", "hermes-engine", "utils")
phase_name = "[RN]Copy Hermes framework"
project = installer.generated_aggregate_targets.first.user_project
target = project.targets.first
if target.shell_script_build_phases.none? { |phase| phase.name == phase_name }
phase = target.new_shell_script_build_phase(phase_name)
phase.shell_script = ". #{utils_dir}/copy-hermes-xcode.sh"
project.save()
end
end
def remove_copy_hermes_framework_script_phase(installer, react_native_path)
utils_dir = File.join(react_native_path, "sdks", "hermes-engine", "utils")
phase_name = "[RN]Copy Hermes framework"
project = installer.generated_aggregate_targets.first.user_project
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