about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-03-19 11:46:56 -0400
committerCorey Farwell <coreyf@rwell.org>2017-04-09 13:59:09 -0400
commitf789d896cbb8b5622d07cf45261b11ebfee73e37 (patch)
tree5c2a420cbba9f69d08aa53559b027d2fe7fdc229 /src
parentbd698b9e8b02e27409123e71c0594523b926b850 (diff)
downloadrust-f789d896cbb8b5622d07cf45261b11ebfee73e37.tar.gz
rust-f789d896cbb8b5622d07cf45261b11ebfee73e37.zip
Print tidy errors to stderr, prefix with 'tidy error: ', handle 'bad' state.
Diffstat (limited to 'src')
-rw-r--r--src/tools/tidy/src/bins.rs3
-rw-r--r--src/tools/tidy/src/cargo.rs5
-rw-r--r--src/tools/tidy/src/errors.rs5
-rw-r--r--src/tools/tidy/src/features.rs9
-rw-r--r--src/tools/tidy/src/main.rs9
-rw-r--r--src/tools/tidy/src/pal.rs3
-rw-r--r--src/tools/tidy/src/style.rs6
-rw-r--r--src/tools/tidy/src/unstable_book.rs31
8 files changed, 34 insertions, 37 deletions
diff --git a/src/tools/tidy/src/bins.rs b/src/tools/tidy/src/bins.rs
index ef93b0858b0..11d5dbe736e 100644
--- a/src/tools/tidy/src/bins.rs
+++ b/src/tools/tidy/src/bins.rs
@@ -62,8 +62,7 @@ pub fn check(path: &Path, bad: &mut bool) {
                 });
             let path_bytes = rel_path.as_os_str().as_bytes();
             if output.status.success() && output.stdout.starts_with(path_bytes) {
-                println!("binary checked into source: {}", file.display());
-                *bad = true;
+                tidy_error!(bad, "binary checked into source: {}", file.display());
             }
         }
     })
diff --git a/src/tools/tidy/src/cargo.rs b/src/tools/tidy/src/cargo.rs
index 053f0bbe3b8..c8c6cb0ee6b 100644
--- a/src/tools/tidy/src/cargo.rs
+++ b/src/tools/tidy/src/cargo.rs
@@ -100,9 +100,8 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
         }
 
         if !librs.contains(&format!("extern crate {}", krate)) {
-            println!("{} doesn't have `extern crate {}`, but Cargo.toml \
-                      depends on it", libfile.display(), krate);
-            *bad = true;
+            tidy_error!(bad, "{} doesn't have `extern crate {}`, but Cargo.toml \
+                              depends on it", libfile.display(), krate);
         }
     }
 }
diff --git a/src/tools/tidy/src/errors.rs b/src/tools/tidy/src/errors.rs
index 3a70e54ff97..5bf7c894cda 100644
--- a/src/tools/tidy/src/errors.rs
+++ b/src/tools/tidy/src/errors.rs
@@ -79,11 +79,10 @@ pub fn check(path: &Path, bad: &mut bool) {
             continue
         }
 
-        println!("duplicate error code: {}", code);
+        tidy_error!(bad, "duplicate error code: {}", code);
         for &(ref file, line_num, ref line) in entries.iter() {
-            println!("{}:{}: {}", file.display(), line_num, line);
+            tidy_error!(bad, "{}:{}: {}", file.display(), line_num, line);
         }
