Skip to content

Commit aa1b8eb

Browse files
Pass src_path to rustdoc_json tidy check
1 parent f8ed2e1 commit aa1b8eb

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/tools/tidy/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn main() {
110110
check!(rustdoc_css_themes, &librustdoc_path);
111111
check!(rustdoc_templates, &librustdoc_path);
112112
check!(rustdoc_js, &librustdoc_path, &tools_path, &src_path);
113-
check!(rustdoc_json);
113+
check!(rustdoc_json, &src_path);
114114
check!(known_bug, &crashes_path);
115115
check!(unknown_revision, &tests_path);
116116

src/tools/tidy/src/rustdoc_json.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
//! Tidy check to ensure that `FORMAT_VERSION` was correctly updated if `rustdoc-json-types` was
22
//! updated as well.
33
4+
use std::ffi::OsStr;
5+
use std::path::Path;
46
use std::process::Command;
57

68
use build_helper::ci::CiEnv;
79
use build_helper::git::{GitConfig, get_closest_upstream_commit};
810
use build_helper::stage0_parser::parse_stage0_file;
911

10-
fn git_diff(base_commit: &str, extra_arg: &str) -> Option<String> {
12+
fn git_diff<S: AsRef<OsStr>>(base_commit: &str, extra_arg: S) -> Option<String> {
1113
let output = Command::new("git").arg("diff").arg(base_commit).arg(extra_arg).output().ok()?;
1214
Some(String::from_utf8_lossy(&output.stdout).into())
1315
}
1416

15-
pub fn check(bad: &mut bool) {
17+
pub fn check(src_path: &Path, bad: &mut bool) {
1618
println!("Checking tidy rustdoc_json...");
1719
let stage0 = parse_stage0_file();
1820
let base_commit = match get_closest_upstream_commit(
@@ -26,13 +28,13 @@ pub fn check(bad: &mut bool) {
2628
Ok(Some(commit)) => commit,
2729
Ok(None) => {
2830
*bad = true;
29-
eprintln!("No base commit found, skipping rustdoc_json check");
31+
eprintln!("error: no base commit found for rustdoc_json check");
3032
return;
3133
}
3234
Err(error) => {
3335
*bad = true;
3436
eprintln!(
35-
"Failed to retrieve base commit for rustdoc_json check because of `{error}`, skipping it"
37+
"error: failed to retrieve base commit for rustdoc_json check because of `{error}`"
3638
);
3739
return;
3840
}
@@ -46,17 +48,18 @@ pub fn check(bad: &mut bool) {
4648
.any(|line| line.starts_with("M") && line.contains("src/rustdoc-json-types"))
4749
{
4850
// `rustdoc-json-types` was not modified so nothing more to check here.
51+
println!("`rustdoc-json-types` was not modified.");
4952
return;
5053
}
5154
}
5255
None => {
5356
*bad = true;
54-
eprintln!("Failed to run `git diff`");
57+
eprintln!("error: failed to run `git diff` in rustdoc_json check");
5558
return;
5659
}
5760
}
5861
// Then we check that if `FORMAT_VERSION` was updated, the `Latest feature:` was also updated.
59-
match git_diff(&base_commit, "src/rustdoc-json-types") {
62+
match git_diff(&base_commit, src_path.join("rustdoc-json-types")) {
6063
Some(output) => {
6164
let mut format_version_updated = false;
6265
let mut latest_feature_comment_updated = false;
@@ -71,18 +74,18 @@ pub fn check(bad: &mut bool) {
7174
*bad = true;
7275
if latest_feature_comment_updated {
7376
eprintln!(
74-
"`Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't"
77+
"error: `Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't"
7578
);
7679
} else {
7780
eprintln!(
78-
"`Latest feature` comment was not updated whereas `FORMAT_VERSION` was"
81+
"error: `Latest feature` comment was not updated whereas `FORMAT_VERSION` was"
7982
);
8083
}
8184
}
8285
}
8386
None => {
8487
*bad = true;
85-
eprintln!("Failed to run `git diff`");
88+
eprintln!("error: failed to run `git diff` in rustdoc_json check");
8689
return;
8790
}
8891
}

0 commit comments

Comments
 (0)