Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume Tarball from Maven #35034

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scripts/__tests__/hermes-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ function populateMockFilesystem() {
path.join(SDKS_DIR, 'hermes-engine', 'hermes-engine.podspec'),
'Dummy file',
);
fs.writeFileSync(
path.join(SDKS_DIR, 'hermes-engine', 'hermes-utils.rb'),
'Dummy file',
);
}

describe('hermes-utils', () => {
Expand Down Expand Up @@ -279,6 +283,23 @@ describe('hermes-utils', () => {
),
);
});
it('should copy hermes-utils.rb to Hermes source directory', () => {
copyPodSpec();
expect(
fs.readFileSync(path.join(SDKS_DIR, 'hermes', 'hermes-utils.rb'), {
encoding: 'utf8',
flag: 'r',
}),
).toEqual(
fs.readFileSync(
path.join(SDKS_DIR, 'hermes-engine', 'hermes-utils.rb'),
{
encoding: 'utf8',
flag: 'r',
},
),
);
});
});
describe('shouldUsePrebuiltHermesC', () => {
it('returns false if path to osx hermesc does not exist', () => {
Expand Down
10 changes: 8 additions & 2 deletions scripts/hermes/hermes-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,15 @@ function copyPodSpec() {
if (!fs.existsSync(HERMES_DIR)) {
fs.mkdirSync(HERMES_DIR, {recursive: true});
}
const podspec = 'hermes-engine.podspec';
fs.copyFileSync(
path.join(SDKS_DIR, 'hermes-engine', 'hermes-engine.podspec'),
path.join(HERMES_DIR, 'hermes-engine.podspec'),
path.join(SDKS_DIR, 'hermes-engine', podspec),
path.join(HERMES_DIR, podspec),
);
const utils = 'hermes-utils.rb';
fs.copyFileSync(
path.join(SDKS_DIR, 'hermes-engine', utils),
path.join(HERMES_DIR, utils),
);
}

Expand Down
11 changes: 10 additions & 1 deletion sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# LICENSE file in the root directory of this source tree.

require "json"
require_relative "./hermes-utils.rb"

react_native_path = File.join(__dir__, "..", "..")

Expand All @@ -24,13 +25,21 @@ import_hermesc_file=File.join(react_native_path, "sdks", "hermesc", "osx-bin", "
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 version.include? '1000.0.0' || version.start_with?('0.0.0-')
elsif isInMain
Pod::UI.puts '[Hermes] Installing hermes-engine may take a while, building Hermes 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...'.yellow if Object.const_defined?("Pod::UI")
hermestag = File.read(hermestag_file).strip
Expand Down
27 changes: 27 additions & 0 deletions sdks/hermes-engine/hermes-utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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 'net/http'
require 'rexml/document'

# This function downloads the nightly prebuilt version of Hermes based on the passed version
# and save it in the node_module/react_native/sdks/downloads folder
# It then returns the path to the hermes tarball
#
# Parameters
# - react_native_path: the path to the React Native folder in node modules. It is used as root path to store the Hermes tarball
# - version: the version of React Native that requires the Hermes tarball
# Returns: the path to the downloaded Hermes tarball
def download_nightly_hermes(react_native_path, version)
# TODO: convert hermes-ios to hermes-ios-debug
params = "r=snapshots\&g=com.facebook.react\&a=react-native-artifacts\&c=hermes-ios-debug\&e=tar.gz\&v=#{version}-SNAPSHOT"
tarball_url = "http://oss.sonatype.org/service/local/artifact/maven/redirect\?#{params}"

destination_folder = "#{react_native_path}/sdks/downloads"
destination_path = "#{destination_folder}/hermes-ios.tar.gz"

`mkdir -p "#{destination_folder}" && curl "#{tarball_url}" -Lo "#{destination_path}"`
return destination_path
end