From d96cd6d285508aee689fe6f5a2b33a4d16a1a6fb Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 4 Mar 2022 07:27:13 -0800 Subject: [PATCH] Create a Gradle task to setup the Hermes Ninja build Summary: As the title says, we need to invoke: ``` ./utils/build/configure.py ./ninja_build cmake --build ./ninja_build --target hermesc ``` In order to build the Hermes compiler, otherwise the CMake build will fail with a missing Cmake file. Changelog: [Internal] [Changed] - Create a Gradle task to setup the Hermes Ninja build Reviewed By: hramos Differential Revision: D34213468 fbshipit-source-id: 83f70bdb068f99ce17a44207b4282fde2d7420ca --- ReactAndroid/hermes-engine/build.gradle | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ReactAndroid/hermes-engine/build.gradle b/ReactAndroid/hermes-engine/build.gradle index 83350f904cd..582c9811d7e 100644 --- a/ReactAndroid/hermes-engine/build.gradle +++ b/ReactAndroid/hermes-engine/build.gradle @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +import org.apache.tools.ant.taskdefs.condition.Os + plugins { id("de.undercouch.download") } @@ -17,6 +19,7 @@ def hermesVersionFile = rootProject.file("sdks/.hermesversion") if (hermesVersionFile.exists()) { hermesVersion = hermesVersionFile.text } +def ndkBuildJobs = Runtime.runtime.availableProcessors().toString() task downloadHermes(type: Download) { src("https://github.com/facebook/hermes/tarball/${hermesVersion}") @@ -42,3 +45,23 @@ task unzipHermes(dependsOn: downloadHermes, type: Copy) { } into(hermesDir) } + + +task configureNinjaForHermes(dependsOn: unzipHermes, type: org.gradle.api.tasks.Exec) { + workingDir(hermesDir) + commandLine(windowsAwareCommandLine("python3", "utils/build/configure.py", "./ninja_build")) +} + +task buildNinjaForHermes(dependsOn: configureNinjaForHermes, type: org.gradle.api.tasks.Exec) { + workingDir(hermesDir) + commandLine(windowsAwareCommandLine("cmake", "--build", "./ninja_build", "--target", "hermesc", "-j", ndkBuildJobs)) +} + +static def windowsAwareCommandLine(String... commands) { + def newCommands = [] + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + newCommands = ['cmd', '/c'] + } + newCommands.addAll(commands) + return newCommands +}