-        *bad = true;
     }
 
     if !*bad {
diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs
index e1fdc19c27d..ad0d2fa0b36 100644
--- a/src/tools/tidy/src/features.rs
+++ b/src/tools/tidy/src/features.rs
@@ -77,8 +77,7 @@ pub fn check(path: &Path, bad: &mut bool) {
 
         for (i, line) in contents.lines().enumerate() {
             let mut err = |msg: &str| {
-                println!("{}:{}: {}", file.display(), i + 1, msg);
-                *bad = true;
+                tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
             };
 
             let gate_test_str = "gate-test-";
@@ -126,8 +125,7 @@ pub fn check(path: &Path, bad: &mut bool) {
     }
 
     if gate_untested.len() > 0 {
-        println!("Found {} features without a gate test.", gate_untested.len());
-        *bad = true;
+        tidy_error!(bad, "Found {} features without a gate test.", gate_untested.len());
     }
 
     if *bad {
@@ -221,8 +219,7 @@ pub fn collect_lib_features(base_src_path: &Path,
 
         for (i, line) in contents.lines().enumerate() {
             let mut err = |msg: &str| {
-                println!("{}:{}: {}", file.display(), i + 1, msg);
-                *bad = true;
+                tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
             };
             let level = if line.contains("[unstable(") {
                 Status::Unstable
diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
index d0e8cf9c343..dee37341051 100644
--- a/src/tools/tidy/src/main.rs
+++ b/src/tools/tidy/src/main.rs
@@ -34,6 +34,15 @@ macro_rules! t {
     })
 }
 
+macro_rules! tidy_error {
+    ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
+        use std::io::Write;
+        *$bad = true;
+        write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr");
+        writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr");
+    });
+}
+
 mod bins;
 mod style;
 mod errors;
diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs
index 3808c05c6b9..cb323bd1d28 100644
--- a/src/tools/tidy/src/pal.rs
+++ b/src/tools/tidy/src/pal.rs
@@ -126,8 +126,7 @@ fn check_cfgs(contents: &mut String, file: &Path,
             Ok(_) => unreachable!(),
             Err(i) => i + 1
         };
-        println!("{}:{}: platform-specific cfg: {}", file.display(), line, cfg);
-        *bad = true;
+        tidy_error!(bad, "{}:{}: platform-specific cfg: {}", file.display(), line, cfg);
     };
 
     for (idx, cfg) in cfgs.into_iter() {
diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs
index 2233f8c3529..081390eb93c 100644
--- a/src/tools/tidy/src/style.rs
+++ b/src/tools/tidy/src/style.rs
@@ -112,8 +112,7 @@ pub fn check(path: &Path, bad: &mut bool) {
         let skip_length = contents.contains("ignore-tidy-linelength");
         for (i, line) in contents.split("\n").enumerate() {
             let mut err = |msg: &str| {
-                println!("{}:{}: {}", file.display(), i + 1, msg);
-                *bad = true;
+                tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
             };
             if !skip_length && line.chars().count() > COLS
                 && !long_line_is_ok(line) {
@@ -138,8 +137,7 @@ pub fn check(path: &Path, bad: &mut bool) {
             }
         }
         if !licenseck(file, &contents) {
-            println!("{}: incorrect license", file.display());
-            *bad = true;
+            tidy_error!(bad, "{}: incorrect license", file.display());
         }
     })
 }
diff --git a/src/tools/tidy/src/unstable_book.rs b/src/tools/tidy/src/unstable_book.rs
index c10e3107794..2d3d9e80257 100644
--- a/src/tools/tidy/src/unstable_book.rs
+++ b/src/tools/tidy/src/unstable_book.rs
@@ -10,7 +10,7 @@
 
 use std::collections::HashSet;
 use std::fs;
-use std::io::{self, BufRead, Write};
+use std::io::{self, BufRead};
 use std::path;
 use features::{collect_lang_features, collect_lib_features, Status};
 
@@ -110,29 +110,26 @@ pub fn check(path: &path::Path, bad: &mut bool) {
 
     // Check for Unstable Book section names with no corresponding SUMMARY.md link
     for feature_name in &unstable_book_section_file_names - &unstable_book_links {
-        *bad = true;
-        writeln!(io::stderr(),
-                 "The Unstable Book section '{}' needs to have a link in SUMMARY.md",
-                 feature_name)
-                .expect("could not write to stderr")
+        tidy_error!(
+            bad,
+            "The Unstable Book section '{}' needs to have a link in SUMMARY.md",
+            feature_name);
     }
 
     // Check for unstable features that don't have Unstable Book sections
     for feature_name in &unstable_feature_names - &unstable_book_section_file_names {
-        *bad = true;
-        writeln!(io::stderr(),
-                 "Unstable feature '{}' needs to have a section in The Unstable Book",
-                 feature_name)
-                .expect("could not write to stderr")
+        tidy_error!(
+            bad,
+            "Unstable feature '{}' needs to have a section in The Unstable Book",
+            feature_name);
     }
 
     // Check for Unstable Book sections that don't have a corresponding unstable feature
     for feature_name in &unstable_book_section_file_names - &unstable_feature_names {
-        *bad = true;
-        writeln!(io::stderr(),
-                 "The Unstable Book has a section '{}' which doesn't correspond \
-                  to an unstable feature",
-                 feature_name)
-                .expect("could not write to stderr")
+        tidy_error!(
+            bad,
+            "The Unstable Book has a section '{}' which doesn't correspond \
+            to an unstable feature",
+            feature_name)
     }
 }