Skip to content
Merged
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
37 changes: 37 additions & 0 deletions src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,13 @@ pub fn parse_arguments(
if debug_info && !is_clang {
match pdb {
Some(p) => {
// A trailing separator makes cl.exe write a shared vc<NNN>.pdb
// inside that directory, like the -Fd-less case below, so the
// program database cannot be tracked as a per-compilation
// artifact.
if p.as_os_str().to_string_lossy().ends_with(['\\', '/']) {
cannot_cache!("shared pdb");
}
// Append the default .pdb prefix if none was given, like how MSVC does.
let path = if p.extension().is_none() {
let mut path = p;
Expand Down Expand Up @@ -3419,6 +3426,36 @@ mod test {
);
}

#[test]
fn test_parse_arguments_pdb_directory() {
// A trailing separator makes cl.exe write a shared vc<NNN>.pdb in that
// directory, which cannot be cached as part of this compilation.
for args in [
ovec!["-c", "foo.c", "-Zi", "-Fdpdb\\", "-Fofoo.obj"],
ovec!["-c", "foo.c", "-Zi", "-Fdpdb/", "-Fofoo.obj"],
] {
assert_eq!(
CompilerArguments::CannotCache("shared pdb", None),
parse_arguments(args)
);
}

// Without debug information cl.exe ignores -Fd entirely.
let a = match parse_arguments(ovec!["-c", "foo.c", "-Fdpdb\\", "-Fofoo.obj"]) {
CompilerArguments::Ok(a) => a,
o => panic!("Got unexpected parse result: {:?}", o),
};
assert!(!a.outputs.contains_key("pdb"));

// An explicit file name is a per-compilation artifact and can be cached.
let a = match parse_arguments(ovec!["-c", "foo.c", "-Zi", "-Fdpdb\\foo.pdb", "-Fofoo.obj"])
{
CompilerArguments::Ok(a) => a,
o => panic!("Got unexpected parse result: {:?}", o),
};
assert_eq!(Path::new("pdb\\foo.pdb"), a.outputs["pdb"].path);
}

#[test]
fn test_preprocess_double_dash_input() {
let args = ovec!["-c", "-Fofoo.o.bj", "--", "foo.c"];
Expand Down
Loading