From 9a56bcf0dadc69caaf909ff1bb9a8a3d6a04d8a5 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Tue, 24 Nov 2026 10:34:06 +0100 Subject: [PATCH 1/3] Read SCCACHE_BASEDIRS from the compile environment as well --- docs/Configuration.md | 2 +- src/compiler/c.rs | 11 +-- src/compiler/rust.rs | 53 ++++++++++++- src/config.rs | 174 ++++++++++++++++++++++++++++------------- tests/sccache_cargo.rs | 46 +++++++++++ tests/system.rs | 87 ++++++++++++++++++++- 6 files changed, 310 insertions(+), 63 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index abff72fd74..c234aa3216 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -198,7 +198,7 @@ Note that some env variables may need sccache server restart to take effect. * `SCCACHE_ALLOW_CORE_DUMPS` to enable core dumps by the server * `SCCACHE_ALLOW_INCREMENTAL` set to `1` to allow Rust builds with `CARGO_INCREMENTAL=1`, leaving incremental crates uncached, or to `cache` to cache them too. See [Rust caveats](Rust.md) * `SCCACHE_CONF` configuration file path -* `SCCACHE_BASEDIRS` base directory (or directories) to strip from paths for cache key computation. This is similar to ccache's `CCACHE_BASEDIR` and enables cache hits across different absolute paths when compiling the same source code. Multiple directories can be separated by `;` on Windows hosts and by `:` on any other operating system. When multiple directories are specified, the longest matching prefix is used. Path matching is **case-insensitive** on Windows and **case-sensitive** on other operating systems. Environment variable takes precedence over file configuration. Only absolute paths are supported; relative paths will cause an error and prevent the server from start. +* `SCCACHE_BASEDIRS` base directory (or directories) to strip from paths for cache key computation. This is similar to ccache's `CCACHE_BASEDIR` and enables cache hits across different absolute paths when compiling the same source code. Multiple directories can be separated by `;` on Windows hosts and by `:` on any other operating system. When multiple directories are specified, the longest matching prefix is used. Path matching is **case-insensitive** on Windows and **case-sensitive** on other operating systems. Environment variable takes precedence over file configuration. Only absolute paths are supported; relative paths will cause an error and prevent the server from start. Also read from the environment of each compile, where it replaces the server's basedirs for that compile, so each checkout can set its own root; an empty value turns basedirs off, and a value with a relative path or not valid UTF-8 is ignored with a warning. Names are case-insensitive on Windows. * `SCCACHE_BASEDIRS_VERBATIM_ENV_DEPS` comma-separated names of variables that a Rust crate reads with `env!` or `option_env!` whose values are hashed without stripping `SCCACHE_BASEDIRS`, e.g. `CARGO_MANIFEST_DIR,CARGO_MANIFEST_PATH`. Read from the environment of each compile; empty or not valid UTF-8 means none. Names are case-insensitive on Windows. See [Rust caveats](Rust.md) * `SCCACHE_CACHED_CONF` * `SCCACHE_DIST_CLIENT_CACHE_DIR` distributed toolchain cache directory; overrides `[dist].cache_dir` from the configuration file. diff --git a/src/compiler/c.rs b/src/compiler/c.rs index a3f0691468..478f42e3a7 100644 --- a/src/compiler/c.rs +++ b/src/compiler/c.rs @@ -22,7 +22,7 @@ use crate::compiler::{ }; #[cfg(feature = "dist-client")] use crate::compiler::{DistPackagers, NoopOutputsRewriter}; -use crate::config::PreprocessorCacheModeConfig; +use crate::config::{PreprocessorCacheModeConfig, compile_basedirs}; use crate::dist; #[cfg(feature = "dist-client")] use crate::dist::pkg; @@ -442,6 +442,7 @@ where // Try to look for a cached preprocessing step for this compilation // request. let preprocessor_cache_mode_config = storage.preprocessor_cache_mode_config(); + let basedirs = compile_basedirs(&env_vars, storage.basedirs()); let too_hard_for_preprocessor_cache_mode = self .parsed_args .too_hard_for_preprocessor_cache_mode @@ -502,7 +503,7 @@ where self.compiler.plusplus(), self.parsed_args.is_multiarch(), preprocessor_cache_mode_config, - storage.basedirs(), + &basedirs, )? } else { None @@ -513,7 +514,7 @@ where // records have to be checked against this tree's copies and not against // the ones that happened to write the entry. let tree_root = if preprocessor_key.is_some() { - compilation_tree_root(&absolute_input_path, &cwd, storage.basedirs())? + compilation_tree_root(&absolute_input_path, &cwd, &basedirs)? } else { None }; @@ -693,7 +694,7 @@ where .with_extra_hashes(&extra_hashes) .with_env_vars(&env_vars) .with_plusplus(self.compiler.plusplus()) - .with_basedirs(storage.basedirs()) + .with_basedirs(&basedirs) .with_assembler_digest(assembler_digest.as_deref()) .with_input_file_name(hashed_input_file_name( self.parsed_args.language, @@ -715,7 +716,7 @@ where start_of_compilation, &key, files, - storage.basedirs(), + &basedirs, tree_root.as_deref(), ); diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index 56c291d457..f13a8bb216 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -21,6 +21,7 @@ use crate::compiler::{ }; #[cfg(feature = "dist-client")] use crate::compiler::{DistPackagers, NoopOutputsRewriter}; +use crate::config::compile_basedirs; #[cfg(feature = "dist-client")] use crate::dist::pkg; #[cfg(feature = "dist-client")] @@ -1994,7 +1995,7 @@ where _cache_control: CacheControl, ) -> Result> { trace!("[{}]: generate_hash_key", self.parsed_args.crate_name); - let basedirs = storage.basedirs(); + let basedirs = &*compile_basedirs(&env_vars, storage.basedirs()); // Keep the incremental directory out of the key, and out of the dep-info and // file-names runs so they don't touch it. let incremental = self.parsed_args.arguments.iter().any(is_incremental_arg); @@ -5017,6 +5018,56 @@ foo.rs: assert_eq!(key(&a, "x", vec![]), key(&a, "x", vec![elsewhere])); } + /// `SCCACHE_BASEDIRS` in the compile environment replaces the configured basedirs. + #[test] + fn test_hash_basedirs_from_compile_env() { + fn key(f: &TestFixture, env_basedirs: Option<&OsStr>, configured: Vec>) -> String { + let root = f.tempdir.path(); + let mut env_vars: Vec<(OsString, OsString)> = + vec![("CARGO_MANIFEST_DIR".into(), root.into())]; + env_vars.extend(env_basedirs.map(|v| ("SCCACHE_BASEDIRS".into(), v.into()))); + hash_key_with( + f, + &[ + "--emit", + "link", + "foo.rs", + "--out-dir", + "out", + "--crate-name", + "foo", + "--crate-type", + "lib", + ], + &env_vars, + &[], + nothing, + MockStorage::new(None, false).with_basedirs(configured), + ) + } + + let a = TestFixture::new(); + let b = TestFixture::new(); + let a_root = a.tempdir.path().as_os_str(); + let b_root = b.tempdir.path().as_os_str(); + let both = vec![basedir(a.tempdir.path()), basedir(b.tempdir.path())]; + // Each checkout names only its own root and still shares the key. + assert_eq!(key(&a, Some(a_root), vec![]), key(&b, Some(b_root), vec![])); + assert_eq!(key(&a, Some(a_root), vec![]), key(&a, None, both.clone())); + // An empty value turns the configured basedirs off. + assert_ne!( + key(&a, Some(OsStr::new("")), both.clone()), + key(&b, Some(OsStr::new("")), both.clone()) + ); + assert_eq!( + key(&a, Some(OsStr::new("")), both.clone()), + key(&a, None, vec![]) + ); + // A relative path is ignored in favor of the configured basedirs. + let relative = Some(OsStr::new("relative")); + assert_eq!(key(&a, relative, both.clone()), key(&b, relative, both)); + } + #[test] fn test_hash_key_cache_incremental() { let f = TestFixture::new(); diff --git a/src/config.rs b/src/config.rs index 7de90a6dba..dcaa1148c7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,6 +13,7 @@ // limitations under the License. use crate::cache::CacheMode; +use crate::util::env_var_name_matches; #[cfg(target_os = "windows")] use crate::util::normalize_win_path; use directories::ProjectDirs; @@ -26,7 +27,9 @@ use serde::{ }; #[cfg(test)] use serial_test::serial; +use std::borrow::Cow; use std::env; +use std::ffi::OsString; use std::io::{Read, Write}; use std::num::NonZeroU64; use std::path::{Path, PathBuf}; @@ -1276,20 +1279,7 @@ fn config_from_env() -> Result { multilevel, }; - // ======= Base directory ======= - // Support multiple paths separated by ';' on Windows and ':' on other platforms - // to match PATH behavior. - #[cfg(target_os = "windows")] - let split_symbol = ';'; - #[cfg(not(target_os = "windows"))] - let split_symbol = ':'; - let basedirs = env::var_os("SCCACHE_BASEDIRS").map(|s| { - s.to_string_lossy() - .split(split_symbol) - .filter(|s| !s.is_empty()) - .map(|s| s.to_owned()) - .collect() - }); + let basedirs = env::var_os("SCCACHE_BASEDIRS").map(|s| split_basedirs(&s.to_string_lossy())); let dist_cache_dir = env::var_os("SCCACHE_DIST_CLIENT_CACHE_DIR").map(PathBuf::from); let client_side_mode = bool_from_env_var("SCCACHE_CLIENT_SIDE")?; @@ -1302,6 +1292,78 @@ fn config_from_env() -> Result { }) } +/// Split a `SCCACHE_BASEDIRS` value on `;` on Windows and `:` elsewhere, like `PATH`. +fn split_basedirs(value: &str) -> Vec { + #[cfg(target_os = "windows")] + let split_symbol = ';'; + #[cfg(not(target_os = "windows"))] + let split_symbol = ':'; + value + .split(split_symbol) + .filter(|s| !s.is_empty()) + .map(|s| s.to_owned()) + .collect() +} + +/// Normalize basedirs into the form `strip_basedirs` matches against: absolute, +/// without `.` and `..`, with a trailing `/`, and on Windows with forward slashes +/// and lowercase. +fn normalize_basedirs(raw: Vec) -> Result>> { + let mut basedirs = Vec::with_capacity(raw.len()); + for d in raw { + let p = Utf8TypedPathBuf::from(d); + if !p.is_absolute() { + bail!("Basedir path must be absolute: {:?}", p); + } + let mut bytes = p.normalize().to_string().into_bytes(); + // Only match complete path components. + bytes.push(b'/'); + #[cfg(target_os = "windows")] + let bytes = normalize_win_path(&bytes); + if !basedirs.contains(&bytes) { + basedirs.push(bytes); + } + } + Ok(basedirs) +} + +fn basedirs_display(basedirs: &[Vec]) -> Vec> { + basedirs + .iter() + .map(|b| String::from_utf8_lossy(b)) + .collect() +} + +/// The basedirs for one compile: `SCCACHE_BASEDIRS` from its environment when set, +/// else the configured ones. An invalid value is ignored. +pub fn compile_basedirs<'a>( + env_vars: &[(OsString, OsString)], + configured: &'a [Vec], +) -> Cow<'a, [Vec]> { + const VAR: &str = "SCCACHE_BASEDIRS"; + let Some((_, value)) = env_vars.iter().find(|(k, _)| env_var_name_matches(k, VAR)) else { + return Cow::Borrowed(configured); + }; + let Some(value) = value.to_str() else { + warn!("Ignoring {VAR}: not valid UTF-8: {value:?}"); + return Cow::Borrowed(configured); + }; + match normalize_basedirs(split_basedirs(value)) { + Ok(basedirs) if basedirs == configured => Cow::Borrowed(configured), + Ok(basedirs) => { + debug!( + "Using basedirs from the compile environment: {:?}", + basedirs_display(&basedirs) + ); + Cow::Owned(basedirs) + } + Err(e) => { + warn!("Ignoring {VAR}={value:?}: {e}"); + Cow::Borrowed(configured) + } + } +} + // The directories crate changed the location of `config_dir` on macos in version 3, // so we also check the config in `preference_dir` (new in that version), which // corresponds to the old location, for compatibility with older setups. @@ -1388,47 +1450,12 @@ impl Config { file_basedirs }; - // Validate that all basedirs are absolute paths - // basedirs_raw is Vec - let mut basedirs = Vec::with_capacity(basedirs_raw.len()); - for d in basedirs_raw { - let p = Utf8TypedPathBuf::from(d); - if !p.is_absolute() { - bail!("Basedir path must be absolute: {:?}", p); - } - // Normalize basedir: - // remove double separators, cur_dirs, parent_dirs, trailing slashes - let p_norm = p.normalize(); - let mut bytes = p_norm.to_string().into_bytes(); - - // Always add a trailing `/` to basedirs to ensure we only match complete path - // components - bytes.push(b'/'); - - // normalize windows paths: use slashes and lowercase - let normalized = { - #[cfg(target_os = "windows")] - { - normalize_win_path(&bytes) - } - - #[cfg(not(target_os = "windows"))] - { - bytes - } - }; - // push only if not already present - if !basedirs.contains(&normalized) { - basedirs.push(normalized); - } - } - + let basedirs = normalize_basedirs(basedirs_raw)?; if !basedirs.is_empty() && log::log_enabled!(log::Level::Debug) { - let basedirs_str: Vec = basedirs - .iter() - .map(|b| String::from_utf8_lossy(b).into_owned()) - .collect(); - debug!("Using basedirs for path normalization: {:?}", basedirs_str); + debug!( + "Using basedirs for path normalization: {:?}", + basedirs_display(&basedirs) + ); } let client_side_mode = env_client_side_mode.unwrap_or(file_client_side_mode) @@ -2225,6 +2252,45 @@ fn test_cache_mode_from_env_var() { } } +#[test] +fn test_compile_basedirs() { + #[cfg(not(target_os = "windows"))] + let (value, expected, relative) = ( + "/env/a:/env/./b/:/env/a", + vec![b"/env/a/".to_vec(), b"/env/b/".to_vec()], + "/env/a:relative", + ); + #[cfg(target_os = "windows")] + let (value, expected, relative) = ( + "C:\\Env\\A;c:/env/./b/;c:/env/a", + vec![b"c:/env/a/".to_vec(), b"c:/env/b/".to_vec()], + "c:/env/a;relative", + ); + let configured = normalize_basedirs(split_basedirs(if cfg!(windows) { + "c:/conf" + } else { + "/conf" + })) + .unwrap(); + let env = |k: &str, v: &str| vec![(OsString::from(k), OsString::from(v))]; + + assert_eq!(compile_basedirs(&[], &configured), configured.as_slice()); + assert_eq!( + compile_basedirs(&env("SCCACHE_BASEDIRS", value), &configured), + expected.as_slice() + ); + assert!(compile_basedirs(&env("SCCACHE_BASEDIRS", ""), &configured).is_empty()); + assert_eq!( + compile_basedirs(&env("SCCACHE_BASEDIRS", relative), &configured), + configured.as_slice() + ); + assert_eq!( + compile_basedirs(&env("sccache_basedirs", value), &configured).as_ref() + == expected.as_slice(), + cfg!(windows) + ); +} + #[test] #[serial(config_from_env)] #[cfg(not(target_os = "windows"))] diff --git a/tests/sccache_cargo.rs b/tests/sccache_cargo.rs index 470f9c749b..fdba840c81 100644 --- a/tests/sccache_cargo.rs +++ b/tests/sccache_cargo.rs @@ -13,6 +13,7 @@ use fs_err as fs; use helpers::{SCCACHE_BIN, SccacheTest}; use predicates::prelude::*; use serial_test::serial; +use std::ffi::OsStr; use std::path::{Path, PathBuf}; use std::process::Command; @@ -427,6 +428,14 @@ fn build_checkout(test_info: &SccacheTest, name: &str) -> Result { /// /// Returns the checkout's target directory. fn cargo_build(test_info: &SccacheTest, checkout: &Path) -> Result { + cargo_build_with_env(test_info, checkout, &[]) +} + +fn cargo_build_with_env( + test_info: &SccacheTest, + checkout: &Path, + env: &[(&str, &OsStr)], +) -> Result { let target_dir = checkout.join("target"); Command::new(CARGO.as_os_str()) // `--target-dir` rather than `CARGO_TARGET_DIR`, @@ -434,6 +443,7 @@ fn cargo_build(test_info: &SccacheTest, checkout: &Path) -> Result { .args(["build", "--color=never", "--target-dir"]) .arg(&target_dir) .envs(test_info.env.iter().cloned()) + .envs(env.iter().copied()) .current_dir(checkout) .assert() .try_success()?; @@ -603,6 +613,42 @@ fn test_rust_cargo_basedirs_other_checkout() -> Result<()> { Ok(()) } +/// `SCCACHE_BASEDIRS` set for each build rather than for the server: each checkout +/// names only its own root and the second one still hits. +#[test] +#[serial] +fn test_rust_cargo_basedirs_from_compile_env() -> Result<()> { + let test_info = SccacheTest::new(None)?; + let tempdir = real_tempdir(&test_info)?; + let [a, b] = ["a", "b"].map(|name| tempdir.join(name)); + restart_sccache(&test_info, None)?; + + write_out_dir_crate(&a)?; + cargo_build_with_env(&test_info, &a, &[("SCCACHE_BASEDIRS", a.as_os_str())])?; + Command::new(SCCACHE_BIN.as_os_str()) + .arg("--zero-stats") + .assert() + .try_success()?; + write_out_dir_crate(&b)?; + cargo_build_with_env(&test_info, &b, &[("SCCACHE_BASEDIRS", b.as_os_str())])?; + + test_info + .show_stats()? + .try_stdout( + predicates::str::contains( + r#""cache_hits":{"counts":{"Rust":2},"adv_counts":{"rust":2}}"#, + ) + .from_utf8(), + )? + .try_stdout( + predicates::str::contains(r#""cache_misses":{"counts":{},"adv_counts":{}}"#) + .from_utf8(), + )? + .try_success()?; + + Ok(()) +} + /// Test that without `SCCACHE_ALLOW_INCREMENTAL`, enabling cargo's incremental /// compilation still makes sccache refuse to run. #[test] diff --git a/tests/system.rs b/tests/system.rs index f5c6ee20fa..8edb86cb18 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -2391,7 +2391,7 @@ fn test_multiarch_depfile_matches_compiler(preprocessor_cache_mode: bool) { stop_local_daemon(); } -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(unix)] fn find_gcc_or_clang() -> Option { let compiler = find_compilers() .into_iter() @@ -2402,7 +2402,7 @@ fn find_gcc_or_clang() -> Option { compiler } -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(unix)] fn restart_local_daemon_with(dir: &Path, cfg: &sccache::config::FileConfig) { write_json_cfg(dir, "sccache-cfg.json", cfg); stop_local_daemon(); @@ -2664,6 +2664,89 @@ fn test_basedirs_preprocessor_cache_checks_header_in_other_basedir() { stop_local_daemon(); } +/// `SCCACHE_BASEDIRS` set for each compile rather than for the server: each +/// checkout names only its own root and the second one still hits. +#[test_case(true ; "with preprocessor cache")] +#[test_case(false ; "without preprocessor cache")] +#[serial] +#[cfg(unix)] +fn test_basedirs_from_compile_env(preprocessor_cache_mode: bool) { + let _ = env_logger::try_init(); + let tempdir = tempfile::Builder::new() + .prefix("sccache_system_test") + .tempdir() + .unwrap(); + // The compiler sees the real path, not the macOS /var symlink. + let root = fs::canonicalize(tempdir.path()).unwrap(); + + let Some(compiler) = find_gcc_or_clang() else { + return; + }; + + let trees: Vec = ["treea", "treeb", "treec"] + .iter() + .map(|name| root.join(name)) + .collect(); + let backdated = + filetime::FileTime::from_system_time(SystemTime::now() - Duration::from_secs(10)); + for tree in &trees { + fs::create_dir_all(tree.join("inc")).unwrap(); + let header = tree.join("inc").join("cfg.h"); + fs::write(&header, "#define VALUE 42\n").unwrap(); + let source = tree.join("main.c"); + fs::write( + &source, + "#include \"cfg.h\"\nint value(void) { return VALUE; }\n", + ) + .unwrap(); + // Preprocessor cache mode refuses to record files modified during the + // compilation, and would not store an entry at all otherwise. + for file in [&header, &source] { + filetime::set_file_times(file, backdated, backdated).unwrap(); + } + } + + let sccache_cfg = sccache_client_cfg(&root, preprocessor_cache_mode); + restart_local_daemon_with(&root, &sccache_cfg); + zero_stats(); + + let compile = |tree: &Path, basedirs: Option<&Path>, hits: u64, misses: u64| { + let mut cmd = sccache_command(); + cmd.args(compile_cmdline( + compiler.name, + &compiler.exe, + tree.join("main.c").to_str().unwrap(), + "main.o", + vec![ + OsString::from(format!("-I{}", tree.join("inc").display())), + // Without the preprocessor cache only arguments like this one + // carry the tree into the key. + OsString::from(format!( + "-fdebug-prefix-map={}=.", + tree.join("inc").display() + )), + ], + )) + .current_dir(tree) + .envs(compiler.env_vars.clone()); + if let Some(basedirs) = basedirs { + cmd.env("SCCACHE_BASEDIRS", basedirs); + } + cmd.assert().success(); + get_stats(move |info| { + assert_eq!(hits, info.stats.cache_hits.all()); + assert_eq!(misses, info.stats.cache_misses.all()); + }); + }; + + compile(&trees[0], Some(&trees[0]), 0, 1); + compile(&trees[1], Some(&trees[1]), 1, 1); + // Without it, the absolute paths keep the third tree apart. + compile(&trees[2], None, 1, 2); + + stop_local_daemon(); +} + #[test] #[serial] fn test_stats_no_server() { From e35302572932f3deb4cce06e3bc7129f8ff450ac Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Tue, 24 Nov 2026 11:05:51 +0100 Subject: [PATCH 2/3] Cover non-UTF8 basedirs --- src/config.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/config.rs b/src/config.rs index dcaa1148c7..e4e4e4d896 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2289,6 +2289,21 @@ fn test_compile_basedirs() { == expected.as_slice(), cfg!(windows) ); + + #[cfg(unix)] + let invalid = { + use std::os::unix::ffi::OsStringExt; + OsString::from_vec(vec![0xff]) + }; + #[cfg(windows)] + let invalid = { + use std::os::windows::ffi::OsStringExt; + OsString::from_wide(&[0xd800]) + }; + assert_eq!( + compile_basedirs(&[("SCCACHE_BASEDIRS".into(), invalid)], &configured), + configured.as_slice() + ); } #[test] From e0dc86a360484193543bc11d32b7e59cb1c8adf7 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Wed, 25 Nov 2026 10:01:18 +0100 Subject: [PATCH 3/3] Address review points --- src/compiler/rust.rs | 12 ++++++------ src/config.rs | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index f13a8bb216..bf81ce2774 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -1995,7 +1995,7 @@ where _cache_control: CacheControl, ) -> Result> { trace!("[{}]: generate_hash_key", self.parsed_args.crate_name); - let basedirs = &*compile_basedirs(&env_vars, storage.basedirs()); + let basedirs = compile_basedirs(&env_vars, storage.basedirs()); // Keep the incremental directory out of the key, and out of the dep-info and // file-names runs so they don't touch it. let incremental = self.parsed_args.arguments.iter().any(is_incremental_arg); @@ -2197,7 +2197,7 @@ where .chain(sortables) .flat_map(|(arg, val)| iter::once(arg).chain(val.as_ref())) .fold(OsString::new(), |mut a, b| { - a.push(strip_basedirs_os(b, basedirs)); + a.push(strip_basedirs_os(b, &basedirs)); a }) }; @@ -2224,7 +2224,7 @@ where // A crate that bakes a listed env-dep such as `env!("CARGO_MANIFEST_DIR")` into its // outputs must not hit across checkouts. Stripped values start with a NUL, unlike these. env_deps.sort(); - let verbatim = basedirs_verbatim_env_deps(&env_vars, basedirs); + let verbatim = basedirs_verbatim_env_deps(&env_vars, &basedirs); for (var, val) in env_deps.iter() { var.hash(&mut HashToDigest { digest: &mut m }); let Some(val) = val else { @@ -2237,7 +2237,7 @@ where if verbatim(var) { val.hash(&mut HashToDigest { digest: &mut m }); } else { - strip_basedirs_os(val, basedirs).hash(&mut HashToDigest { digest: &mut m }); + strip_basedirs_os(val, &basedirs).hash(&mut HashToDigest { digest: &mut m }); } } let mut env_vars: Vec<_> = env_vars @@ -2272,10 +2272,10 @@ where var.hash(&mut HashToDigest { digest: &mut m }); m.update(b"="); - strip_basedirs_os(val, basedirs).hash(&mut HashToDigest { digest: &mut m }); + strip_basedirs_os(val, &basedirs).hash(&mut HashToDigest { digest: &mut m }); } // 9. The cwd of the compile. This will wind up in the rlib. - Path::new(&strip_basedirs_os(cwd.as_os_str(), basedirs)) + Path::new(&strip_basedirs_os(cwd.as_os_str(), &basedirs)) .hash(&mut HashToDigest { digest: &mut m }); // 10. The version of the compiler. self.version.hash(&mut HashToDigest { digest: &mut m }); diff --git a/src/config.rs b/src/config.rs index e4e4e4d896..89ae6413a1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2284,11 +2284,12 @@ fn test_compile_basedirs() { compile_basedirs(&env("SCCACHE_BASEDIRS", relative), &configured), configured.as_slice() ); - assert_eq!( - compile_basedirs(&env("sccache_basedirs", value), &configured).as_ref() - == expected.as_slice(), - cfg!(windows) - ); + + let lowercase = compile_basedirs(&env("sccache_basedirs", value), &configured); + #[cfg(windows)] + assert_eq!(lowercase, expected.as_slice()); + #[cfg(not(windows))] + assert_eq!(lowercase, configured.as_slice()); #[cfg(unix)] let invalid = {