Skip to content

Commit 28f5e34

Browse files
authored
Merge pull request #333 from jdm/filter-supported
Filter out -v from compiler args when checking if a flag is supported.
2 parents 5b3949a + 12816c8 commit 28f5e34

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: false
33

44
matrix:
55
include:
6-
- rust: 1.13.0
6+
- rust: 1.16.0
77
install:
88
script: cargo build
99
- rust: stable

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)