Reject relative CCACHE_BASEDIR values too

This commit is contained in:
J. Nick Koston
2026-08-26 14:13:57 -05:00
parent 26e51c23b1
commit 1d4d28832e
2 changed files with 4 additions and 7 deletions
+3 -6
View File
@@ -99,10 +99,7 @@ def effective_ccache_basedir() -> str:
from esphome.core import CORE
raw = os.environ.get("CCACHE_BASEDIR")
if raw is not None:
# A degenerate value ("", "/", relative) must not be used for
# substring stripping; fall back to the resolved build path
if len(Path(raw).parts) > 1:
return raw
return str(Path(CORE.build_path).resolve())
if raw is not None and Path(raw).is_absolute() and len(Path(raw).parts) > 1:
return raw
# Unset or degenerate ("", "/", relative): fall back to the build path
return str(Path(CORE.build_path).resolve())
@@ -130,6 +130,6 @@ def test_effective_ccache_basedir_prefers_user_value(tmp_path: Path) -> None:
with patch.dict(os.environ, {}, clear=True):
assert ccache.effective_ccache_basedir() == str(tmp_path.resolve())
# Degenerate values would strip substrings ccache never rewrites
for bad in ("", "/"):
for bad in ("", "/", "a/b"):
with patch.dict(os.environ, {"CCACHE_BASEDIR": bad}, clear=True):
assert ccache.effective_ccache_basedir() == str(tmp_path.resolve())