-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
download hermes-engine when the configuration change (#37850)
Summary: Currently, we ask users to reinstall the pods using the `PRODUCTION` flag when they want to either profile their app or prepare a release. This way of working with the Release mode is not standard. One of the reason why we introduced it was to provide a different binary for Hermes and reinstalling the pods was the quickest way. With this change, we are deferring the decision on when Hermes should be installed for apps to the moment where the app is actually build by the system. These changes are not applied to Nightlies, when a specific tarball is passed to the cocoapods using the `HERMES_ENGINE_TARBALL_PATH` env var, and when hermes is built from source as in these scenarios we are usually not interested in building for Release. The system is also smart enough not to redownload the tarball if the configuration does not change. It assumes that the default configuration when the pods are installed for the first time is Debug. ## Changelog: [IOS] [CHANGED] - Download the right `hermes-engine` configuration at build time. Pull Request resolved: #37850 Test Plan: - CircleCI green for the Release template jobs - Tested locally modifying the `hermes-utils` to force specific versions. - Tested locally with RNTestProject Reviewed By: dmytrorykun Differential Revision: D46687390 Pulled By: cipolleschi fbshipit-source-id: 375406e0ab351a5d1f5d5146e724f5ed0cd77949
- Loading branch information
1 parent
b3cc19c
commit 332be0f
Showing
7 changed files
with
212 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/react-native/sdks/hermes-engine/utils/replace_hermes_version.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const yargs = require('yargs'); | ||
const fs = require('fs'); | ||
const {execSync} = require('child_process'); | ||
|
||
const LAST_BUILD_FILENAME = '.last_build_configuration'; | ||
|
||
function validateBuildConfiguration(configuration) { | ||
if (!['Debug', 'Release'].includes(configuration)) { | ||
throw new Error(`Invalid configuration ${configuration}`); | ||
} | ||
} | ||
|
||
function validateVersion(version) { | ||
if (version == null || version === '') { | ||
throw new Error('Version cannot be empty'); | ||
} | ||
} | ||
|
||
function shouldReplaceHermesConfiguration(configuration) { | ||
const fileExists = fs.existsSync(LAST_BUILD_FILENAME); | ||
|
||
if (fileExists) { | ||
console.log(`Found ${LAST_BUILD_FILENAME} file`); | ||
const oldConfiguration = fs.readFileSync(LAST_BUILD_FILENAME).toString(); | ||
if (oldConfiguration === configuration) { | ||
console.log('No need to download a new build of Hermes!'); | ||
return false; | ||
} | ||
} | ||
|
||
// Assumption: if there is no stored last build, we assume that it was build for debug. | ||
if (!fs.existsSync && configuration === 'Debug') { | ||
console.log( | ||
'File does not exists, but Debug configuration. No need to download a new build of Hermes!', | ||
); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
function replaceHermesConfiguration(configuration, version, reactNativePath) { | ||
const tarballURLPath = `${reactNativePath}/sdks/downloads/hermes-ios-${version}-${configuration}.tar.gz`; | ||
|
||
const finalLocation = 'hermes-engine'; | ||
console.log('Preparing the final location'); | ||
fs.rmSync(finalLocation, {force: true, recursive: true}); | ||
fs.mkdirSync(finalLocation, {recursive: true}); | ||
|
||
console.log('Extracting the tarball'); | ||
execSync(`tar -xf ${tarballURLPath} -C ${finalLocation}`); | ||
} | ||
|
||
function updateLastBuildConfiguration(configuration) { | ||
fs.writeFileSync(LAST_BUILD_FILENAME, configuration); | ||
} | ||
|
||
function main(configuration, version, reactNativePath) { | ||
validateBuildConfiguration(configuration); | ||
validateVersion(version); | ||
|
||
if (!shouldReplaceHermesConfiguration(configuration)) { | ||
return; | ||
} | ||
|
||
replaceHermesConfiguration(configuration, version, reactNativePath); | ||
updateLastBuildConfiguration(configuration); | ||
console.log('Done replacing hermes-engine'); | ||
} | ||
|
||
// This script is executed in the Pods folder, which is usually not synched to Github, so it should be ok | ||
const argv = yargs | ||
.option('c', { | ||
alias: 'configuration', | ||
description: | ||
'Configuration to use to download the right Hermes version. Allowed values are "Debug" and "Release".', | ||
}) | ||
.option('r', { | ||
alias: 'reactNativeVersion', | ||
description: | ||
'The Version of React Native associated with the Hermes tarball.', | ||
}) | ||
.option('p', { | ||
alias: 'reactNativePath', | ||
description: 'The path to the React Native root folder', | ||
}) | ||
.usage('Usage: $0 -c Debug -r <version> -p <path/to/react-native>').argv; | ||
|
||
const configuration = argv.configuration; | ||
const version = argv.reactNativeVersion; | ||
const reactNativePath = argv.reactNativePath; | ||
|
||
main(configuration, version, reactNativePath); |
Oops, something went wrong.