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 ;
54use std:: path:: Path ;
6- use std:: process:: Command ;
75use std:: str:: FromStr ;
86
9- use build_helper:: ci:: CiEnv ;
10- use build_helper:: git:: { GitConfig , get_closest_upstream_commit} ;
11- use build_helper:: stage0_parser:: parse_stage0_file;
12-
137const RUSTDOC_JSON_TYPES : & str = "src/rustdoc-json-types" ;
148
15- fn git_diff < S : AsRef < OsStr > > ( base_commit : & str , extra_arg : S ) -> Option < String > {
16- let output = Command :: new ( "git" ) . arg ( "diff" ) . arg ( base_commit) . arg ( extra_arg) . output ( ) . ok ( ) ?;
17- Some ( String :: from_utf8_lossy ( & output. stdout ) . into ( ) )
18- }
19-
20- fn error_if_in_ci ( ci_env : CiEnv , msg : & str , bad : & mut bool ) {
21- if ci_env. is_running_in_ci ( ) {
22- * bad = true ;
23- eprintln ! ( "error in `rustdoc_json` tidy check: {msg}" ) ;
24- } else {
25- eprintln ! ( "{msg}. Skipping `rustdoc_json` tidy check" ) ;
26- }
27- }
28-
29- pub fn check ( src_path : & Path , bad : & mut bool ) {
9+ pub fn check ( src_path : & Path , ci_info : & crate :: CiInfo , bad : & mut bool ) {
3010 println ! ( "Checking tidy rustdoc_json..." ) ;
31- let stage0 = parse_stage0_file ( ) ;
32- let ci_env = CiEnv :: current ( ) ;
33- let base_commit = match get_closest_upstream_commit (
34- None ,
35- & GitConfig {
36- nightly_branch : & stage0. config . nightly_branch ,
37- git_merge_commit_email : & stage0. config . git_merge_commit_email ,
38- } ,
39- ci_env,
40- ) {
41- Ok ( Some ( commit) ) => commit,
42- Ok ( None ) => {
43- error_if_in_ci ( ci_env, "no base commit found" , bad) ;
44- return ;
45- }
46- Err ( error) => {
47- error_if_in_ci ( ci_env, & format ! ( "failed to retrieve base commit: {error}" ) , bad) ;
48- return ;
49- }
11+ let Some ( base_commit) = & ci_info. base_commit else {
12+ eprintln ! ( "No base commit, skipping rustdoc_json check" ) ;
13+ return ;
5014 } ;
5115
5216 // First we check that `src/rustdoc-json-types` was modified.
53- match git_diff ( & base_commit, "--name-status" ) {
17+ match crate :: git_diff ( & base_commit, "--name-status" ) {
5418 Some ( output) => {
5519 if !output
5620 . lines ( )
@@ -68,7 +32,7 @@ pub fn check(src_path: &Path, bad: &mut bool) {
6832 }
6933 }
7034 // Then we check that if `FORMAT_VERSION` was updated, the `Latest feature:` was also updated.
71- match git_diff ( & base_commit, src_path. join ( "rustdoc-json-types" ) ) {
35+ match crate :: git_diff ( & base_commit, src_path. join ( "rustdoc-json-types" ) ) {
7236 Some ( output) => {
7337 let mut format_version_updated = false ;
7438 let mut latest_feature_comment_updated = false ;
0 commit comments