From e46f739c7cd87221b1900729689b89f7ef297ed5 Mon Sep 17 00:00:00 2001 From: Dev M <294291171+devtechedge@users.noreply.github.com> Date: Tue, 6 Oct 2026 18:31:22 +0530 Subject: [PATCH 1/5] test: show --debug-preprocessor-cache ignores SCCACHE_DIR The debug command always reads the platform default cache dir, so it fails when the cache is moved with SCCACHE_DIR or [cache.disk] dir. --- tests/sccache_args.rs | 63 +++++++++++++++++++++++++++++++++++++++++++ tests/system.rs | 16 +++++++++++ 2 files changed, 79 insertions(+) diff --git a/tests/sccache_args.rs b/tests/sccache_args.rs index 4b4b3d24bf..96ef99fafc 100644 --- a/tests/sccache_args.rs +++ b/tests/sccache_args.rs @@ -6,9 +6,11 @@ pub mod helpers; use anyhow::Result; use assert_cmd::prelude::*; +use fs_err as fs; use helpers::{SCCACHE_BIN, stop_sccache}; use predicates::prelude::*; use serial_test::serial; +use std::path::Path; use std::process::Command; #[macro_use] @@ -77,3 +79,64 @@ fn test_s3_invalid_args() -> Result<()> { Ok(()) } + +/// An empty entry file reads as a valid, empty entry. +fn write_empty_preprocessor_entry(cache_dir: &Path) -> Result { + let entries_dir = cache_dir.join("preprocessor"); + fs::create_dir_all(&entries_dir)?; + let entry = entries_dir.join("entry"); + fs::write(&entry, b"")?; + Ok(format!( + "Showing preprocessor entry file {}", + entry.display() + )) +} + +fn debug_preprocessor_cache_cmd(tempdir: &Path) -> Command { + let mut cmd = Command::new(SCCACHE_BIN.as_os_str()); + // Keep any user config out, and on Linux point the default cache dir + // somewhere empty. + cmd.arg("--debug-preprocessor-cache") + .env_remove("SCCACHE_DIR") + .env("SCCACHE_CONF", tempdir.join("missing-config")) + .env("XDG_CACHE_HOME", tempdir.join("xdg-cache")); + cmd +} + +#[test] +#[serial] +fn test_debug_preprocessor_cache_uses_sccache_dir() -> Result<()> { + let tempdir = tempfile::tempdir()?; + let cache_dir = tempdir.path().join("cache"); + let expected = write_empty_preprocessor_entry(&cache_dir)?; + + debug_preprocessor_cache_cmd(tempdir.path()) + .env("SCCACHE_DIR", &cache_dir) + .assert() + .success() + .stdout(predicate::str::contains(expected)); + + Ok(()) +} + +#[test] +#[serial] +fn test_debug_preprocessor_cache_uses_config_disk_dir() -> Result<()> { + let tempdir = tempfile::tempdir()?; + let cache_dir = tempdir.path().join("cache"); + let expected = write_empty_preprocessor_entry(&cache_dir)?; + let config = tempdir.path().join("config"); + // TOML literal string, so Windows backslashes are not escapes. + fs::write( + &config, + format!("[cache.disk]\ndir = '{}'\n", cache_dir.display()), + )?; + + debug_preprocessor_cache_cmd(tempdir.path()) + .env("SCCACHE_CONF", &config) + .assert() + .success() + .stdout(predicate::str::contains(expected)); + + Ok(()) +} diff --git a/tests/system.rs b/tests/system.rs index f1d66cd96d..9cddc5fab4 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -1977,10 +1977,26 @@ fn test_sccache_command(preprocessor_cache_mode: bool) { &tempdir.path().join("sccache-cfg.json"), &sccache_cached_cfg_path, ); + let wrote_preprocessor_entries = preprocessor_cache_mode + && compilers + .iter() + .any(|c| matches!(c.name, "gcc" | "clang" | "clang++")); for compiler in compilers { run_sccache_command_tests(compiler, tempdir.path(), preprocessor_cache_mode); zero_stats(); } + if wrote_preprocessor_entries { + let entries_dir = tempdir.path().join("client-cache").join("preprocessor"); + sccache_command() + .arg("--debug-preprocessor-cache") + .env("SCCACHE_CONF", tempdir.path().join("sccache-cfg.json")) + .assert() + .success() + .stdout(predicate::str::contains(format!( + "Showing preprocessor entry file {}", + entries_dir.display() + ))); + } stop_local_daemon(); } } From 9ae36146b47ca457b7f3bb2d75edf95123161d71 Mon Sep 17 00:00:00 2001 From: Dev M <294291171+devtechedge@users.noreply.github.com> Date: Tue, 6 Oct 2026 18:31:43 +0530 Subject: [PATCH 2/5] commands: read preprocessor entries from the configured disk cache dir The server stores preprocessor cache entries under the disk cache dir from the config, which honours SCCACHE_DIR and [cache.disk] dir. The debug command now reads them from the same place instead of the platform default. Fixes #2880 --- src/commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 805827dd39..dcb48b47c7 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -16,7 +16,7 @@ use crate::cache::{IpcStorage, storage_from_config}; use crate::client::{ServerConnection, connect_to_server, connect_with_retry}; use crate::cmdline::{Command, StatsFormat}; use crate::compiler::{ColorMode, is_rmeta_artifact_notification}; -use crate::config::{Config, default_disk_cache_dir}; +use crate::config::Config; use crate::jobserver::Client; use crate::mock_command::{CommandChild, CommandCreatorSync, ProcessCommandCreator, RunCommand}; use crate::protocol::{Compile, CompileFinished, CompileResponse, Request, Response}; @@ -795,7 +795,7 @@ pub fn run_command(cmd: Command) -> Result { } Command::DebugPreprocessorCacheEntries => { trace!("Command::DebugPreprocessorCacheEntries"); - let entries_dir = default_disk_cache_dir().join("preprocessor"); + let entries_dir = config.fallback_cache.dir.join("preprocessor"); for entry in WalkDir::new(entries_dir).sort_by_file_name() { let preprocessor_cache_entry_file = entry?; let path = preprocessor_cache_entry_file.path(); From d31ddaf4d98b0f018bf1f69d7ef076f6b7fe958c Mon Sep 17 00:00:00 2001 From: Dev M <294291171+devtechedge@users.noreply.github.com> Date: Wed, 7 Oct 2026 03:18:31 +0530 Subject: [PATCH 3/5] tests: check for the preprocessor dir instead of listing compilers --- tests/system.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/system.rs b/tests/system.rs index 9cddc5fab4..9aa5bc6ab6 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -1977,16 +1977,12 @@ fn test_sccache_command(preprocessor_cache_mode: bool) { &tempdir.path().join("sccache-cfg.json"), &sccache_cached_cfg_path, ); - let wrote_preprocessor_entries = preprocessor_cache_mode - && compilers - .iter() - .any(|c| matches!(c.name, "gcc" | "clang" | "clang++")); for compiler in compilers { run_sccache_command_tests(compiler, tempdir.path(), preprocessor_cache_mode); zero_stats(); } - if wrote_preprocessor_entries { - let entries_dir = tempdir.path().join("client-cache").join("preprocessor"); + let entries_dir = tempdir.path().join("client-cache").join("preprocessor"); + if entries_dir.exists() { sccache_command() .arg("--debug-preprocessor-cache") .env("SCCACHE_CONF", tempdir.path().join("sccache-cfg.json")) From abcaaf56ae5afbdf67311e82d3f9963545065c92 Mon Sep 17 00:00:00 2001 From: Dev M <294291171+devtechedge@users.noreply.github.com> Date: Wed, 7 Oct 2026 03:18:39 +0530 Subject: [PATCH 4/5] tests: fit the expected preprocessor entry line on one line --- tests/sccache_args.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/sccache_args.rs b/tests/sccache_args.rs index 96ef99fafc..3a7a543353 100644 --- a/tests/sccache_args.rs +++ b/tests/sccache_args.rs @@ -86,10 +86,8 @@ fn write_empty_preprocessor_entry(cache_dir: &Path) -> Result { fs::create_dir_all(&entries_dir)?; let entry = entries_dir.join("entry"); fs::write(&entry, b"")?; - Ok(format!( - "Showing preprocessor entry file {}", - entry.display() - )) + let expected = format!("Showing preprocessor entry file {}", entry.display()); + Ok(expected) } fn debug_preprocessor_cache_cmd(tempdir: &Path) -> Command { From f0c2996087f67f59de07eff05f50d410be1bfcf2 Mon Sep 17 00:00:00 2001 From: devtechedge Date: Sat, 10 Oct 2026 03:12:25 +0530 Subject: [PATCH 5/5] tests: only check --debug-preprocessor-cache output when entries exist MSVC does not write preprocessor cache entries, but the preprocessor directory is still created by the disk cache, so the check failed on Windows with empty output. --- tests/system.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/system.rs b/tests/system.rs index 9aa5bc6ab6..57e5f65c6e 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -1981,8 +1981,15 @@ fn test_sccache_command(preprocessor_cache_mode: bool) { run_sccache_command_tests(compiler, tempdir.path(), preprocessor_cache_mode); zero_stats(); } + // The preprocessor dir is created as soon as the disk cache is used, + // but entries are only written by compilers that support preprocessor + // cache mode (not MSVC), so check for an actual entry file. let entries_dir = tempdir.path().join("client-cache").join("preprocessor"); - if entries_dir.exists() { + let has_entries = walkdir::WalkDir::new(&entries_dir) + .into_iter() + .filter_map(Result::ok) + .any(|e| e.file_type().is_file()); + if has_entries { sccache_command() .arg("--debug-preprocessor-cache") .env("SCCACHE_CONF", tempdir.path().join("sccache-cfg.json"))