Skip to content

Commit c0a0b6e

Browse files
authored
Don't cache dep file (#2322)
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.
1 parent 6362a7a commit c0a0b6e

File tree

4 files changed

+52
-62
lines changed

4 files changed

+52
-62
lines changed

src/compiler/gcc.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ where
290290
let mut language_extensions = true; // by default, GCC allows extensions
291291
let mut split_dwarf = false;
292292
let mut need_explicit_dep_target = false;
293-
let mut dep_path = None;
294293
enum DepArgumentRequirePath {
295294
NotNeeded,
296295
Missing,
@@ -382,9 +381,8 @@ where
382381
dep_flag = OsString::from(arg.flag_str().expect("Dep target flag expected"));
383382
dep_target = Some(s.clone());
384383
}
385-
Some(DepArgumentPath(path)) => {
384+
Some(DepArgumentPath(_)) => {
386385
need_explicit_dep_argument_path = DepArgumentRequirePath::Provided;
387-
dep_path = Some(path.clone());
388386
}
389387
Some(SerializeDiagnostics(path)) => {
390388
serialize_diagnostics = Some(path.clone());
@@ -644,16 +642,6 @@ where
644642
dependency_args.push(Path::new(&output).with_extension("d").into_os_string());
645643
}
646644

647-
if let Some(path) = dep_path {
648-
outputs.insert(
649-
"d",
650-
ArtifactDescriptor {
651-
path: path.clone(),
652-
optional: false,
653-
},
654-
);
655-
}
656-
657645
if let Some(path) = serialize_diagnostics {
658646
outputs.insert(
659647
"dia",
@@ -1464,13 +1452,6 @@ mod test {
14641452
path: "foo.o".into(),
14651453
optional: false
14661454
}
1467-
),
1468-
(
1469-
"d",
1470-
ArtifactDescriptor {
1471-
path: "foo.o.d".into(),
1472-
optional: false
1473-
}
14741455
)
14751456
);
14761457
assert_eq!(ovec!["-MF", "foo.o.d"], dependency_args);
@@ -1564,13 +1545,6 @@ mod test {
15641545
path: "foo.o".into(),
15651546
optional: false
15661547
}
1567-
),
1568-
(
1569-
"d",
1570-
ArtifactDescriptor {
1571-
path: "foo.o.d".into(),
1572-
optional: false
1573-
}
15741548
)
15751549
);
15761550
assert_eq!(ovec!["-MF", "foo.o.d"], dependency_args);
@@ -1606,13 +1580,6 @@ mod test {
16061580
path: "foo.o".into(),
16071581
optional: false
16081582
}
1609-
),
1610-
(
1611-
"d",
1612-
ArtifactDescriptor {
1613-
path: "foo.o.d".into(),
1614-
optional: false
1615-
}
16161583
)
16171584
);
16181585
assert_eq!(
@@ -1652,13 +1619,6 @@ mod test {
16521619
path: "foo.o".into(),
16531620
optional: false
16541621
}
1655-
),
1656-
(
1657-
"d",
1658-
ArtifactDescriptor {
1659-
path: "foo.o.d".into(),
1660-
optional: false
1661-
}
16621622
)
16631623
);
16641624
assert_eq!(
@@ -1899,13 +1859,6 @@ mod test {
18991859
path: "foo.o".into(),
19001860
optional: false
19011861
}
1902-
),
1903-
(
1904-
"d",
1905-
ArtifactDescriptor {
1906-
path: "foo.o.d".into(),
1907-
optional: false
1908-
}
19091862
)
19101863
);
19111864
assert_eq!(

src/compiler/nvcc.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,13 +1783,6 @@ mod test {
17831783
path: "foo.o".into(),
17841784
optional: false
17851785
}
1786-
),
1787-
(
1788-
"d",
1789-
ArtifactDescriptor {
1790-
path: "foo.o.d".into(),
1791-
optional: false
1792-
}
17931786
)
17941787
);
17951788
assert_eq!(

src/compiler/nvhpc.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,6 @@ mod test {
352352
path: "foo.o".into(),
353353
optional: false
354354
}
355-
),
356-
(
357-
"d",
358-
ArtifactDescriptor {
359-
path: "foo.o.d".into(),
360-
optional: false
361-
}
362355
)
363356
);
364357
assert_eq!(

tests/system.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,56 @@ fn test_compile_with_define(compiler: Compiler, tempdir: &Path) {
573573
.stderr(predicates::str::contains("warning:").from_utf8().not());
574574
}
575575

576+
fn test_gcc_clang_depfile(compiler: Compiler, tempdir: &Path) {
577+
let Compiler {
578+
name,
579+
exe,
580+
env_vars,
581+
} = compiler;
582+
println!("test_gcc_clang_depfile: {}", name);
583+
copy_to_tempdir(&[INPUT], tempdir);
584+
fs::copy(tempdir.join(INPUT), tempdir.join("same-content.c")).unwrap();
585+
586+
trace!("compile");
587+
sccache_command()
588+
.args(compile_cmdline(
589+
name,
590+
exe.clone(),
591+
INPUT,
592+
OUTPUT,
593+
Vec::new(),
594+
))
595+
.args(vec_from!(OsString, "-MD", "-MF", "first.d"))
596+
.current_dir(tempdir)
597+
.envs(env_vars.clone())
598+
.assert()
599+
.success();
600+
sccache_command()
601+
.args(compile_cmdline(
602+
name,
603+
exe,
604+
"same-content.c",
605+
"same-content.o",
606+
Vec::new(),
607+
))
608+
.args(vec_from!(OsString, "-MD", "-MF", "second.d"))
609+
.current_dir(tempdir)
610+
.envs(env_vars)
611+
.assert()
612+
.success();
613+
let mut first = String::new();
614+
let mut second = String::new();
615+
File::open(tempdir.join("first.d"))
616+
.unwrap()
617+
.read_to_string(&mut first)
618+
.unwrap();
619+
File::open(tempdir.join("second.d"))
620+
.unwrap()
621+
.read_to_string(&mut second)
622+
.unwrap();
623+
assert_ne!(first, second);
624+
}
625+
576626
fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path, preprocessor_cache_mode: bool) {
577627
if compiler.name != "clang++" {
578628
test_basic_compile(compiler.clone(), tempdir);
@@ -589,6 +639,7 @@ fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path, preprocessor_ca
589639
if compiler.name == "clang" || compiler.name == "gcc" {
590640
test_gcc_clang_no_warnings_from_macro_expansion(compiler.clone(), tempdir);
591641
test_split_dwarf_object_generate_output_dir_changes(compiler.clone(), tempdir);
642+
test_gcc_clang_depfile(compiler.clone(), tempdir);
592643
}
593644
if compiler.name == "clang++" {
594645
test_clang_multicall(compiler.clone(), tempdir);

0 commit comments

Comments
 (0)