From 63ca55bdccd622f071e16c21e604743ce3d7d98b Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 26 Sep 2023 06:26:55 -0700 Subject: [PATCH] Unblock build-from-source on nightlies (#39634) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39634 Running build from source as suggested here: https://reactnative.dev/contributing/how-to-build-from-source is currently broken for nightly versions (and for 0.73). This fixes it by: - Fixing the import of the Gradle Version Catalog - Actually adding the Gradle version catalog to the NPM package - Fixing how the build Codegen CLI task is invoked for build-from-source - Updating the search directories for codegenDir/reactNativeDir from build-from-source Changelog: [Internal] [Fixed] - Unblock build-from-source on nightlies Reviewed By: cipolleschi Differential Revision: D49562595 fbshipit-source-id: 9594b7d947569d41c461a7e8287d3ae68fb87b98 --- .../react/internal/PrivateReactExtension.kt | 5 +++-- packages/react-native/ReactAndroid/build.gradle | 14 ++++++++++++++ packages/react-native/package.json | 1 + packages/react-native/settings.gradle.kts | 6 +----- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt index 056111f7f5..31795b3e5e 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt @@ -30,7 +30,7 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) { .directoryProperty() .convention( // This is the default for the project root if the users hasn't specified anything. - // If the project is called "react-native-github" + // If the project is called "react-native-github" or "react-native-build-from-source" // - We're inside the Github Repo -> root is defined by RN Tester (so no default // needed) // - We're inside an includedBuild as we're performing a build from source @@ -39,7 +39,8 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) { // - We're inside a user project, so inside the ./android folder. Default should be // ../ // User can always override this default by setting a `root =` inside the template. - if (project.rootProject.name == "react-native-github") { + if (project.rootProject.name == "react-native-github" || + project.rootProject.name == "react-native-build-from-source") { project.rootProject.layout.projectDirectory.dir("../../") } else { project.rootProject.layout.projectDirectory.dir("../") diff --git a/packages/react-native/ReactAndroid/build.gradle b/packages/react-native/ReactAndroid/build.gradle index b4a8f8aa60..cce54c2a0e 100644 --- a/packages/react-native/ReactAndroid/build.gradle +++ b/packages/react-native/ReactAndroid/build.gradle @@ -392,6 +392,10 @@ task prepareKotlinBuildScriptModel { final def buildCodegenCLITask = tasks.register('buildCodegenCLI', BuildCodegenCLITask) { it.codegenDir.set(file("$rootDir/node_modules/@react-native/codegen")) it.bashWindowsHome.set(project.findProperty("react.internal.windowsBashPath")) + it.onlyIf { + // For build from source scenario, we don't need to build the codegen at all. + rootProject.name != "react-native-build-from-source" + } } /** @@ -790,6 +794,16 @@ react { jsRootDir = file("../Libraries") } +// For build from source, we need to override the privateReact extension. +// This is neeeded as the build-from-source won't have a com.android.application +// module to apply the plugin to, so it's codegenDir and reactNativeDir won't be evaluated. +if (rootProject.name == "react-native-build-from-source") { + privateReact { + codegenDir = file("$rootDir/../@react-native/codegen") + reactNativeDir = file("$rootDir") + } +} + kotlin { jvmToolchain(17) } diff --git a/packages/react-native/package.json b/packages/react-native/package.json index 036eee0360..591bcf5b26 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -35,6 +35,7 @@ "cli.js", "flow", "gradle.properties", + "gradle/libs.versions.toml", "index.js", "interface.js", "jest-preset.js", diff --git a/packages/react-native/settings.gradle.kts b/packages/react-native/settings.gradle.kts index 49736a7519..840aa5506e 100644 --- a/packages/react-native/settings.gradle.kts +++ b/packages/react-native/settings.gradle.kts @@ -19,11 +19,7 @@ pluginManagement { } } -dependencyResolutionManagement { - versionCatalogs { create("libs") { from(files("gradle/libs.versions.toml")) } } -} - -rootProject.name = "react-native-github" +rootProject.name = "react-native-build-from-source" include(":packages:react-native:ReactAndroid")