From d5c0eaef1f7c3b705cc1cf3087bd83ad9098aa2f Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Thu, 13 Jan 2022 21:04:31 +0000 Subject: [PATCH] Makefile, toolchain-wrapper.c: disable ccache by default outside of Buildroot Until now, when BR2_CCACHE=y, ccache support was built into the toolchain wrapper, and used regardless of whether the toolchain is using during the Buildroot build itself, or later as part of the SDK. However, having ccache support forcefully enabled in the SDK can really be surprising, and is certainly unexpected for a cross-compilation toolchain. This can be particularly surprising as the ccache cache directory may be hardcoded in the ccache binary to point to a folder that does not make sense on the SDK user's machine. So what this commit does is create a BR2_USE_CCACHE variable, which when set to 1 tells the toolchain wrapper to use ccache. Not defining the variable, or specifying any other value that 1 causes the toolchain wrapper to not use ccache. The main Buildroot Makefile is modified to export BR2_USE_CCACHE = 1 when ccache support is enabled, so that ccache is used during the Buildroot build. However, when someone will use the SDK outside of Buildroot, the toolchain wrapper will not use ccache. The BR2_USE_CCACHE variable is only conditionally enabled in the main Makefile (via ?=) so that it can be overridden in the environment if one wants to quickly test disabling ccache in a ccache-enabled Buildroot configuration. This is the scenario that was considered in commit 792f1278e3fbc165086aebb8c07cfd18e10f374b ("toolchain-wrapper: support change of BR2_CCACHE"), which added the BR_NO_CCACHE variable. The BR_NO_CCACHE variable is no longer needed, and replaced by this BR2_USE_CCACHE variable. Signed-off-by: Paul Cercueil [Thomas: almost entirely rework the implementation and commit log] Signed-off-by: Thomas Petazzoni --- Makefile | 3 +-- toolchain/toolchain-wrapper.c | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4305c8c3dd..7d2081b98e 100644 --- a/Makefile +++ b/Makefile @@ -478,8 +478,7 @@ BR_CACHE_DIR ?= $(call qstrip,$(BR2_CCACHE_DIR)) export BR_CACHE_DIR HOSTCC = $(CCACHE) $(HOSTCC_NOCCACHE) HOSTCXX = $(CCACHE) $(HOSTCXX_NOCCACHE) -else -export BR_NO_CCACHE +export BR2_USE_CCACHE ?= 1 endif # Scripts in support/ or post-build scripts may need to reference diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c index 0fb6064b1c..37b24dd24a 100644 --- a/toolchain/toolchain-wrapper.c +++ b/toolchain/toolchain-wrapper.c @@ -507,8 +507,10 @@ int main(int argc, char **argv) exec_args = args; #ifdef BR_CCACHE - if (getenv("BR_NO_CCACHE")) - /* Skip the ccache call */ + /* If BR2_USE_CCACHE is not defined, or its value is not 1, + * skip the ccache call */ + char *br_use_ccache = getenv("BR2_USE_CCACHE"); + if (!br_use_ccache || strncmp(br_use_ccache, "1", strlen("1"))) exec_args++; #endif