Skip to content

Commit d37bd81

Browse files
committed
Filter out -v from compiler args when checking if a flag is supported.
1 parent 5b3949a commit d37bd81

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ pub struct Tool {
175175
env: Vec<(OsString, OsString)>,
176176
family: ToolFamily,
177177
cuda: bool,
178+
removed_args: Vec<OsString>,
178179
}
179180

180181
/// Represents the family of tools this tool belongs to.
@@ -259,6 +260,10 @@ impl ToolFamily {
259260
ToolFamily::Gnu | ToolFamily::Clang => "-Xcompiler",
260261
}
261262
}
263+
264+
fn verbose_stderr(&self) -> bool {
265+
*self == ToolFamily::Clang
266+
}
262267
}
263268

264269
/// Represents an object.
@@ -422,7 +427,14 @@ impl Build {
422427
.debug(false)
423428
.cpp(self.cpp)
424429
.cuda(self.cuda);
425-
let compiler = cfg.try_get_compiler()?;
430+
let mut compiler = cfg.try_get_compiler()?;
431+
432+
// Clang uses stderr for verbose output, which yields a false positive
433+
// result if the CFLAGS/CXXFLAGS include -v to aid in debugging.
434+
if compiler.family.verbose_stderr() {
435+
compiler.remove_arg("-v".into());
436+
}
437+
426438
let mut cmd = compiler.to_command();
427439
let is_arm = target.contains("aarch64") || target.contains("arm");
428440
command_add_output_file(&mut cmd, &obj, target.contains("msvc"), false, is_arm);
@@ -1960,9 +1972,15 @@ impl Tool {
19601972
env: Vec::new(),
19611973
family: family,
19621974
cuda: cuda,
1975+
removed_args: Vec::new(),
19631976
}
19641977
}
19651978

1979+
/// Add an argument to be stripped from the final command arguments.
1980+
fn remove_arg(&mut self, flag: OsString) {
1981+
self.removed_args.push(flag);
1982+
}
1983+
19661984
/// Add a flag, and optionally prepend the NVCC wrapper flag "-Xcompiler".
19671985
///
19681986
/// Currently this is only used for compiling CUDA sources, since NVCC only
@@ -1990,7 +2008,7 @@ impl Tool {
19902008
None => Command::new(&self.path),
19912009
};
19922010
cmd.args(&self.cc_wrapper_args);
1993-
cmd.args(&self.args);
2011+
cmd.args(self.args.iter().filter(|a| !self.removed_args.contains(a)));
19942012
for &(ref k, ref v) in self.env.iter() {
19952013
cmd.env(k, v);
19962014
}

tests/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,14 @@ fn gnu_flag_if_supported() {
230230
let test = Test::gnu();
231231
test.gcc()
232232
.file("foo.c")
233+
.flag("-v")
233234
.flag_if_supported("-Wall")
234235
.flag_if_supported("-Wflag-does-not-exist")
235236
.flag_if_supported("-std=c++11")
236237
.compile("foo");
237238

238239
test.cmd(0)
240+
.must_have("-v")
239241
.must_have("-Wall")
240242
.must_not_have("-Wflag-does-not-exist")
241243
.must_not_have("-std=c++11");

0 commit comments

Comments
 (0)