Skip to content

Commit edde193

Browse files
Audran DoubletAJIOB
authored andcommitted
msvc: fix detect_showincludes_prefix with MSBuild
The problem usually occurs when VS_UNICODE_OUTPUT is set. This is a @AudranDoublet #1835 and @exoosh #2483 fixes with working tests: thank you! Should fix issues #1830 and #909
1 parent 98fbe0d commit edde193

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/compiler/compiler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ mod test {
19551955
s = &s[4..];
19561956
}
19571957
let prefix = String::from("blah: ");
1958-
let stdout = format!("{}{}\r\n", prefix, s);
1958+
let stderr = format!("{}{}\r\n", prefix, s);
19591959
// Compiler detection output
19601960
next_command(
19611961
&creator,
@@ -1972,7 +1972,7 @@ mod test {
19721972
// showincludes prefix detection output
19731973
next_command(
19741974
&creator,
1975-
Ok(MockChild::new(exit_status(0), stdout, String::new())),
1975+
Ok(MockChild::new(exit_status(0), String::new(), stderr)),
19761976
);
19771977
let c = detect_compiler(creator, &f.bins[0], f.tempdir.path(), &[], &[], pool, None)
19781978
.wait()

src/compiler/msvc.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::collections::{HashMap, HashSet};
2929
use std::ffi::{OsStr, OsString};
3030
use std::io::{self, BufWriter, Read, Write};
3131
use std::path::{Path, PathBuf};
32-
use std::process::{self, Stdio};
32+
use std::process;
3333

3434
use crate::errors::*;
3535

@@ -201,13 +201,9 @@ where
201201
if is_clang {
202202
cmd.arg("--driver-mode=cl");
203203
}
204-
cmd.args(&["-nologo", "-showIncludes", "-c", "-Fonul", "-I."])
204+
cmd.args(&["-nologo", "-showIncludes", "-c", "-Fonul", "-I.", "-E"])
205205
.arg(&input)
206-
.current_dir(tempdir.path())
207-
// The MSDN docs say the -showIncludes output goes to stderr,
208-
// but that's not true unless running with -E.
209-
.stdout(Stdio::piped())
210-
.stderr(Stdio::null());
206+
.current_dir(tempdir.path());
211207
for (k, v) in env {
212208
cmd.env(k, v);
213209
}
@@ -216,16 +212,20 @@ where
216212
let output = run_input_output(cmd, None).await?;
217213

218214
if !output.status.success() {
219-
bail!("Failed to detect showIncludes prefix")
215+
warn!(
216+
"Failed to detect showIncludes prefix (status: {:?})",
217+
output.status.code().unwrap_or(-1)
218+
)
220219
}
221220

222221
let process::Output {
223-
stdout: stdout_bytes,
222+
stderr: stderr_bytes,
224223
..
225224
} = output;
226-
let stdout = from_local_codepage(&stdout_bytes)
227-
.context("Failed to convert compiler stdout while detecting showIncludes prefix")?;
228-
for line in stdout.lines() {
225+
let output = from_local_codepage(&stderr_bytes)
226+
.context("Failed to convert compiler stderr while detecting showIncludes prefix")?;
227+
228+
for line in output.lines() {
229229
if !line.ends_with("test.h") {
230230
continue;
231231
}
@@ -246,7 +246,7 @@ where
246246

247247
debug!(
248248
"failed to detect showIncludes prefix with output: {}",
249-
stdout
249+
output
250250
);
251251

252252
bail!("Failed to detect showIncludes prefix")
@@ -1416,8 +1416,8 @@ mod test {
14161416
if s.starts_with("\\\\?\\") {
14171417
s = &s[4..];
14181418
}
1419-
let stdout = format!("blah: {}\r\n", s);
1420-
let stderr = String::from("some\r\nstderr\r\n");
1419+
let stderr = format!("blah: {}\r\n", s);
1420+
let stdout = String::from("some\r\nstdout\r\n");
14211421
next_command(&creator, Ok(MockChild::new(exit_status(0), stdout, stderr)));
14221422
assert_eq!(
14231423
"blah: ",

0 commit comments

Comments
 (0)