Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple minor improvements for tidy error handling. #40653

Merged
merged 2 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/tools/tidy/src/bins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
})
Expand Down
5 changes: 2 additions & 3 deletions src/tools/tidy/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
5 changes: 2 additions & 3 deletions src/tools/tidy/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions src/tools/tidy/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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-";
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

extern crate regex;

use std::env;
use std::fs;
use std::io::{self, Write};
use std::path::{PathBuf, Path};
use std::env;
use std::process;

macro_rules! t {
($e:expr, $p:expr) => (match $e {
Expand All @@ -32,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;
Expand Down Expand Up @@ -60,7 +71,8 @@ fn main() {
}

if bad {
panic!("some tidy checks failed");
writeln!(io::stderr(), "some tidy checks failed").expect("could not write to stderr");
process::exit(1);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/tools/tidy/src/pal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 2 additions & 4 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
}
})
}
Expand Down
31 changes: 14 additions & 17 deletions src/tools/tidy/src/unstable_book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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)
}
}