From 55210fe1bb61615fdc3aaede47dbe399ddc05794 Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Mon, 27 Aug 2018 14:31:41 -0400 Subject: [PATCH] Fix -showIncludes prefix detection for clang.exe on Windows. 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. --- src/compiler/compiler.rs | 1 + src/compiler/msvc.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 2b9db3688..13a7a7e1c 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -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| { diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 317ce36b6..6fbb9c083 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -95,6 +95,7 @@ fn from_local_codepage(bytes: &Vec) -> io::Result { /// Detect the prefix included in the output of MSVC's -showIncludes output. pub fn detect_showincludes_prefix(creator: &T, exe: &OsStr, + is_clang: bool, env: Vec<(OsString, OsString)>, pool: &CpuPool) -> SFuture @@ -119,6 +120,12 @@ pub fn detect_showincludes_prefix(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()) @@ -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]