Skip to content

Commit

Permalink
Don't cache dep file
Browse files Browse the repository at this point in the history
sccache has two modes:
- normal mode
- preprocessor cache mode (aka direct mode in ccache)

In the former case, the preprocessor is invoked and creates the dep file
itself. Whatever sccache does after that is going to overwrite a fresh
file with potentially wrong information, since the cache key is not
indexed on the elements that would affect the contents of the dep file,
resulting in issue #2321.

In the latter case, sccache currently doesn't handle the situation
appropriately (issue #2194), which is why preprocessor cache mode is
automatically disabled when the dependency flags are on the command line
(#2195). Which also means we fallback to the case above.
  • Loading branch information
glandium committed Jan 28, 2025
1 parent de991d0 commit b4b5263
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 62 deletions.
49 changes: 1 addition & 48 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ where
let mut language_extensions = true; // by default, GCC allows extensions
let mut split_dwarf = false;
let mut need_explicit_dep_target = false;
let mut dep_path = None;
enum DepArgumentRequirePath {
NotNeeded,
Missing,
Expand Down Expand Up @@ -382,9 +381,8 @@ where
dep_flag = OsString::from(arg.flag_str().expect("Dep target flag expected"));
dep_target = Some(s.clone());
}
Some(DepArgumentPath(path)) => {
Some(DepArgumentPath(_)) => {
need_explicit_dep_argument_path = DepArgumentRequirePath::Provided;
dep_path = Some(path.clone());
}
Some(SerializeDiagnostics(path)) => {
serialize_diagnostics = Some(path.clone());
Expand Down Expand Up @@ -644,16 +642,6 @@ where
dependency_args.push(Path::new(&output).with_extension("d").into_os_string());
}

if let Some(path) = dep_path {
outputs.insert(
"d",
ArtifactDescriptor {
path: path.clone(),
optional: false,
},
);
}

if let Some(path) = serialize_diagnostics {
outputs.insert(
"dia",
Expand Down Expand Up @@ -1464,13 +1452,6 @@ mod test {
path: "foo.o".into(),
optional: false
}
),
(
"d",
ArtifactDescriptor {
path: "foo.o.d".into(),
optional: false
}
)
);
assert_eq!(ovec!["-MF", "foo.o.d"], dependency_args);
Expand Down Expand Up @@ -1564,13 +1545,6 @@ mod test {
path: "foo.o".into(),
optional: false
}
),
(
"d",
ArtifactDescriptor {
path: "foo.o.d".into(),
optional: false
}
)
);
assert_eq!(ovec!["-MF", "foo.o.d"], dependency_args);
Expand Down Expand Up @@ -1606,13 +1580,6 @@ mod test {
path: "foo.o".into(),
optional: false
}
),
(
"d",
ArtifactDescriptor {
path: "foo.o.d".into(),
optional: false
}
)
);
assert_eq!(
Expand Down Expand Up @@ -1652,13 +1619,6 @@ mod test {
path: "foo.o".into(),
optional: false
}
),
(
"d",
ArtifactDescriptor {
path: "foo.o.d".into(),
optional: false
}
)
);
assert_eq!(
Expand Down Expand Up @@ -1899,13 +1859,6 @@ mod test {
path: "foo.o".into(),
optional: false
}
),
(
"d",
ArtifactDescriptor {
path: "foo.o.d".into(),
optional: false
}
)
);
assert_eq!(
Expand Down
7 changes: 0 additions & 7 deletions src/compiler/nvcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1783,13 +1783,6 @@ mod test {
path: "foo.o".into(),
optional: false
}
),
(
"d",
ArtifactDescriptor {
path: "foo.o.d".into(),
optional: false
}
)
);
assert_eq!(
Expand Down
7 changes: 0 additions & 7 deletions src/compiler/nvhpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,6 @@ mod test {
path: "foo.o".into(),
optional: false
}
),
(
"d",
ArtifactDescriptor {
path: "foo.o.d".into(),
optional: false
}
)
);
assert_eq!(
Expand Down
51 changes: 51 additions & 0 deletions tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,56 @@ fn test_compile_with_define(compiler: Compiler, tempdir: &Path) {
.stderr(predicates::str::contains("warning:").from_utf8().not());
}

fn test_gcc_clang_depfile(compiler: Compiler, tempdir: &Path) {
let Compiler {
name,
exe,
env_vars,
} = compiler;
println!("test_gcc_clang_depfile: {}", name);
copy_to_tempdir(&[INPUT], tempdir);
fs::copy(tempdir.join(INPUT), tempdir.join("same-content.c")).unwrap();

trace!("compile");
sccache_command()
.args(compile_cmdline(
name,
exe.clone(),
INPUT,
OUTPUT,
Vec::new(),
))
.args(vec_from!(OsString, "-MD", "-MF", "first.d"))
.current_dir(tempdir)
.envs(env_vars.clone())
.assert()
.success();
sccache_command()
.args(compile_cmdline(
name,
exe,
"same-content.c",
"same-content.o",
Vec::new(),
))
.args(vec_from!(OsString, "-MD", "-MF", "second.d"))
.current_dir(tempdir)
.envs(env_vars)
.assert()
.success();
let mut first = String::new();
let mut second = String::new();
File::open(tempdir.join("first.d"))
.unwrap()
.read_to_string(&mut first)
.unwrap();
File::open(tempdir.join("second.d"))
.unwrap()
.read_to_string(&mut second)
.unwrap();
assert_ne!(first, second);
}

fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path, preprocessor_cache_mode: bool) {
if compiler.name != "clang++" {
test_basic_compile(compiler.clone(), tempdir);
Expand All @@ -589,6 +639,7 @@ fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path, preprocessor_ca
if compiler.name == "clang" || compiler.name == "gcc" {
test_gcc_clang_no_warnings_from_macro_expansion(compiler.clone(), tempdir);
test_split_dwarf_object_generate_output_dir_changes(compiler.clone(), tempdir);
test_gcc_clang_depfile(compiler.clone(), tempdir);
}
if compiler.name == "clang++" {
test_clang_multicall(compiler.clone(), tempdir);
Expand Down

0 comments on commit b4b5263

Please sign in to comment.