public inbox for buildroot@busybox.net
 help / color / mirror / Atom feed
From: Fiona Klute via buildroot <buildroot@buildroot.org>
To: Shubham Chakraborty <chakrabortyshubham66@gmail.com>,
	buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH] package/host-ccache: force use of BR_CACHE_DIR instead of user directories
Date: Fri, 13 Mar 2026 19:06:31 +0200	[thread overview]
Message-ID: <402fa802-4fd9-49a8-926a-ce9dbde5ce5e@gmx.de> (raw)
In-Reply-To: <20260313110739.90948-1-chakrabortyshubham66@gmail.com>

Am 13.03.26 um 13:07 schrieb Shubham Chakraborty:
> Override ccache's default cache directory paths to use Buildroot's
> BR_CACHE_DIR environment variable instead of CCACHE_DIR and XDG
> standard directories.
> 
> By default, ccache stores its cache in user home directories
> (~/.ccache, ~/.cache/ccache, ~/.config/ccache) based on XDG_CACHE_HOME
> and XDG_CONFIG_HOME environment variables. This causes issues in
> Buildroot because:
> 
>   - Pollutes user home directories during builds
>   - Breaks reproducibility across different build environments
>   - Complicates cache management in CI/CD systems
>   - May cause permission issues in shared build systems

Under what circumstances can these issues appear? I've done many 
Buildroot builds with CCache enabled and haven't encountered any of 
them. HOST_CCACHE_PATCH_CONFIGURATION should already be doing what you 
describe as the purpose of the new patch, if that's not working 
understanding why seems important.

Best regards,
Fiona

