diff --git a/scripts/hermes/hermes-utils.js b/scripts/hermes/hermes-utils.js index 1dc2bba067d6c8..d9db7a4aba61ce 100644 --- a/scripts/hermes/hermes-utils.js +++ b/scripts/hermes/hermes-utils.js @@ -15,7 +15,6 @@ const {execSync} = require('child_process'); const SDKS_DIR = path.normalize(path.join(__dirname, '..', '..', 'sdks')); const HERMES_DIR = path.join(SDKS_DIR, 'hermes'); -const DEFAULT_HERMES_TAG = 'main'; const HERMES_TAG_FILE_PATH = path.join(SDKS_DIR, '.hermesversion'); const HERMES_TARBALL_BASE_URL = 'https://github.com/facebook/hermes/tarball/'; const HERMES_TARBALL_DOWNLOAD_DIR = path.join(SDKS_DIR, 'download'); @@ -162,65 +161,8 @@ function isTestingAgainstLocalHermesTarball() { return 'HERMES_ENGINE_TARBALL_PATH' in process.env; } -function isOnAReactNativeReleaseBranch() { - try { - let currentBranch = execSync('git rev-parse --abbrev-ref HEAD') - .toString() - .trim(); - let currentRemote = execSync('git config --get remote.origin.url') - .toString() - .trim(); - return ( - currentBranch.endsWith('-stable') && - currentRemote.endsWith('facebook/react-native.git') - ); - } catch (error) { - // If not inside a git repo, we're going to fail here and return. - return false; - } -} - -function isOnAReactNativeReleaseTag() { - try { - // If on a named tag, this method will return the tag name. - // If not, it will throw as the return code is not 0. - execSync('git describe --exact-match HEAD', {stdio: 'ignore'}); - } catch (error) { - return false; - } - let currentRemote = execSync('git config --get remote.origin.url') - .toString() - .trim(); - return currentRemote.endsWith('facebook/react-native.git'); -} - -function isRequestingLatestCommitFromHermesMainBranch() { - const hermesTag = readHermesTag(); - return hermesTag === DEFAULT_HERMES_TAG; -} - -function isPRAgainstStable(pullRequest) { - if (pullRequest == null) { - return false; - } - - const prComponents = pullRequest.split('/'); - const prNumber = prComponents[prComponents.length - 1]; - const apiURL = `https://api.github.com/repos/facebook/react-native/pulls/${prNumber}`; - const prJson = JSON.parse(execSync(`curl ${apiURL}`).toString()); - const baseBranch = prJson.base.label; - - return baseBranch.endsWith('-stable'); -} - -function shouldBuildHermesFromSource(pullRequest) { - return ( - !isTestingAgainstLocalHermesTarball() && - (isOnAReactNativeReleaseBranch() || - isOnAReactNativeReleaseTag() || - isPRAgainstStable(pullRequest) || - isRequestingLatestCommitFromHermesMainBranch()) - ); +function shouldBuildHermesFromSource(isInCI) { + return !isTestingAgainstLocalHermesTarball() && isInCI; } function shouldUsePrebuiltHermesC(os) { diff --git a/scripts/hermes/prepare-hermes-for-build.js b/scripts/hermes/prepare-hermes-for-build.js index 42b33bad58a0dc..140d9f3a4380d0 100644 --- a/scripts/hermes/prepare-hermes-for-build.js +++ b/scripts/hermes/prepare-hermes-for-build.js @@ -23,12 +23,11 @@ const { shouldBuildHermesFromSource, } = require('./hermes-utils'); -async function main(pullRequest) { - if (!shouldBuildHermesFromSource(pullRequest)) { +async function main(isInCI) { + if (!shouldBuildHermesFromSource(isInCI)) { copyPodSpec(); return; } - downloadHermesTarball(); expandHermesTarball(); copyPodSpec(); @@ -40,8 +39,8 @@ async function main(pullRequest) { } } -const pullRequest = process.argv.length > 2 ? process.argv[2] : null; -console.log(`Pull request detected: ${pullRequest}`); -main(pullRequest).then(() => { +const isInCI = process.env.CI === 'true'; + +main(isInCI).then(() => { process.exit(0); }); diff --git a/sdks/hermes-engine/hermes-engine.podspec b/sdks/hermes-engine/hermes-engine.podspec index 8d331e096ad2e0..430ab9e7639a6c 100644 --- a/sdks/hermes-engine/hermes-engine.podspec +++ b/sdks/hermes-engine/hermes-engine.podspec @@ -13,6 +13,8 @@ import_hermesc_file=File.join(__dir__, "..", "hermesc", "osx-bin", "ImportHermes package_file = File.join(__dir__, "..", "..", "package.json") package = JSON.parse(File.read(package_file)) version = package['version'] +isInCI = ENV['CI'] == true +hermestag_file = File.join(__dir__, "..", ".hermesversion") # We need to check the current git branch/remote to verify if # we're on a React Native release branch to actually build Hermes. @@ -29,9 +31,8 @@ elsif version == '1000.0.0' Pod::UI.puts '[Hermes] Hermes needs to be compiled, installing hermes-engine may take a while...'.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 currentremote.strip.end_with?("facebook/react-native.git") and currentbranch.strip.end_with?("-stable") +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 = File.join(__dir__, "..", ".hermesversion") hermestag = File.read(hermestag_file).strip source[:git] = git source[:tag] = hermestag