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

Replace some println! with tidy_error! to simplify #80025

Merged
merged 1 commit into from
Dec 15, 2020
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
29 changes: 13 additions & 16 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
for (name, license) in EXCEPTIONS {
// Check that the package actually exists.
if !metadata.packages.iter().any(|p| p.name == *name) {
println!(
tidy_error!(
bad,
"could not find exception package `{}`\n\
Remove from EXCEPTIONS list if it is no longer used.",
name
);
*bad = true;
}
// Check that the license hasn't changed.
for pkg in metadata.packages.iter().filter(|p| p.name == *name) {
Expand All @@ -232,11 +232,11 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
}
match &pkg.license {
None => {
println!(
tidy_error!(
bad,
"dependency exception `{}` does not declare a license expression",
pkg.id
);
*bad = true;
}
Some(pkg_license) => {
if pkg_license.as_str() != *license {
Expand Down Expand Up @@ -273,8 +273,7 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
let license = match &pkg.license {
Some(license) => license,
None => {
println!("dependency `{}` does not define a license expression", pkg.id,);
*bad = true;
tidy_error!(bad, "dependency `{}` does not define a license expression", pkg.id);
continue;
}
};
Expand All @@ -286,8 +285,7 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
// general, these should never be added.
continue;
}
println!("invalid license `{}` in `{}`", license, pkg.id);
*bad = true;
tidy_error!(bad, "invalid license `{}` in `{}`", license, pkg.id);
}
}
}
Expand All @@ -300,12 +298,12 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
// Check that the PERMITTED_DEPENDENCIES does not have unused entries.
for name in PERMITTED_DEPENDENCIES {
if !metadata.packages.iter().any(|p| p.name == *name) {
println!(
tidy_error!(
bad,
"could not find allowed package `{}`\n\
Remove from PERMITTED_DEPENDENCIES list if it is no longer used.",
name
);
*bad = true;
}
}
// Get the list in a convenient form.
Expand All @@ -322,11 +320,10 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
}

if !unapproved.is_empty() {
println!("Dependencies not explicitly permitted:");
tidy_error!(bad, "Dependencies not explicitly permitted:");
for dep in unapproved {
println!("* {}", dep);
}
*bad = true;
}
}

Expand Down Expand Up @@ -381,16 +378,17 @@ fn check_crate_duplicate(metadata: &Metadata, bad: &mut bool) {
let matches: Vec<_> = metadata.packages.iter().filter(|pkg| pkg.name == name).collect();
match matches.len() {
0 => {
println!(
tidy_error!(
bad,
"crate `{}` is missing, update `check_crate_duplicate` \
if it is no longer used",
name
);
*bad = true;
}
1 => {}
_ => {
println!(
tidy_error!(
bad,
"crate `{}` is duplicated in `Cargo.lock`, \
it is too expensive to build multiple times, \
so make sure only one version appears across all dependencies",
Expand All @@ -399,7 +397,6 @@ fn check_crate_duplicate(metadata: &Metadata, bad: &mut bool) {
for pkg in matches {
println!(" * {}", pkg.id);
}
*bad = true;
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/tools/tidy/src/extdeps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ pub fn check(root: &Path, bad: &mut bool) {

// Ensure source is allowed.
if !ALLOWED_SOURCES.contains(&&*source) {
println!("invalid source: {}", source);
*bad = true;
tidy_error!(bad, "invalid source: {}", source);
}
}
}
1 change: 0 additions & 1 deletion src/tools/tidy/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
let issue_str = parts.next().unwrap().trim();
let tracking_issue = if issue_str.starts_with("None") {
if level == Status::Unstable && !next_feature_omits_tracking_issue {
*bad = true;
tidy_error!(
bad,
"{}:{}: no tracking issue for feature {}",
Expand Down
4 changes: 4 additions & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ macro_rules! t {
}

macro_rules! tidy_error {
($bad:expr, $fmt:expr) => ({
*$bad = true;
eprintln!("tidy error: {}", $fmt);
});
($bad:expr, $fmt:expr, $($arg:tt)*) => ({
*$bad = true;
eprint!("tidy error: ");
Expand Down
6 changes: 2 additions & 4 deletions src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ pub fn check(path: &Path, bad: &mut bool) {
let testname =
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
if !file_path.with_file_name(testname).with_extension("rs").exists() {
println!("Stray file with UI testing output: {:?}", file_path);
*bad = true;
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
}

if let Ok(metadata) = fs::metadata(file_path) {
if metadata.len() == 0 {
println!("Empty file with UI testing output: {:?}", file_path);
*bad = true;
tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);
}
}
}
Expand Down