> This patch modifies ccache source to:
>   - Replace util::getenv_path("CCACHE_DIR") with "BR_CACHE_DIR"
>   - Replace hardcoded paths (.ccache, .cache/ccache, .config/ccache)
>     with Buildroot's HOST_CCACHE_DEFAULT_CCACHE_DIR
>   - Disable XDG_CACHE_HOME, XDG_CONFIG_HOME, and XDG_RUNTIME_DIR lookups
>   - Update command-line option handling to use BR_CACHE_DIR
> 
> This ensures ccache respects Buildroot's cache directory configuration
> and avoids user home directory pollution.
> 
> Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
> ---
>   ...ost-ccache-force-use-of-BR_CACHE_DIR.patch | 108 ++++++++++++++++++
>   package/ccache/ccache.mk                      |  11 +-
>   2 files changed, 110 insertions(+), 9 deletions(-)
>   create mode 100644 package/ccache/0001-package-host-ccache-force-use-of-BR_CACHE_DIR.patch
> 
> diff --git a/package/ccache/0001-package-host-ccache-force-use-of-BR_CACHE_DIR.patch b/package/ccache/0001-package-host-ccache-force-use-of-BR_CACHE_DIR.patch
> new file mode 100644
> index 0000000000..a990c43dd2
> --- /dev/null
> +++ b/package/ccache/0001-package-host-ccache-force-use-of-BR_CACHE_DIR.patch
> @@ -0,0 +1,108 @@
> +From 5140c64cdd2d469ff5be7f94cc11de928cbe585a Mon Sep 17 00:00:00 2001
> +From: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
> +Date: Fri, 13 Mar 2026 15:38:53 +0530
> +Subject: [PATCH] package/host-ccache: force use of BR_CACHE_DIR.
> +
> +Override ccache's default cache directory paths to use Buildroot's
> +BR_CACHE_DIR environment variable instead of CCACHE_DIR and XDG
> +standard directories.
> +
> +By default, ccache stores its cache in user home directories
> +(~/.ccache, ~/.cache/ccache, ~/.config/ccache) based on XDG_CACHE_HOME
> +and XDG_CONFIG_HOME environment variables. This causes issues in
> +Buildroot because:
> +
> + - Pollutes user home directories during builds
> + - Breaks reproducibility across different build environments
> + - Complicates cache management in CI/CD systems
> + - May cause permission issues in shared build systems
> +
> +This patch modifies ccache source to:
> + - Replace util::getenv_path("CCACHE_DIR") with "BR_CACHE_DIR"
> + - Replace hardcoded paths (.ccache, .cache/ccache, .config/ccache)
> +   with Buildroot's HOST_CCACHE_DEFAULT_CCACHE_DIR
> + - Disable XDG_CACHE_HOME, XDG_CONFIG_HOME, and XDG_RUNTIME_DIR lookups
> + - Update command-line option handling to use BR_CACHE_DIR
> +
> +This ensures ccache respects Buildroot's cache directory configuration
> +and avoids user home directory pollution.
> +
> +Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
> +---
> + src/ccache/config.cpp           | 14 +++++++-------
> + src/ccache/core/mainoptions.cpp |  2 +-
> + 2 files changed, 8 insertions(+), 8 deletions(-)
> +
> +diff --git a/src/ccache/config.cpp b/src/ccache/config.cpp
> +index a4f67d8..1a6e130 100644
> +--- a/src/ccache/config.cpp
> ++++ b/src/ccache/config.cpp
> +@@ -500,7 +500,7 @@ default_cache_dir(const fs::path& home_dir)
> + #  ifdef __APPLE__
> +   return home_dir / "Library/Caches/ccache";
> + #  else
> +-  return home_dir / ".cache/ccache";
> ++  return home_dir / HOST_CCACHE_DEFAULT_CCACHE_DIR;
> + #  endif
> + }
> +
> +@@ -510,7 +510,7 @@ default_config_dir(const fs::path& home_dir)
> + #  ifdef __APPLE__
> +   return home_dir / "Library/Preferences/ccache";
> + #  else
> +-  return home_dir / ".config/ccache";
> ++  return home_dir / HOST_CCACHE_DEFAULT_CCACHE_DIR;
> + #  endif
> + }
> +
> +@@ -598,13 +598,13 @@ Config::read(const std::vector<std::string>& cmdline_config_settings)
> +     create_cmdline_settings_map(cmdline_config_settings);
> +
> +   const fs::path home_dir = home_directory();
> +-  const util::DirEntry legacy_ccache_dir = home_dir / ".ccache";
> ++  const util::DirEntry legacy_ccache_dir = home_dir / HOST_CCACHE_DEFAULT_CCACHE_DIR;
> + #ifdef _WIN32
> +   auto env_appdata = util::getenv_path("APPDATA");
> +   auto env_local_appdata = util::getenv_path("LOCALAPPDATA");
> + #else
> +-  auto env_xdg_cache_home = util::getenv_path("XDG_CACHE_HOME");
> +-  auto env_xdg_config_home = util::getenv_path("XDG_CONFIG_HOME");
> ++  auto env_xdg_cache_home = std::optional<fs::path>(std::nullopt);
> ++  auto env_xdg_config_home = std::optional<fs::path>(std::nullopt);
> + #endif
> +
> +   auto env_ccache_configpath = util::getenv_path("CCACHE_CONFIGPATH");
> +@@ -627,7 +627,7 @@ Config::read(const std::vector<std::string>& cmdline_config_settings)
> +     // A missing config file in SYSCONFDIR is OK so don't check return value.
> +     update_from_file(system_config_path());
> +
> +-    auto env_ccache_dir = util::getenv_path("CCACHE_DIR");
> ++    auto env_ccache_dir = util::getenv_path("BR_CACHE_DIR");
> +     auto cmdline_cache_dir = cmdline_settings_map.find("cache_dir");
> +
> +     fs::path config_dir;
> +@@ -1232,7 +1232,7 @@ Config::default_temporary_dir() const
> + {
> +   static const fs::path run_user_tmp_dir = [] {
> + #ifndef _WIN32
> +-    const char* const xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
> ++    const char* const xdg_runtime_dir = nullptr;
> +     if (xdg_runtime_dir && DirEntry(xdg_runtime_dir).is_directory()) {
> +       fs::path dir = FMT("{}/ccache-tmp", xdg_runtime_dir);
> +       if (fs::create_directories(dir) && access(dir.c_str(), W_OK) == 0) {
> +diff --git a/src/ccache/core/mainoptions.cpp b/src/ccache/core/mainoptions.cpp
> +index d253ebc..9ad2824 100644
> +--- a/src/ccache/core/mainoptions.cpp
> ++++ b/src/ccache/core/mainoptions.cpp
> +@@ -527,7 +527,7 @@ process_main_options(int argc, const char* const* argv)
> +
> +     switch (c) {
> +     case 'd': // --dir
> +-      util::setenv("CCACHE_DIR", arg);
> ++      util::setenv("BR_CACHE_DIR", arg);
> +       break;
> +     case FORMAT:
> +       if (arg == "tab") {
> +--
> +2.53.0
> +
> diff --git a/package/ccache/ccache.mk b/package/ccache/ccache.mk
> index 30f87f7d90..f2f73a115d 100644
> --- a/package/ccache/ccache.mk
> +++ b/package/ccache/ccache.mk
> @@ -42,16 +42,9 @@ HOST_CCACHE_CONF_OPTS += \
>   #    so rewrite BR_CACHE_DIR to take that into consideration for SDK purpose
>   HOST_CCACHE_DEFAULT_CCACHE_DIR = $(patsubst $(HOME)/%,%,$(BR_CACHE_DIR))
>   
> -define HOST_CCACHE_PATCH_CONFIGURATION
> -	sed -i 's,getenv("CCACHE_DIR"),getenv("BR_CACHE_DIR"),' $(@D)/src/ccache/config.cpp
> -	sed -i 's,".ccache","$(HOST_CCACHE_DEFAULT_CCACHE_DIR)",' $(@D)/src/ccache/config.cpp
> -	sed -i 's,"/.cache/ccache","/$(HOST_CCACHE_DEFAULT_CCACHE_DIR)",' $(@D)/src/ccache/config.cpp
> -	sed -i 's,"/.config/ccache","/$(HOST_CCACHE_DEFAULT_CCACHE_DIR)",' $(@D)/src/ccache/config.cpp
> -	sed -i 's,getenv("XDG_CACHE_HOME"),nullptr,' $(@D)/src/ccache/config.cpp
> -	sed -i 's,getenv("XDG_CONFIG_HOME"),nullptr,' $(@D)/src/ccache/config.cpp
> -endef
> +HOST_CCACHE_CONF_OPTS += \
> +	-DCMAKE_CXX_FLAGS='$(HOST_CXXFLAGS) -DHOST_CCACHE_DEFAULT_CCACHE_DIR=\"$(HOST_CCACHE_DEFAULT_CCACHE_DIR)\"'
>   
> -HOST_CCACHE_POST_PATCH_HOOKS += HOST_CCACHE_PATCH_CONFIGURATION
>   
>   define HOST_CCACHE_MAKE_CACHE_DIR
>   	mkdir -p $(BR_CACHE_DIR)

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2026-03-13 17:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13 11:07 [Buildroot] [PATCH] package/host-ccache: force use of BR_CACHE_DIR instead of user directories Shubham Chakraborty
2026-03-13 11:07 ` [Buildroot] [PATCH] DEVELOPERS: add Shubham Chakraborty as ccache maintainer Shubham Chakraborty
2026-03-27 20:33   ` Julien Olivain via buildroot
2026-04-03 10:28   ` Thomas Perale via buildroot
2026-03-13 17:06 ` Fiona Klute via buildroot [this message]
2026-03-13 17:21   ` [Buildroot] [PATCH] package/host-ccache: force use of BR_CACHE_DIR instead of user directories Shubham Chakraborty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=402fa802-4fd9-49a8-926a-ce9dbde5ce5e@gmx.de \
    --to=buildroot@buildroot.org \
    --cc=chakrabortyshubham66@gmail.com \
    --cc=fiona.klute@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox