public inbox for buildroot@busybox.net
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/host-ccache: force use of BR_CACHE_DIR instead of user directories
@ 2026-03-13 11:07 Shubham Chakraborty
  2026-03-13 11:07 ` [Buildroot] [PATCH] DEVELOPERS: add Shubham Chakraborty as ccache maintainer Shubham Chakraborty
  2026-03-13 17:06 ` [Buildroot] [PATCH] package/host-ccache: force use of BR_CACHE_DIR instead of user directories Fiona Klute via buildroot
  0 siblings, 2 replies; 6+ messages in thread
From: Shubham Chakraborty @ 2026-03-13 11:07 UTC (permalink / raw)
  To: buildroot; +Cc: 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

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)
-- 
2.53.0

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-03 10:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [Buildroot] [PATCH] package/host-ccache: force use of BR_CACHE_DIR instead of user directories Fiona Klute via buildroot
2026-03-13 17:21   ` Shubham Chakraborty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox