Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -795,7 +795,7 @@ pub fn run_command(cmd: Command) -> Result<i32> {
}
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();
Expand Down
61 changes: 61 additions & 0 deletions tests/sccache_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -77,3 +79,62 @@ 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<String> {
let entries_dir = cache_dir.join("preprocessor");
fs::create_dir_all(&entries_dir)?;
let entry = entries_dir.join("entry");
fs::write(&entry, b"")?;
let expected = format!("Showing preprocessor entry file {}", entry.display());
Ok(expected)
}

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(())
}
19 changes: 19 additions & 0 deletions tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,25 @@ 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");
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"))
.assert()
.success()
.stdout(predicate::str::contains(format!(
"Showing preprocessor entry file {}",
entries_dir.display()
)));
}
stop_local_daemon();
}
}
Expand Down
Loading