Skip to content

Commit

Permalink
Fix -showIncludes prefix detection for clang.exe on Windows.
Browse files Browse the repository at this point in the history
clang.exe reports the same set of built-in preprocessor defines as clang-cl.exe,
but it doesn't accept MSVC commandline options unless you pass --driver-mode=cl.
This breaks sccache's test for the -showIncludes prefix. We fix this by always
passing --driver-mode=cl for this test when we detect clang or clang-cl.
  • Loading branch information
luser committed Aug 27, 2018
1 parent d502791 commit 55210fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ gcc
debug!("Found MSVC (is clang: {})", is_clang);
let prefix = msvc::detect_showincludes_prefix(&creator,
executable.as_ref(),
is_clang,
env,
&pool);
return Box::new(prefix.and_then(move |prefix| {
Expand Down
10 changes: 9 additions & 1 deletion src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn from_local_codepage(bytes: &Vec<u8>) -> io::Result<String> {
/// Detect the prefix included in the output of MSVC's -showIncludes output.
pub fn detect_showincludes_prefix<T>(creator: &T,
exe: &OsStr,
is_clang: bool,
env: Vec<(OsString, OsString)>,
pool: &CpuPool)
-> SFuture<String>
Expand All @@ -119,6 +120,12 @@ pub fn detect_showincludes_prefix<T>(creator: &T,
});
let output = write2.and_then(move |(tempdir, input)| {
let mut cmd = creator.new_command_sync(&exe);
// clang.exe on Windows reports the same set of built-in preprocessor defines as clang-cl,
// but it doesn't accept MSVC commandline arguments unless you pass --driver-mode=cl.
// clang-cl.exe will accept this argument as well, so always add it in this case.
if is_clang {
cmd.arg("--driver-mode=cl");
}
cmd.args(&["-nologo", "-showIncludes", "-c", "-Fonul", "-I."])
.arg(&input)
.current_dir(&tempdir.path())
Expand Down Expand Up @@ -625,7 +632,8 @@ mod test {
let stdout = format!("blah: {}\r\n", s);
let stderr = String::from("some\r\nstderr\r\n");
next_command(&creator, Ok(MockChild::new(exit_status(0), &stdout, &stderr)));
assert_eq!("blah: ", detect_showincludes_prefix(&creator, "cl.exe".as_ref(), Vec::new(), &pool).wait().unwrap());
assert_eq!("blah: ", detect_showincludes_prefix(&creator, "cl.exe".as_ref(), false,
Vec::new(), &pool).wait().unwrap());
}

#[test]
Expand Down

0 comments on commit 55210fe

Please sign in to comment.