Browse Source

Add custom flags after -Wall

Right now we add them before, and we add -Wall by default. This allows
users to manually turn off specific warnings, without having to resort
to a dance of:

```
 .warnings(false)
 .flag("-Wall")
 .flag("-Wno-foo")
```

This strikes a good balance of keeping -Wall on by default, while
minimising the surprising experience observed in
https://github.com/alexcrichton/cc-rs/issues/235.
cl-test
Daniel Wagner-Hall 8 years ago
parent
commit
2ba6e98f39
  1. 12
      src/lib.rs
  2. 10
      tests/support/mod.rs
  3. 13
      tests/test.rs

12
src/lib.rs

@ -1093,6 +1093,12 @@ impl Build {
cmd.args.push(directory.into());
}
if self.warnings {
for flag in cmd.family.warnings_flags().iter() {
cmd.args.push(flag.into());
}
}
for flag in self.flags.iter() {
cmd.args.push(flag.into());
}
@ -1112,12 +1118,6 @@ impl Build {
}
}
if self.warnings {
for flag in cmd.family.warnings_flags().iter() {
cmd.args.push(flag.into());
}
}
if self.warnings_into_errors {
cmd.args.push(cmd.family.warnings_to_errors_flag().into());
}

10
tests/support/mod.rs

@ -109,4 +109,14 @@ impl Execution {
pub fn has(&self, p: &OsStr) -> bool {
self.args.iter().any(|arg| OsStr::new(arg) == p)
}
pub fn must_have_in_order(&self, before: &str, after: &str) -> &Execution {
let before_position = self.args.iter().rposition(|x| OsStr::new(x) == OsStr::new(before));
let after_position = self.args.iter().rposition(|x| OsStr::new(x) == OsStr::new(after));
match (before_position, after_position) {
(Some(b), Some(a)) if b < a => {},
(b, a) => { panic!("{:?} (last position: {:?}) did not appear before {:?} (last position: {:?})", before, b, after, a) },
};
self
}
}

13
tests/test.rs

@ -77,6 +77,7 @@ fn gnu_warnings() {
let test = Test::gnu();
test.gcc()
.warnings(true)
.flag("-Wno-missing-field-initializers")
.file("foo.c")
.compile("foo");
@ -84,6 +85,18 @@ fn gnu_warnings() {
.must_have("-Wextra");
}
#[test]
fn gnu_warnings_overridable() {
let test = Test::gnu();
test.gcc()
.warnings(true)
.flag("-Wno-missing-field-initializers")
.file("foo.c")
.compile("foo");
test.cmd(0).must_have_in_order("-Wall", "-Wno-missing-field-initializers");
}
#[test]
fn gnu_x86_64() {
for vendor in &["unknown-linux-gnu", "apple-darwin"] {

Loading…
Cancel
Save