Skip to content

Commit 9cccf1e

Browse files
Generate base commit in rustdoc_json tidy checks
1 parent 43d18cf commit 9cccf1e

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/build_helper/src/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn get_latest_upstream_commit_that_modified_files(
198198
/// author.
199199
///
200200
/// If we are in CI, we simply return our first parent.
201-
fn get_closest_upstream_commit(
201+
pub fn get_closest_upstream_commit(
202202
git_dir: Option<&Path>,
203203
config: &GitConfig<'_>,
204204
env: CiEnv,

src/tools/tidy/src/rustdoc_json.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,39 @@
33
44
use std::process::Command;
55

6+
use build_helper::ci::CiEnv;
7+
use build_helper::git::{GitConfig, get_closest_upstream_commit};
8+
use build_helper::stage0_parser::parse_stage0_file;
9+
610
fn git_diff(base_commit: &str, extra_arg: &str) -> Option<String> {
711
let output = Command::new("git").arg("diff").arg(base_commit).arg(extra_arg).output().ok()?;
812
Some(String::from_utf8_lossy(&output.stdout).into())
913
}
1014

1115
pub fn check(bad: &mut bool) {
12-
let Ok(base_commit) = std::env::var("BASE_COMMIT") else {
13-
// Not in CI so nothing we can check here.
14-
println!("not checking rustdoc JSON `FORMAT_VERSION` update");
15-
return;
16+
println!("Checking tidy rustdoc_json...");
17+
let stage0 = parse_stage0_file();
18+
let base_commit = match get_closest_upstream_commit(
19+
None,
20+
&GitConfig {
21+
nightly_branch: &stage0.config.nightly_branch,
22+
git_merge_commit_email: &stage0.config.git_merge_commit_email,
23+
},
24+
CiEnv::current(),
25+
) {
26+
Ok(Some(commit)) => commit,
27+
Ok(None) => {
28+
*bad = true;
29+
eprintln!("No base commit found, skipping rustdoc_json check");
30+
return;
31+
}
32+
Err(error) => {
33+
*bad = true;
34+
eprintln!(
35+
"Failed to retrieve base commit for rustdoc_json check because of `{error}`, skipping it"
36+
);
37+
return;
38+
}
1639
};
1740

1841
// First we check that `src/rustdoc-json-types` was modified.

0 commit comments

Comments
 (0)