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;
46use std::process::Command;
57
68use build_helper::ci::CiEnv;
79use build_helper::git::{GitConfig, get_closest_upstream_commit};
810use 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,19 +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`");
86- return;
88+ eprintln!("error: failed to run `git diff` in rustdoc_json check");
8789 }
8890 }
8991}
0 commit comments