mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
c540ff7bd1
Summary: This PR is a follow up of https://github.com/facebook/react-native/pull/35075 and https://github.com/facebook/react-native/commit/1546666a6d713ef756b2f11de9581e3b2bbe08dc to ensure that even in the local e2e testing scenario the new maven approach is followed - without this, RNTestProject on Android won't work, like so: <img width="1905" alt="Screenshot 2022-10-27 at 12 15 38" src="https://user-images.githubusercontent.com/16104054/198334105-30fb2037-4e7c-4814-8c3f-2412ba0bd49f.png"> And iOS will always build everything from source every time. This PR addresses both by generating the artifacts locally, and passing them to RNTestProject as if they were coming from a url (mimicking as closely as possible the behaviour for the final user) In doing so, there's been some refactoring to prep the ground for follow up work. * refactor CI to rely less on scripts directly in the CircleCI config, but invoke .js ones * we should be able to trigger more the "manual" artifacts generation so that it will only happen once between RNTester and RNTestProject, and we can pass existing artifacts to the other flows. * once all of this in place, a very good improvement would be to be able to download the maven artifacts kind of like nightlies and stables do. This will only be viable by checking that there's no local changes, after which there needs to be logic to pull down from CircleCI the artifacts based on git commit <-> circleCI job references. --- While at it, I've also fixed the hermes-engine podspec logic for detecting if it's on CI: basically the local e2e script needs to align with the changes done here: https://github.com/facebook/react-native/commit/4b512077354eb4702ce144e9958d7513c1607275 but as you can see there, the condition was actually inconsistent across the various files, so realigned to `CI === 'true'`. We probably didn't catch that so far 'cause the other condition in the hermes podspect (existence of `hermestag_file`) is only true on release branches and this new logic has not been in any release branches yet. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Internal] [Fixed] - add logic to local e2e script to handle maven local for iOS and Android accordingly Pull Request resolved: https://github.com/facebook/react-native/pull/35104 Test Plan: Run ` yarn test-e2e-local -t RNTestProject -p Android` successfully. Run ` yarn test-e2e-local -t RNTestProject -p iOS` successfully. On the pod install stage, you will see `[Hermes] Using pre-built Hermes binaries from local path.` Reviewed By: dmytrorykun Differential Revision: D40893239 Pulled By: cipolleschi fbshipit-source-id: a31217ec4f177383c62292d00fabc4cbe4391cfd
139 lines
5.8 KiB
Ruby
139 lines
5.8 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 "json"
|
|
require_relative "./hermes-utils.rb"
|
|
|
|
react_native_path = File.join(__dir__, "..", "..")
|
|
|
|
# Whether Hermes is built for Release or Debug is determined by the PRODUCTION envvar.
|
|
build_type = ENV['PRODUCTION'] == "1" ? :release : :debug
|
|
|
|
# package.json
|
|
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))
|
|
version = package['version']
|
|
|
|
# sdks/.hermesversion
|
|
hermestag_file = File.join(react_native_path, "sdks", ".hermesversion")
|
|
isInCI = ENV['CI'] === 'true'
|
|
|
|
source = {}
|
|
git = "https://github.com/facebook/hermes.git"
|
|
|
|
isInMain = version.include?('1000.0.0')
|
|
isNightly = version.start_with?('0.0.0-')
|
|
|
|
if ENV.has_key?('HERMES_ENGINE_TARBALL_PATH')
|
|
Pod::UI.puts '[Hermes] Using pre-built Hermes binaries from local path.' if Object.const_defined?("Pod::UI")
|
|
source[:http] = "file://#{ENV['HERMES_ENGINE_TARBALL_PATH']}"
|
|
elsif isInMain
|
|
Pod::UI.puts '[Hermes] Installing hermes-engine may take slightly longer, building Hermes compiler from source...'.yellow if Object.const_defined?("Pod::UI")
|
|
source[:git] = git
|
|
source[:commit] = `git ls-remote https://github.com/facebook/hermes main | cut -f 1`.strip
|
|
elsif isNightly
|
|
Pod::UI.puts '[Hermes] Nightly version, download pre-built for Hermes'.yellow if Object.const_defined?("Pod::UI")
|
|
destination_path = download_nightly_hermes(react_native_path, version)
|
|
# set tarball as hermes engine
|
|
source[:http] = "file://#{destination_path}"
|
|
elsif File.exists?(hermestag_file) && isInCI
|
|
Pod::UI.puts '[Hermes] Detected that you are on a React Native release branch, building Hermes from source but fetched from tag...'.yellow if Object.const_defined?("Pod::UI")
|
|
hermestag = File.read(hermestag_file).strip
|
|
source[:git] = git
|
|
source[:tag] = hermestag
|
|
else
|
|
# Sample url from Maven:
|
|
# https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/0.71.0/react-native-artifacts-0.71.0-hermes-ios-debug.tar.gz
|
|
source[:http] = "https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/#{version}/react-native-artifacts-#{version}-hermes-ios-#{build_type.to_s}.tar.gz"
|
|
end
|
|
|
|
Pod::Spec.new do |spec|
|
|
spec.name = "hermes-engine"
|
|
spec.version = version
|
|
spec.summary = "Hermes is a small and lightweight JavaScript engine optimized for running React Native."
|
|
spec.description = "Hermes is a JavaScript engine optimized for fast start-up of React Native apps. It features ahead-of-time static optimization and compact bytecode."
|
|
spec.homepage = "https://hermesengine.dev"
|
|
spec.license = package['license']
|
|
spec.author = "Facebook"
|
|
spec.source = source
|
|
spec.platforms = { :osx => "10.13", :ios => "12.4" }
|
|
|
|
spec.preserve_paths = '**/*.*'
|
|
spec.source_files = ''
|
|
|
|
spec.xcconfig = {
|
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
|
"CLANG_CXX_LIBRARY" => "compiler-default"
|
|
}.merge!(build_type == :debug ? { "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" } : {})
|
|
|
|
if source[:http] then
|
|
|
|
spec.subspec 'Pre-built' do |ss|
|
|
ss.preserve_paths = ["destroot/bin/*"].concat(build_type == :debug ? ["**/*.{h,c,cpp}"] : [])
|
|
ss.source_files = "destroot/include/**/*.h"
|
|
ss.exclude_files = ["destroot/include/jsi/jsi/JSIDynamic.{h,cpp}", "destroot/include/jsi/jsi/jsilib-*.{h,cpp}"]
|
|
ss.header_mappings_dir = "destroot/include"
|
|
ss.ios.vendored_frameworks = "destroot/Library/Frameworks/universal/hermes.xcframework"
|
|
ss.osx.vendored_frameworks = "destroot/Library/Frameworks/macosx/hermes.framework"
|
|
end
|
|
|
|
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'
|
|
ss.header_dir = 'hermes'
|
|
end
|
|
|
|
spec.subspec 'JSI' do |ss|
|
|
ss.source_files = ''
|
|
ss.public_header_files = 'API/jsi/jsi/*.h'
|
|
ss.header_dir = 'jsi'
|
|
end
|
|
|
|
spec.subspec 'Public' do |ss|
|
|
ss.source_files = ''
|
|
ss.public_header_files = 'public/hermes/Public/*.h'
|
|
ss.header_dir = 'hermes/Public'
|
|
end
|
|
|
|
hermesc_path = ""
|
|
|
|
if ENV.has_key?('HERMES_OVERRIDE_HERMESC_PATH') && File.exist?(ENV['HERMES_OVERRIDE_HERMESC_PATH']) then
|
|
hermesc_path = ENV['HERMES_OVERRIDE_HERMESC_PATH']
|
|
else
|
|
# 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"
|
|
spec.prepare_command = ". #{react_native_path}/sdks/hermes-engine/utils/build-hermesc-xcode.sh #{hermesc_path}"
|
|
end
|
|
|
|
spec.user_target_xcconfig = {
|
|
'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/hermes-engine/destroot/Library/Frameworks/iphoneos" ' +
|
|
'"$(PODS_ROOT)/hermes-engine/destroot/Library/Frameworks/iphonesimulator" ' +
|
|
'"$(PODS_ROOT)/hermes-engine/destroot/Library/Frameworks/macosx" ' +
|
|
'"$(PODS_ROOT)/hermes-engine/destroot/Library/Frameworks/catalyst"',
|
|
'OTHER_LDFLAGS' => '-framework "hermes"',
|
|
'HERMES_CLI_PATH' => "#{hermesc_path}/bin/hermesc"
|
|
}
|
|
|
|
spec.script_phases = [
|
|
{
|
|
:name => 'Build Hermes',
|
|
:script => <<-EOS
|
|
. ${PODS_ROOT}/../.xcode.env
|
|
export CMAKE_BINARY=${CMAKE_BINARY:-#{%x(command -v cmake | tr -d '\n')}}
|
|
. ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermes-xcode.sh #{version} #{hermesc_path}/ImportHermesc.cmake
|
|
EOS
|
|
},
|
|
{
|
|
:name => 'Copy Hermes Framework',
|
|
:script => ". ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/copy-hermes-xcode.sh"
|
|
}
|
|
]
|
|
end
|
|
end
|