Skip to content

Commit 081d289

Browse files
zhouronghuatrxcllnt
authored andcommitted
Fix: fix sccache bug for dwo file generate (mozilla#2271)
1 parent 3701221 commit 081d289

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

src/compiler/gcc.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ where
607607
};
608608
if split_dwarf {
609609
let dwo = output.with_extension("dwo");
610+
common_args.push(OsString::from(
611+
"-D_gsplit_dwarf_path=".to_owned() + dwo.to_str().unwrap(),
612+
));
610613
// -gsplit-dwarf doesn't guarantee .dwo file if no -g is specified
611614
outputs.insert(
612615
"dwo",
@@ -1162,6 +1165,9 @@ mod test {
11621165
CompilerArguments::Ok(args) => args,
11631166
o => panic!("Got unexpected parse result: {:?}", o),
11641167
};
1168+
let mut common_and_arch_args = common_args.clone();
1169+
common_and_arch_args.extend(common_args.to_vec());
1170+
debug!("common_and_arch_args: {:?}", common_and_arch_args);
11651171
assert_eq!(Some("foo.cpp"), input.to_str());
11661172
assert_eq!(Language::Cxx, language);
11671173
assert_map_contains!(
@@ -1182,7 +1188,10 @@ mod test {
11821188
)
11831189
);
11841190
assert!(preprocessor_args.is_empty());
1185-
assert_eq!(ovec!["-gsplit-dwarf"], common_args);
1191+
assert!(
1192+
common_args.contains(&"-gsplit-dwarf".into())
1193+
&& common_args.contains(&"-D_gsplit_dwarf_path=foo.dwo".into())
1194+
);
11861195
assert!(!msvc_show_includes);
11871196
}
11881197

tests/system.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,73 @@ int main(int argc, char** argv) {
454454
});
455455
}
456456

457+
/* test case like this:
458+
echo "int test(){}" > test.cc
459+
mkdir o1 o2
460+
sccache g++ -c -g -gsplit-dwarf test.cc -o test1.o
461+
sccache g++ -c -g -gsplit-dwarf test.cc -o test1.o --- > cache hit
462+
sccache g++ -c -g -gsplit-dwarf test.cc -o test2.o --- > cache miss
463+
strings test2.o |grep test2.dwo
464+
*/
465+
fn test_split_dwarf_object_generate_output_dir_changes(compiler: Compiler, tempdir: &Path) {
466+
let Compiler {
467+
name,
468+
exe,
469+
env_vars,
470+
} = compiler;
471+
trace!("test -g -gsplit-dwarf with different output");
472+
zero_stats();
473+
const SRC: &str = "source.c";
474+
write_source(tempdir, SRC, "int test(){}");
475+
let mut args = compile_cmdline(name, exe.clone(), SRC, "test1.o", Vec::new());
476+
args.extend(vec_from!(OsString, "-g"));
477+
args.extend(vec_from!(OsString, "-gsplit-dwarf"));
478+
trace!("compile source.c (1)");
479+
sccache_command()
480+
.args(&args)
481+
.current_dir(tempdir)
482+
.envs(env_vars.clone())
483+
.assert()
484+
.success();
485+
get_stats(|info| {
486+
assert_eq!(0, info.stats.cache_hits.all());
487+
assert_eq!(1, info.stats.cache_misses.all());
488+
assert_eq!(&1, info.stats.cache_misses.get("C/C++").unwrap());
489+
});
490+
// Compile the same source again to ensure we can get a cache hit.
491+
trace!("compile source.c (2)");
492+
sccache_command()
493+
.args(&args)
494+
.current_dir(tempdir)
495+
.envs(env_vars.clone())
496+
.assert()
497+
.success();
498+
get_stats(|info| {
499+
assert_eq!(1, info.stats.cache_hits.all());
500+
assert_eq!(1, info.stats.cache_misses.all());
501+
assert_eq!(&1, info.stats.cache_hits.get("C/C++").unwrap());
502+
assert_eq!(&1, info.stats.cache_misses.get("C/C++").unwrap());
503+
});
504+
// Compile the same source again with different output
505+
// to ensure we can force generate new object file.
506+
let mut args2 = compile_cmdline(name, exe, SRC, "test2.o", Vec::new());
507+
args2.extend(vec_from!(OsString, "-g"));
508+
args2.extend(vec_from!(OsString, "-gsplit-dwarf"));
509+
trace!("compile source.c (2)");
510+
sccache_command()
511+
.args(&args2)
512+
.current_dir(tempdir)
513+
.envs(env_vars.clone())
514+
.assert()
515+
.success();
516+
get_stats(|info| {
517+
assert_eq!(1, info.stats.cache_hits.all());
518+
assert_eq!(2, info.stats.cache_misses.all());
519+
assert_eq!(&1, info.stats.cache_hits.get("C/C++").unwrap());
520+
assert_eq!(&2, info.stats.cache_misses.get("C/C++").unwrap());
521+
});
522+
}
523+
457524
fn test_gcc_clang_no_warnings_from_macro_expansion(compiler: Compiler, tempdir: &Path) {
458525
let Compiler {
459526
name,
@@ -521,6 +588,7 @@ fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path, preprocessor_ca
521588
}
522589
if compiler.name == "clang" || compiler.name == "gcc" {
523590
test_gcc_clang_no_warnings_from_macro_expansion(compiler.clone(), tempdir);
591+
test_split_dwarf_object_generate_output_dir_changes(compiler.clone(), tempdir);
524592
}
525593
if compiler.name == "clang++" {
526594
test_clang_multicall(compiler.clone(), tempdir);

0 commit comments

Comments
 (0)