From 191fc0f7cca8a3ab924a352876a35078c8d3d11f Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 4 Mar 2022 07:27:13 -0800 Subject: [PATCH] Setup a Gradle build inside `ReactAndroid/hermes-engine` to download Hermes sources Summary: This Diff sets up a small Gradle build inside `ReactAndroid/hermes-engine` The idea is to kickoff a small project where we can download Hermes sources and start a compilation of the Hermes sources from there. Specifically the used paths are: - `/sdk/hermes` for the unzipping - `/sdk/download/hermes.tar.gz` for the tarball location - `/sdk/hermes/.hermesversion` for the hermes version. allow-large-files Changelog: [Internal] [Changed] - Setup a Gradle build inside `hermes-engine` to download Hermes sources Reviewed By: hramos Differential Revision: D34210236 fbshipit-source-id: 97034f5608dfb3fcd1d74e9851944f7a60e52ea1 --- .gitignore | 5 +-- ReactAndroid/hermes-engine/build.gradle | 44 +++++++++++++++++++++++++ settings.gradle.kts | 3 +- 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 ReactAndroid/hermes-engine/build.gradle diff --git a/.gitignore b/.gitignore index ff797f94a40..b0ac5d1d575 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ project.xcworkspace # Gradle /build/ /packages/react-native-gradle-plugin/build/ +/packages/rn-tester/build /packages/rn-tester/android/app/.cxx/ /packages/rn-tester/android/app/build/ /packages/rn-tester/android/app/gradle/ @@ -34,6 +35,7 @@ project.xcworkspace /ReactAndroid/gradle/ /ReactAndroid/gradlew /ReactAndroid/gradlew.bat +/ReactAndroid/hermes-engine/build/ /template/android/app/build/ /template/android/build/ @@ -72,6 +74,7 @@ package-lock.json # Hermes /sdks/hermes +/sdks/download # Test generated files /ReactAndroid/src/androidTest/assets/AndroidTestBundle.js @@ -85,8 +88,6 @@ package-lock.json # ReactCommon subdir shouldn't have Xcode project /ReactCommon/**/*.xcodeproj -/packages/rn-tester/build -/packages/rn-tester/android/app/build/* # Libs that shouldn't have Xcode project /Libraries/FBLazyVector/**/*.xcodeproj diff --git a/ReactAndroid/hermes-engine/build.gradle b/ReactAndroid/hermes-engine/build.gradle new file mode 100644 index 00000000000..83350f904cd --- /dev/null +++ b/ReactAndroid/hermes-engine/build.gradle @@ -0,0 +1,44 @@ +/* + * 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. + */ + +plugins { + id("de.undercouch.download") +} + +def customDownloadDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR") +def downloadsDir = customDownloadDir ? new File(customDownloadDir) : rootProject.file("sdks/download") +def hermesDir = rootProject.file("sdks/hermes") +def hermesVersion = "main" +def hermesVersionFile = rootProject.file("sdks/.hermesversion") +if (hermesVersionFile.exists()) { + hermesVersion = hermesVersionFile.text +} + +task downloadHermes(type: Download) { + src("https://github.com/facebook/hermes/tarball/${hermesVersion}") + onlyIfNewer(true) + overwrite(false) + dest(new File(downloadsDir, "hermes.tar.gz")) +} + +// This task is called by the CI to download all the extrenal source code tarballs. +task downloadNdkBuildDependencies() { + dependsOn(downloadHermes) +} + +task unzipHermes(dependsOn: downloadHermes, type: Copy) { + from(tarTree(downloadHermes.dest)) { + eachFile { file -> + // We flatten the unzip as the tarball contains a `facebook-hermes-` + // folder at the top level. + if (file.relativePath.segments.size() > 1) { + file.relativePath = new org.gradle.api.file.RelativePath(!file.isDirectory(), file.relativePath.segments.drop(1)) + } + } + } + into(hermesDir) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 6d1179da696..2e7297ebc14 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,6 +15,7 @@ pluginManagement { include( ":ReactAndroid", + ":ReactAndroid:hermes-engine", ":packages:react-native-codegen:android", ":packages:rn-tester:android:app" ) @@ -32,4 +33,4 @@ plugins { // you can configure your custom Gradle Enterprise instance if (File("./gradle/gradle-enterprise.gradle.kts").exists()) { apply(from = "./gradle/gradle-enterprise.gradle.kts") -} \ No newline at end of file +}