Skip to content

Commit

Permalink
fix(local-e2e-script): add logic to handle maven local for iOS and An…
Browse files Browse the repository at this point in the history
…droid accordingly (#35104)

Summary:
This PR is a follow up of #35075 and 1546666 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: 4b51207

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: #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
  • Loading branch information
kelset authored and facebook-github-bot committed Nov 2, 2022
1 parent 0fd282f commit c540ff7
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 35 deletions.
41 changes: 40 additions & 1 deletion scripts/release-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

'use strict';

const {exec, echo, exit, test, env} = require('shelljs');
const {exec, echo, exit, test, env, pushd, popd} = require('shelljs');
const {saveFiles} = require('./scm-utils');
const {createHermesPrebuiltArtifactsTarball} = require('./hermes/hermes-utils');

// TODO: we should probably remove this because of this? https://github.com/facebook/react-native/pull/34846
function saveFilesToRestore(tmpPublishingFolder) {
const filesToSaveAndRestore = [
'template/Gemfile',
Expand Down Expand Up @@ -94,8 +96,45 @@ function publishAndroidArtifactsToMaven(releaseVersion, isNightly) {
echo('Published artifacts to Maven Central');
}

function generateiOSArtifacts(
jsiFolder,
hermesCoreSourceFolder,
buildType,
releaseVersion,
targetFolder,
) {
pushd(`${hermesCoreSourceFolder}`);

//Need to generate hermesc
exec(
`${hermesCoreSourceFolder}/utils/build-hermesc-xcode.sh ${hermesCoreSourceFolder}/build_host_hermesc`,
);

//Generating iOS Artifacts
exec(
`JSI_PATH=${jsiFolder} BUILD_TYPE=${buildType} ${hermesCoreSourceFolder}/utils/build-mac-framework.sh`,
);

exec(
`JSI_PATH=${jsiFolder} BUILD_TYPE=${buildType} ${hermesCoreSourceFolder}/utils/build-ios-framework.sh`,
);

popd();

const tarballOutputPath = createHermesPrebuiltArtifactsTarball(
hermesCoreSourceFolder,
buildType,
releaseVersion,
targetFolder,
true, // this is excludeDebugSymbols, we keep it as the default
);

return tarballOutputPath;
}

module.exports = {
generateAndroidArtifacts,
generateiOSArtifacts,
publishAndroidArtifactsToMaven,
saveFilesToRestore,
};
1 change: 1 addition & 0 deletions scripts/test-e2e-local-clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if (isPackagerRunning() === 'running') {
// Android
console.info('\n** Cleaning Gradle build artifacts **\n');
exec('./gradlew cleanAll');
exec('rm -rf /tmp/maven-local');

// iOS
console.info('\n** Nuking the derived data folder **\n');
Expand Down
108 changes: 76 additions & 32 deletions scripts/test-e2e-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* and to make it more accessible for other devs to play around with.
*/

const {exec, exit, pushd, popd, pwd, cd} = require('shelljs');
const {exec, exit, pushd, popd, pwd, cd, cp} = require('shelljs');
const yargs = require('yargs');
const fs = require('fs');
const path = require('path');
Expand All @@ -31,8 +31,14 @@ const {
const {
generateAndroidArtifacts,
saveFilesToRestore,
generateiOSArtifacts,
} = require('./release-utils');

const {
downloadHermesSourceTarball,
expandHermesSourceTarball,
} = require('./hermes/hermes-utils');

const argv = yargs
.option('t', {
alias: 'target',
Expand Down Expand Up @@ -65,6 +71,12 @@ if (isPackagerRunning() === 'running') {
exec("lsof -i :8081 | grep LISTEN | /usr/bin/awk '{print $2}' | xargs kill");
}

const onReleaseBranch = exec('git rev-parse --abbrev-ref HEAD', {
silent: true,
})
.stdout.trim()
.endsWith('-stable');

if (argv.target === 'RNTester') {
// FIXME: make sure that the commands retains colors
// (--ansi) doesn't always work
Expand All @@ -76,10 +88,15 @@ if (argv.target === 'RNTester') {
argv.hermes ? 'Hermes' : 'JSC'
} version of RNTester iOS with the new Architecture enabled`,
);

// remember that for this to be successful
// you should have run bundle install once
// in your local setup - also: if I'm on release branch, I pick the
// hermes ref from the hermes ref file (see hermes-engine.podspec)
exec(
`cd packages/rn-tester && USE_HERMES=${
argv.hermes ? 1 : 0
} RCT_NEW_ARCH_ENABLED=1 bundle exec pod install --ansi`,
} CI=${onReleaseBranch} RCT_NEW_ARCH_ENABLED=1 bundle exec pod install --ansi`,
);

// if everything succeeded so far, we can launch Metro and the app
Expand Down Expand Up @@ -113,12 +130,14 @@ if (argv.target === 'RNTester') {
// if everything succeeded so far, we can launch Metro and the app
// start the Metro server in a separate window
launchPackagerInSeparateWindow();
// just to make sure that the Android up won't have troubles finding the Metro server
exec('adb reverse tcp:8081 tcp:8081');

// launch the app
exec(
'adb shell am start -n com.facebook.react.uiapp/com.facebook.react.uiapp.RNTesterActivity',
);

// just to make sure that the Android up won't have troubles finding the Metro server
exec('adb reverse tcp:8081 tcp:8081');
}
} else {
console.info("We're going to test a fresh new RN project");
Expand Down Expand Up @@ -147,50 +166,75 @@ if (argv.target === 'RNTester') {
// this is needed to generate the Android artifacts correctly
exec(`node scripts/set-rn-version.js --to-version ${releaseVersion}`).code;

// Generate native files (Android only for now)
// Generate native files for Android
generateAndroidArtifacts(releaseVersion, tmpPublishingFolder);

// Setting up generating native iOS (will be done later)
const repoRoot = pwd();
const jsiFolder = `${repoRoot}/ReactCommon/jsi`;
const hermesCoreSourceFolder = `${repoRoot}/sdks/hermes`;

if (!fs.existsSync(hermesCoreSourceFolder)) {
console.info('The Hermes source folder is missing. Downloading...');
downloadHermesSourceTarball();
expandHermesSourceTarball();
}

// need to move the scripts inside the local hermes cloned folder
// cp sdks/hermes-engine/utils/*.sh <your_hermes_checkout>/utils/.
cp(
`${repoRoot}/sdks/hermes-engine/utils/*.sh`,
`${repoRoot}/sdks/hermes/utils/.`,
);

// for this scenario, we only need to create the debug build
// (env variable PRODUCTION defines that podspec side)
const buildType = 'Debug';

// the android ones get set into /private/tmp/maven-local
const localMavenPath = '/private/tmp/maven-local';

// Generate native files for iOS
const tarballOutputPath = generateiOSArtifacts(
jsiFolder,
hermesCoreSourceFolder,
buildType,
releaseVersion,
localMavenPath,
);

// create locally the node module
exec('npm pack');

const localNodeTGZPath = `${pwd()}/react-native-${releaseVersion}.tgz`;
const localNodeTGZPath = `${repoRoot}/react-native-${releaseVersion}.tgz`;
exec(`node scripts/set-rn-template-version.js "file:${localNodeTGZPath}"`);

const repoRoot = pwd();

pushd('/tmp/');
// need to avoid the pod install step because it will fail! (see above)
// need to avoid the pod install step - we'll do it later
exec(
`node ${repoRoot}/cli.js init RNTestProject --template ${repoRoot} --skip-install`,
);

cd('RNTestProject');
exec('yarn install');

// need to do this here so that Android will be properly setup either way
exec(
'echo "REACT_NATIVE_MAVEN_LOCAL_REPO=/private/tmp/maven-local" >> android/gradle.properties',
);

// doing the pod install here so that it's easier to play around RNTestProject
cd('ios');
exec('bundle install');
exec(
`HERMES_ENGINE_TARBALL_PATH=${tarballOutputPath} USE_HERMES=${
argv.hermes ? 1 : 0
} bundle exec pod install --ansi`,
);

cd('..');

if (argv.platform === 'iOS') {
// if we want iOS, we need to do pod install - but with a trick
cd('ios');
exec('bundle install');

// TODO: we should be able to also use HERMES_ENGINE_TARBALL_PATH
// if we can make RNTester step generate it already so that it gets reused

// need to discern if it's main branch or release branch
if (baseVersion === '1000.0.0') {
// main branch
exec(`USE_HERMES=${argv.hermes ? 1 : 0} bundle exec pod install --ansi`);
} else {
// TODO: to test this, I need to apply changes on top of a release branch
// a release branch
// copy over the .hermesversion file from react-native core into the RNTestProject
exec(`cp -f ${repoRoot}/sdks/.hermesversion .`);
exec(
`CI=true USE_HERMES=${
argv.hermes ? 1 : 0
} bundle exec pod install --ansi`,
);
}
cd('..');
exec('yarn ios');
} else {
// android
Expand Down
4 changes: 2 additions & 2 deletions sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ version = package['version']

# sdks/.hermesversion
hermestag_file = File.join(react_native_path, "sdks", ".hermesversion")
isInCI = ENV['CI'] == true
isInCI = ENV['CI'] === 'true'

source = {}
git = "https://github.com/facebook/hermes.git"
Expand All @@ -38,7 +38,7 @@ elsif isNightly
# 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")
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
Expand Down
Empty file modified sdks/hermes-engine/utils/build-hermes-xcode.sh
100644 → 100755
Empty file.
Empty file modified sdks/hermes-engine/utils/build-hermesc-xcode.sh
100644 → 100755
Empty file.
Empty file modified sdks/hermes-engine/utils/copy-hermes-xcode.sh
100644 → 100755
Empty file.

0 comments on commit c540ff7

Please sign in to comment.