From 90e7f510dcd45a3c46a16e7f3eb0cc9ec339e642 Mon Sep 17 00:00:00 2001 From: Vincenzo Vitale Date: Mon, 12 Sep 2022 12:33:07 -0700 Subject: [PATCH] Test the Android Template with the JSC engine (#34664) Summary: https://www.internalfb.com/T131530362 We are testing the New App template in CircleCI. For Android we test the combination of Debug/Release and Old/New Architecture, and always use the Hermes engine. We don't test the JSC engines (in iOS this is already happening). We're not automatically testing that we can create a new project with JSC, forcing release managers to do it manually. ## Changelog [Android] [Added] - Automatic testing of the new project template with the JSC engine. Pull Request resolved: https://github.com/facebook/react-native/pull/34664 Test Plan: - Open the circle-ci dashboard - Verify there are now 8 jobs adeed to the pipeline: ``` test_android_template-Debug-Hermes-false test_android_template-Debug-Hermes-true test_android_template-Debug-JSC-false test_android_template-Debug-JSC-true test_android_template-Release-Hermes-false test_android_template-Release-Hermes-true test_android_template-Release-JSC-false test_android_template-Release-JSC-true ``` - Verify they are all passing. Reviewed By: cortinico Differential Revision: D39426388 Pulled By: vincenzovitale fbshipit-source-id: e5d606b1cc3ace53f8dab0f7d6d7d06ab11a2b46 --- .circleci/config.yml | 16 +++++++++++- scripts/set-rn-engine.js | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 scripts/set-rn-engine.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 0b0653894cc..ad348c436dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -674,6 +674,9 @@ jobs: newarchitecture: type: boolean default: false + jsengine: + type: string + default: "Hermes" environment: - PROJECT_NAME: "AndroidTemplateProject" steps: @@ -681,6 +684,16 @@ jobs: - run_yarn - attach_workspace: at: . + - when: + condition: + equal: ["JSC", << parameters.jsengine >>] + steps: + - run: + name: Set enableHermes in buld.gradle to false + command: | + node ./scripts/set-rn-engine.js -e jsc + echo "Hermes disabled." + grep enableHermes: template/android/app/build.gradle - run: name: Create Android template project @@ -692,7 +705,7 @@ jobs: yarn - run: - name: Build the template application for << parameters.flavor >> with New Architecture set << parameters.newarchitecture >> + name: Build the template application for << parameters.flavor >> with New Architecture set to << parameters.newarchitecture >>, and using the << parameters.jsengine>> JS engine. command: cd /tmp/$PROJECT_NAME/android/ && ./gradlew assemble<< parameters.flavor >> -PnewArchEnabled=<< parameters.newarchitecture >> # ------------------------- @@ -1376,6 +1389,7 @@ workflows: matrix: parameters: newarchitecture: [true, false] + jsengine: ["Hermes", "JSC"] flavor: ["Debug", "Release"] - test_buck - test_ios_template: diff --git a/scripts/set-rn-engine.js b/scripts/set-rn-engine.js new file mode 100755 index 00000000000..52afa5b749d --- /dev/null +++ b/scripts/set-rn-engine.js @@ -0,0 +1,53 @@ +/** + * 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'; + +/** + * This script updates the engine used by React Native + */ +const {echo, exec, exit, sed} = require('shelljs'); +const yargs = require('yargs'); + +let argv = yargs.option('e', { + alias: 'engine', + describe: 'Choose an engine', + type: 'string', + choices: ['hermes', 'jsc'], +}).argv; + +const engine = argv.engine; + +if (!engine) { + echo('You must specify an engine using -e'); + exit(1); +} + +// Change the template build.gradle +sed( + '-i', + /enableHermes:.*/, + engine === 'jsc' ? 'enableHermes: false' : 'enableHermes: true', + 'template/android/app/build.gradle', +); + +// Validate the hermes flag has been changed properly +const hermes = + exec( + 'grep enableHermes: template/android/app/build.gradle | awk \'{split($0,a,"[:,]"); print a[2]}\'', + {silent: true}, + ).stdout.trim() === 'true'; + +if ((engine === 'jsc' && hermes) || (engine === 'hermes' && !hermes)) { + echo('Failed to update the engine in template/android/app/build.gradle'); + echo('Fix the issue and try again'); + exit(1); +} + +exit(0);