diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-06-20 16:12:41 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-06-20 16:22:05 +0200 |
| commit | 0fc950735ac35784b2ba49679f164f3ae2dfc8f7 (patch) | |
| tree | 9cb15c518ac96af68f220f001ba7a22e27eee2c1 | |
| parent | 636769490445a477746a1242e40fa11b633388a5 (diff) | |
| download | rust-0fc950735ac35784b2ba49679f164f3ae2dfc8f7.tar.gz rust-0fc950735ac35784b2ba49679f164f3ae2dfc8f7.zip | |
Improve error message for rustdoc_json_types tidy check
Only emit git errors if we are in CI environment
| -rw-r--r-- | src/build_helper/src/ci.rs | 6 | ||||
| -rw-r--r-- | src/tools/tidy/src/rustdoc_json.rs | 30 |
2 files changed, 25 insertions, 11 deletions
diff --git a/src/build_helper/src/ci.rs b/src/build_helper/src/ci.rs index 60f319129a0..9d114c70a67 100644 --- a/src/build_helper/src/ci.rs +++ b/src/build_helper/src/ci.rs @@ -17,7 +17,11 @@ impl CiEnv { } pub fn is_ci() -> bool { - Self::current() != CiEnv::None + Self::current().is_running_in_ci() + } + + pub fn is_running_in_ci(self) -> bool { + self != CiEnv::None } /// Checks if running in rust-lang/rust managed CI job. diff --git a/src/tools/tidy/src/rustdoc_json.rs b/src/tools/tidy/src/rustdoc_json.rs index 808341fbd06..f179acf4a51 100644 --- a/src/tools/tidy/src/rustdoc_json.rs +++ b/src/tools/tidy/src/rustdoc_json.rs @@ -9,33 +9,41 @@ use build_helper::ci::CiEnv; use build_helper::git::{GitConfig, get_closest_upstream_commit}; use build_helper::stage0_parser::parse_stage0_file; +const RUSTDOC_JSON_TYPES: &str = "src/rustdoc-json-types"; + fn git_diff<S: AsRef<OsStr>>(base_commit: &str, extra_arg: S) -> 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()) } +fn error_if_in_ci(ci_env: CiEnv, msg: &str, bad: &mut bool) { + if ci_env.is_running_in_ci() { + *bad = true; + eprintln!("error in `rustdoc_json` tidy check: {msg}"); + } else { + eprintln!("{msg}. Skipping `rustdoc_json` tidy check"); + } +} + pub fn check(src_path: &Path, bad: &mut bool) { println!("Checking tidy rustdoc_json..."); let stage0 = parse_stage0_file(); + let ci_env = CiEnv::current(); let base_commit = match get_closest_upstream_commit( None, &GitConfig { nightly_branch: &stage0.config.nightly_branch, git_merge_commit_email: &stage0.config.git_merge_commit_email, }, - CiEnv::current(), + ci_env, ) { Ok(Some(commit)) => commit, Ok(None) => { - *bad = true; - eprintln!("error: no base commit found for rustdoc_json check"); + error_if_in_ci(ci_env, "no base commit found", bad); return; } Err(error) => { - *bad = true; - eprintln!( - "error: failed to retrieve base commit for rustdoc_json check because of `{error}`" - ); + error_if_in_ci(ci_env, &format!("failed to retrieve base commit: {error}"), bad); return; } }; @@ -45,7 +53,7 @@ pub fn check(src_path: &Path, bad: &mut bool) { Some(output) => { if !output .lines() - .any(|line| line.starts_with("M") && line.contains("src/rustdoc-json-types")) + .any(|line| line.starts_with("M") && line.contains(RUSTDOC_JSON_TYPES)) { // `rustdoc-json-types` was not modified so nothing more to check here. println!("`rustdoc-json-types` was not modified."); @@ -74,11 +82,13 @@ pub fn check(src_path: &Path, bad: &mut bool) { *bad = true; if latest_feature_comment_updated { eprintln!( - "error: `Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't" + "error in `rustdoc_json` tidy check: `Latest feature` comment was updated \ + whereas `FORMAT_VERSION` wasn't in `{RUSTDOC_JSON_TYPES}/lib.rs`" ); } else { eprintln!( - "error: `Latest feature` comment was not updated whereas `FORMAT_VERSION` was" + "error in `rustdoc_json` tidy check: `Latest feature` comment was not \ + updated whereas `FORMAT_VERSION` was in `{RUSTDOC_JSON_TYPES}/lib.rs`" ); } } |
