From 43cffb96dbb4e723bccd71d373aeb7ea9555bab8 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 17 Feb 2025 03:35:43 -0800 Subject: [PATCH] Gradle Configuration Cache - Round 3 (#49439) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49439 This is the next part of a series of diff needed to enable G. Configuration Cache: https://docs.gradle.org/current/userguide/configuration_cache.html as it will make our CI faster (and will be the default in the future Gradle version). Here I'm removing the `onlyIf` lambdas to make some tasks CC friendly. The problem is that some `onlyIf` lambdas can't easily be serialized. Here I'm cleaning up the problematic one to move the condition checks at execution time Changelog: [Internal] [Changed] - Reviewed By: cipolleschi Differential Revision: D69664732 fbshipit-source-id: a457b2fae8114568ec4e04d772c9944022b1e1a5 --- .../facebook/react/tasks/internal/BuildCodegenCLITask.kt | 6 ++++++ packages/react-native/ReactAndroid/build.gradle.kts | 5 +---- .../ReactAndroid/hermes-engine/build.gradle.kts | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITask.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITask.kt index ad2d51ed03e..74eba652707 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITask.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITask.kt @@ -28,6 +28,8 @@ abstract class BuildCodegenCLITask : Exec() { @get:Internal abstract val bashWindowsHome: Property + @get:Internal abstract val rootProjectName: Property + @get:InputFiles abstract val inputFiles: Property @get:OutputFiles abstract val outputFiles: Property @@ -35,6 +37,10 @@ abstract class BuildCodegenCLITask : Exec() { @get:OutputFile abstract val logFile: RegularFileProperty override fun exec() { + // For build from source scenario, we don't need to build the codegen at all. + if (rootProjectName.get() == "react-native-build-from-source") { + return + } val logFileConcrete = logFile.get().asFile.apply { parentFile.mkdirs() diff --git a/packages/react-native/ReactAndroid/build.gradle.kts b/packages/react-native/ReactAndroid/build.gradle.kts index 80c7fede9b5..2f212b63580 100644 --- a/packages/react-native/ReactAndroid/build.gradle.kts +++ b/packages/react-native/ReactAndroid/build.gradle.kts @@ -426,10 +426,7 @@ val buildCodegenCLI by include("lib/**/*.js") include("lib/**/*.js.flow") }) - onlyIf { - // For build from source scenario, we don't need to build the codegen at all. - rootProject.name != "react-native-build-from-source" - } + rootProjectName.set(rootProject.name) } /** diff --git a/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts b/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts index 43b4268edc9..9fa746dff89 100644 --- a/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts +++ b/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts @@ -124,8 +124,8 @@ val unzipHermes by // the two tasks mentioned before, so we install CMake manually to break the circular dependency. val installCMake by - tasks.registering(Exec::class) { - onlyIf { !File(cmakePath).exists() } + tasks.registering(CustomExecTask::class) { + onlyIfProvidedPathDoesNotExists.set(cmakePath) commandLine( windowsAwareCommandLine(getSDKManagerPath(), "--install", "cmake;${cmakeVersion}")) }