Skip to content

Commit

Permalink
hermes-engine: downloading prebuilt artifact takes precedence over bu…
Browse files Browse the repository at this point in the history
…ilding from source
  • Loading branch information
Dmitry Rykun committed Dec 8, 2022
1 parent 95c1358 commit 3e7cf27
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
24 changes: 14 additions & 10 deletions sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ build_type = ENV['PRODUCTION'] == "1" ? :release : :debug
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')
isOnMain = version.include?('1000.0.0')
isNightly = version.start_with?('0.0.0-')
isOnStable = version.include?('-rc.')

if ENV.has_key?('HERMES_ENGINE_TARBALL_PATH')
if !File.exist?(ENV['HERMES_ENGINE_TARBALL_PATH'])
Expand All @@ -34,7 +31,7 @@ end
if ENV.has_key?('HERMES_ENGINE_TARBALL_PATH')
Pod::UI.puts "[Hermes] Using pre-built Hermes binaries from local path: #{ENV['HERMES_ENGINE_TARBALL_PATH']}".yellow if Object.const_defined?("Pod::UI")
source[:http] = "file://#{ENV['HERMES_ENGINE_TARBALL_PATH']}"
elsif isInMain
elsif isOnMain
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
Expand All @@ -43,15 +40,22 @@ elsif isNightly
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
elsif hermes_artifact_exists(version, build_type)
hermesArtifactURL = hermes_artifact_url(version, build_type)
Pod::UI.puts "[Hermes] Downloading artifact from #{hermesArtifactURL}".yellow if Object.const_defined?("Pod::UI")
source[:http] = hermesArtifactURL
elsif isOnStable
# sdks/.hermesversion
hermestag_file = File.join(react_native_path, "sdks", ".hermesversion")
if !File.exists?(hermestag_file)
abort "[Hermes] .hermesversion file missing on stable branch."
end
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"
abort "[Hermes] Unable to determine source for hermes-engine."
end

Pod::Spec.new do |spec|
Expand Down
22 changes: 22 additions & 0 deletions sdks/hermes-engine/hermes-utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,25 @@ def download_nightly_hermes(react_native_path, version)
`mkdir -p "#{destination_folder}" && curl "#{tarball_url}" -Lo "#{destination_path}"`
return destination_path
end

# This function builds Hermes artifact URL.
# As of now it should point to the Maven repo.
#
# Parameters
# - version: the version of React Native
# - build_type: debug or release
def hermes_artifact_url(version, build_type)
# 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
return "https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/#{version}/react-native-artifacts-#{version}-hermes-ios-#{build_type}.tar.gz"
end

# This function checks that Hermes artifact exists.
# As of now it should check it on the Maven repo.
#
# Parameters
# - version: the version of React Native
# - build_type: debug or release
def hermes_artifact_exists(version, build_type)
return (`curl -o /dev/null --silent -Iw '%{http_code}' #{hermes_artifact_url(version, build_type)}` == "200")
end

0 comments on commit 3e7cf27

Please sign in to comment.