Browse Source

Filter out -v from compiler args when checking if a flag is supported.

wintest
Josh Matthews 7 years ago
parent
commit
d37bd811a2
  1. 22
      src/lib.rs
  2. 2
      tests/test.rs

22
src/lib.rs

@ -175,6 +175,7 @@ pub struct Tool {
env: Vec<(OsString, OsString)>, env: Vec<(OsString, OsString)>,
family: ToolFamily, family: ToolFamily,
cuda: bool, cuda: bool,
removed_args: Vec<OsString>,
} }
/// Represents the family of tools this tool belongs to. /// Represents the family of tools this tool belongs to.
@ -259,6 +260,10 @@ impl ToolFamily {
ToolFamily::Gnu | ToolFamily::Clang => "-Xcompiler", ToolFamily::Gnu | ToolFamily::Clang => "-Xcompiler",
} }
} }
fn verbose_stderr(&self) -> bool {
*self == ToolFamily::Clang
}
} }
/// Represents an object. /// Represents an object.
@ -422,7 +427,14 @@ impl Build {
.debug(false) .debug(false)
.cpp(self.cpp) .cpp(self.cpp)
.cuda(self.cuda); .cuda(self.cuda);
let compiler = cfg.try_get_compiler()?; let mut compiler = cfg.try_get_compiler()?;
// Clang uses stderr for verbose output, which yields a false positive
// result if the CFLAGS/CXXFLAGS include -v to aid in debugging.
if compiler.family.verbose_stderr() {
compiler.remove_arg("-v".into());
}
let mut cmd = compiler.to_command(); let mut cmd = compiler.to_command();
let is_arm = target.contains("aarch64") || target.contains("arm"); let is_arm = target.contains("aarch64") || target.contains("arm");
command_add_output_file(&mut cmd, &obj, target.contains("msvc"), false, is_arm); command_add_output_file(&mut cmd, &obj, target.contains("msvc"), false, is_arm);
@ -1960,9 +1972,15 @@ impl Tool {
env: Vec::new(), env: Vec::new(),
family: family, family: family,
cuda: cuda, cuda: cuda,
removed_args: Vec::new(),
} }
} }
/// Add an argument to be stripped from the final command arguments.
fn remove_arg(&mut self, flag: OsString) {
self.removed_args.push(flag);
}
/// Add a flag, and optionally prepend the NVCC wrapper flag "-Xcompiler". /// Add a flag, and optionally prepend the NVCC wrapper flag "-Xcompiler".
/// ///
/// Currently this is only used for compiling CUDA sources, since NVCC only /// Currently this is only used for compiling CUDA sources, since NVCC only
@ -1990,7 +2008,7 @@ impl Tool {
None => Command::new(&self.path), None => Command::new(&self.path),
}; };
cmd.args(&self.cc_wrapper_args); cmd.args(&self.cc_wrapper_args);
cmd.args(&self.args); cmd.args(self.args.iter().filter(|a| !self.removed_args.contains(a)));
for &(ref k, ref v) in self.env.iter() { for &(ref k, ref v) in self.env.iter() {
cmd.env(k, v); cmd.env(k, v);
} }

2
tests/test.rs

@ -230,12 +230,14 @@ fn gnu_flag_if_supported() {
let test = Test::gnu(); let test = Test::gnu();
test.gcc() test.gcc()
.file("foo.c") .file("foo.c")
.flag("-v")
.flag_if_supported("-Wall") .flag_if_supported("-Wall")
.flag_if_supported("-Wflag-does-not-exist") .flag_if_supported("-Wflag-does-not-exist")
.flag_if_supported("-std=c++11") .flag_if_supported("-std=c++11")
.compile("foo"); .compile("foo");
test.cmd(0) test.cmd(0)
.must_have("-v")
.must_have("-Wall") .must_have("-Wall")
.must_not_have("-Wflag-does-not-exist") .must_not_have("-Wflag-does-not-exist")
.must_not_have("-std=c++11"); .must_not_have("-std=c++11");

Loading…
Cancel
Save