Skip to content

Commit

Permalink
Fix: fix sccache bug for dwo file generate
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouronghua committed Oct 21, 2024
1 parent 29d17c7 commit ce57a02
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ where
};
if split_dwarf {
let dwo = output.with_extension("dwo");
common_args.push(OsString::from(
"-D_gsplit_dwarf_path=".to_owned() + dwo.to_str().unwrap(),
));
// -gsplit-dwarf doesn't guarantee .dwo file if no -g is specified
outputs.insert(
"dwo",
Expand Down Expand Up @@ -1075,6 +1078,9 @@ mod test {
CompilerArguments::Ok(args) => args,
o => panic!("Got unexpected parse result: {:?}", o),
};
let mut common_and_arch_args = common_args.clone();
common_and_arch_args.extend(common_args.to_vec());
debug!("common_and_arch_args: {:?}", common_and_arch_args);
assert_eq!(Some("foo.cpp"), input.to_str());
assert_eq!(Language::Cxx, language);
assert_map_contains!(
Expand All @@ -1095,7 +1101,10 @@ mod test {
)
);
assert!(preprocessor_args.is_empty());
assert_eq!(ovec!["-gsplit-dwarf"], common_args);
assert!(
common_args.contains(&"-gsplit-dwarf".into())
&& common_args.contains(&"-D_gsplit_dwarf_path=foo.dwo".into())
);
assert!(!msvc_show_includes);
}

Expand Down
72 changes: 72 additions & 0 deletions tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,77 @@ int main(int argc, char** argv) {
});
}

/* test case like this:
echo "int test(){}" > test.cc
mkdir o1 o2
sccache g++ -c -g -gsplit-dwarf test.cc -o test1.o
sccache g++ -c -g -gsplit-dwarf test.cc -o test1.o --- > cache hit
sccache g++ -c -g -gsplit-dwarf test.cc -o test2.o --- > cache miss
strings test2.o |grep test2.dwo
*/
fn test_split_dwarf_object_generate_output_dir_changes(compiler: Compiler, tempdir: &Path) {
let Compiler {
name,
exe,
env_vars,
} = compiler;
trace!("test -g -gsplit-dwarf with different output");
zero_stats();
const SRC: &str = "source.c";
write_source(
tempdir,
SRC,
"int test(){}",
);
let mut args = compile_cmdline(name, exe.clone(), SRC, "test1.o", Vec::new());
args.extend(vec_from!(OsString, "-g"));
args.extend(vec_from!(OsString, "-gsplit-dwarf"));
trace!("compile source.c (1)");
sccache_command()
.args(&args)
.current_dir(tempdir)
.envs(env_vars.clone())
.assert()
.success();
get_stats(|info| {
assert_eq!(0, info.stats.cache_hits.all());
assert_eq!(1, info.stats.cache_misses.all());
assert_eq!(&1, info.stats.cache_misses.get("C/C++").unwrap());
});
// Compile the same source again to ensure we can get a cache hit.
trace!("compile source.c (2)");
sccache_command()
.args(&args)
.current_dir(tempdir)
.envs(env_vars.clone())
.assert()
.success();
get_stats(|info| {
assert_eq!(1, info.stats.cache_hits.all());
assert_eq!(1, info.stats.cache_misses.all());
assert_eq!(&1, info.stats.cache_hits.get("C/C++").unwrap());
assert_eq!(&1, info.stats.cache_misses.get("C/C++").unwrap());
});
// Compile the same source again with different output
// to ensure we can force generate new object file.
let mut args2 = compile_cmdline(name, exe, SRC, "test2.o", Vec::new());
args2.extend(vec_from!(OsString, "-g"));
args2.extend(vec_from!(OsString, "-gsplit-dwarf"));
trace!("compile source.c (2)");
sccache_command()
.args(&args2)
.current_dir(tempdir)
.envs(env_vars.clone())
.assert()
.success();
get_stats(|info| {
assert_eq!(1, info.stats.cache_hits.all());
assert_eq!(2, info.stats.cache_misses.all());
assert_eq!(&1, info.stats.cache_hits.get("C/C++").unwrap());
assert_eq!(&2, info.stats.cache_misses.get("C/C++").unwrap());
});
}

fn test_gcc_clang_no_warnings_from_macro_expansion(compiler: Compiler, tempdir: &Path) {
let Compiler {
name,
Expand Down Expand Up @@ -505,6 +576,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);
}
if compiler.name == "clang++" {
test_clang_multicall(compiler.clone(), tempdir);
Expand Down

0 comments on commit ce57a02

Please sign in to comment.