Skip to content

Commit 138af74

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Remove HERMES_BUILD_FROM_SOURCE flag (#35397)
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. ## Changelog: [iOS][Changed] - Remove `HERMES_BUILD_FROM_SOURCE` flag Reviewed By: cortinico, dmytrorykun Differential Revision: D41373439 fbshipit-source-id: ea4aafd187c0ca3ff5c0d79f8aeaaa46ad50f499
1 parent 8b319fd commit 138af74

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

scripts/cocoapods/__tests__/jsengine-test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def setup
1919
end
2020

2121
def teardown
22+
ENV['HERMES_ENGINE_TARBALL_PATH'] = nil
2223
Open3.reset()
2324
Pod::Config.reset()
2425
Pod::UI.reset()
@@ -119,4 +120,21 @@ def test_setupHermes_installsPods_installsFabricSubspecWhenFabricEnabled
119120
assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes")
120121
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12")
121122
end
123+
124+
# ================================= #
125+
# TEST - isBuildingHermesFromSource #
126+
# ================================= #
127+
def test_isBuildingHermesFromSource_whenTarballIsNilAndVersionIsNotNightly_returnTrue
128+
assert_true(is_building_hermes_from_source("1000.0.0"))
129+
end
130+
131+
def test_isBuildingHermesFromSource_whenTarballIsNotNil_returnFalse
132+
ENV['HERMES_ENGINE_TARBALL_PATH'] = "~/Downloads/hermes-ios-debug.tar.gz"
133+
assert_false(is_building_hermes_from_source("1000.0.0"))
134+
end
135+
136+
def test_isBuildingHermesFromSource_whenIsNigthly_returnsFalse
137+
assert_false(is_building_hermes_from_source("0.0.0-"))
138+
end
139+
122140
end

scripts/cocoapods/jsengine.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,15 @@ def remove_copy_hermes_framework_script_phase(installer, react_native_path)
6363
def remove_hermesc_build_dir(react_native_path)
6464
%x(rm -rf #{react_native_path}/sdks/hermes-engine/build_host_hermesc)
6565
end
66+
67+
def is_building_hermes_from_source(react_native_version)
68+
is_nightly = react_native_version.start_with?('0.0.0-')
69+
has_tarball = ENV['HERMES_ENGINE_TARBALL_PATH'] != nil
70+
71+
# this is the same logic in the hermes-engine.podspec
72+
if has_tarball || is_nightly
73+
return false
74+
end
75+
76+
return true
77+
end

scripts/react_native_pods.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
202202
flipper_post_install(installer)
203203
end
204204

205-
if ReactNativePodsUtils.has_pod(installer, 'hermes-engine') && ENV['HERMES_BUILD_FROM_SOURCE'] == "1"
205+
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))
206+
version = package['version']
207+
208+
if ReactNativePodsUtils.has_pod(installer, 'hermes-engine') && is_building_hermes_from_source(version)
206209
add_copy_hermes_framework_script_phase(installer, react_native_path)
207210
else
208211
remove_copy_hermes_framework_script_phase(installer, react_native_path)

sdks/hermes-engine/hermes-engine.podspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ Pod::Spec.new do |spec|
8686

8787
elsif source[:git] then
8888

89-
ENV['HERMES_BUILD_FROM_SOURCE'] = "1"
90-
9189
spec.subspec 'Hermes' do |ss|
9290
ss.source_files = ''
9391
ss.public_header_files = 'API/hermes/*.h'
@@ -114,6 +112,7 @@ Pod::Spec.new do |spec|
114112
# Keep hermesc_path synchronized with .gitignore entry.
115113
ENV['REACT_NATIVE_PATH'] = react_native_path
116114
hermesc_path = "${REACT_NATIVE_PATH}/sdks/hermes-engine/build_host_hermesc"
115+
# NOTE: Prepare command is not run if the pod is not downloaded.
117116
spec.prepare_command = ". #{react_native_path}/sdks/hermes-engine/utils/build-hermesc-xcode.sh #{hermesc_path}"
118117
end
119118

0 commit comments

Comments
 (0)