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 792f1278e3 ("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 <paul@crapouillou.net>
[Thomas: almost entirely rework the implementation and commit log]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022.08.x
Paul Cercueil 2022-01-13 21:04:31 +00:00 committed by Thomas Petazzoni
parent d353d30dee
commit d5c0eaef1f
2 changed files with 5 additions and 4 deletions

View File

@ -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

View File

@ -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