From 57c1b8b904ca3606e59d337cbcb2b595ac0f5acd Mon Sep 17 00:00:00 2001 From: LoveSy Date: Wed, 23 Mar 2022 19:16:19 +0800 Subject: [PATCH] Use ccache for all native modules (#1787) --- build.gradle.kts | 16 ++++++++++++++++ daemon/src/main/jni/CMakeLists.txt | 2 +- external/CMakeLists.txt | 7 ------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c5507d53..73f6ad37 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,6 +22,8 @@ import com.android.build.api.variant.ApplicationAndroidComponentsExtension import com.android.build.gradle.BaseExtension import org.eclipse.jgit.api.Git import org.eclipse.jgit.internal.storage.file.FileRepository +import java.nio.file.Paths +import org.gradle.internal.os.OperatingSystem plugins { id("com.android.application") apply false @@ -63,6 +65,16 @@ tasks.register("Delete", Delete::class) { delete(rootProject.buildDir) } +fun findInPath(executable: String): String? { + val pathEnv = System.getenv("PATH") + return pathEnv.split(File.pathSeparator).map { folder -> + Paths.get("${folder}${File.separator}${executable}${if (OperatingSystem.current().isWindows) ".exe" else ""}") + .toFile() + }.firstOrNull { path -> + path.exists() + }?.absolutePath +} + fun Project.configureBaseExtension() { extensions.findByType(BaseExtension::class)?.run { compileSdkVersion(androidCompileSdkVersion) @@ -102,6 +114,10 @@ fun Project.configureBaseExtension() { "-DVERSION_CODE=$verCode", "-DVERSION_NAME=$verName", ) + findInPath("ccache")?.let { + println("Using ccache $it") + arguments += "-DANDROID_CCACHE=$it" + } } } } diff --git a/daemon/src/main/jni/CMakeLists.txt b/daemon/src/main/jni/CMakeLists.txt index a40bf5ec..046ef8d3 100644 --- a/daemon/src/main/jni/CMakeLists.txt +++ b/daemon/src/main/jni/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.4.1) project(daemon) +cmake_minimum_required(VERSION 3.4.1) add_subdirectory(${EXTERNAL_ROOT} external) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index c19b328d..70e5b668 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,12 +1,5 @@ project(external) -find_program(CCACHE ccache) - -if (CCACHE) - set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE}) - set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE}) -endif () - macro(SET_OPTION option value) set(${option} ${value} CACHE INTERNAL "" FORCE) endmacro()