diff options
| -rw-r--r-- | src/tools/tidy/src/lib.rs | 1 | ||||
| -rw-r--r-- | src/tools/tidy/src/main.rs | 1 | ||||
| -rw-r--r-- | src/tools/tidy/src/rustdoc_json.rs | 66 |
3 files changed, 68 insertions, 0 deletions
diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index e8a12d56335..28aa80225b1 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -83,6 +83,7 @@ pub mod pal; pub mod rustdoc_css_themes; pub mod rustdoc_gui_tests; pub mod rustdoc_js; +pub mod rustdoc_json; pub mod rustdoc_templates; pub mod style; pub mod target_policy; diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 776f1bde2eb..420260a97a0 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -110,6 +110,7 @@ fn main() { check!(rustdoc_css_themes, &librustdoc_path); check!(rustdoc_templates, &librustdoc_path); check!(rustdoc_js, &librustdoc_path, &tools_path, &src_path); + check!(rustdoc_json); check!(known_bug, &crashes_path); check!(unknown_revision, &tests_path); diff --git a/src/tools/tidy/src/rustdoc_json.rs b/src/tools/tidy/src/rustdoc_json.rs new file mode 100644 index 00000000000..a98c4f4cc3e --- /dev/null +++ b/src/tools/tidy/src/rustdoc_json.rs @@ -0,0 +1,66 @@ +//! Tidy check to ensure that `FORMAT_VERSION` was correctly updated if `rustdoc-json-types` was +//! updated as well. + +use std::process::Command; + +fn git_diff(base_commit: &str, extra_arg: &str) -> Option<String> { + let output = Command::new("git").arg("diff").arg(base_commit).arg(extra_arg).output().ok()?; + Some(String::from_utf8_lossy(&output.stdout).into()) +} + +pub fn check(bad: &mut bool) { + let Ok(base_commit) = std::env::var("BASE_COMMIT") else { + // Not in CI so nothing we can check here. + println!("not checking rustdoc JSON `FORMAT_VERSION` update"); + return; + }; + + // First we check that `src/rustdoc-json-types` was modified. + match git_diff(&base_commit, "--name-status") { + Some(output) => { + if !output + .lines() + .any(|line| line.starts_with("M") && line.contains("src/rustdoc-json-types")) + { + // `rustdoc-json-types` was not modified so nothing more to check here. + return; + } + } + None => { + *bad = true; + eprintln!("Failed to run `git diff`"); + return; + } + } + // Then we check that if `FORMAT_VERSION` was updated, the `Latest feature:` was also updated. + match git_diff(&base_commit, "src/rustdoc-json-types") { + Some(output) => { + let mut format_version_updated = false; + let mut latest_feature_comment_updated = false; + for line in output.lines() { + if line.starts_with("+pub const FORMAT_VERSION: u32 =") { + format_version_updated = true; + } else if line.starts_with("+// Latest feature:") { + latest_feature_comment_updated = true; + } + } + if format_version_updated != latest_feature_comment_updated { + *bad = true; + if latest_feature_comment_updated { + eprintln!( + "`Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't" + ); + } else { + eprintln!( + "`Latest feature` comment was not updated whereas `FORMAT_VERSION` was" + ); + } + } + } + None => { + *bad = true; + eprintln!("Failed to run `git diff`"); + return; + } + } +} |
