@@ -9,33 +9,41 @@ use build_helper::ci::CiEnv;
99use build_helper:: git:: { GitConfig , get_closest_upstream_commit} ;
1010use build_helper:: stage0_parser:: parse_stage0_file;
1111
12+ const RUSTDOC_JSON_TYPES : & str = "src/rustdoc-json-types" ;
13+
1214fn git_diff < S : AsRef < OsStr > > ( base_commit : & str , extra_arg : S ) -> Option < String > {
1315 let output = Command :: new ( "git" ) . arg ( "diff" ) . arg ( base_commit) . arg ( extra_arg) . output ( ) . ok ( ) ?;
1416 Some ( String :: from_utf8_lossy ( & output. stdout ) . into ( ) )
1517}
1618
19+ fn error_if_in_ci ( ci_env : CiEnv , msg : & str , bad : & mut bool ) {
20+ if ci_env. is_ci ( ) {
21+ * bad = true ;
22+ eprintln ! ( "error in `rustdoc_json` tidy check: {message}" ) ;
23+ } else {
24+ eprintln ! ( "{message}. Skipping `rustdoc_json` tidy check" ) ;
25+ }
26+ }
27+
1728pub fn check ( src_path : & Path , bad : & mut bool ) {
1829 println ! ( "Checking tidy rustdoc_json..." ) ;
1930 let stage0 = parse_stage0_file ( ) ;
31+ let ci_env = CiEnv :: current ( ) ;
2032 let base_commit = match get_closest_upstream_commit (
2133 None ,
2234 & GitConfig {
2335 nightly_branch : & stage0. config . nightly_branch ,
2436 git_merge_commit_email : & stage0. config . git_merge_commit_email ,
2537 } ,
26- CiEnv :: current ( ) ,
38+ ci_env ,
2739 ) {
2840 Ok ( Some ( commit) ) => commit,
2941 Ok ( None ) => {
30- * bad = true ;
31- eprintln ! ( "error: no base commit found for rustdoc_json check" ) ;
42+ error_if_in_ci ( ci_env, "no base commit found" , bad) ;
3243 return ;
3344 }
3445 Err ( error) => {
35- * bad = true ;
36- eprintln ! (
37- "error: failed to retrieve base commit for rustdoc_json check because of `{error}`"
38- ) ;
46+ error_if_in_ci ( ci_env, "failed to retrieve base commit" , bad) ;
3947 return ;
4048 }
4149 } ;
@@ -45,7 +53,7 @@ pub fn check(src_path: &Path, bad: &mut bool) {
4553 Some ( output) => {
4654 if !output
4755 . lines ( )
48- . any ( |line| line. starts_with ( "M" ) && line. contains ( "src/rustdoc-json-types" ) )
56+ . any ( |line| line. starts_with ( "M" ) && line. contains ( RUSTDOC_JSON_TYPES ) )
4957 {
5058 // `rustdoc-json-types` was not modified so nothing more to check here.
5159 println ! ( "`rustdoc-json-types` was not modified." ) ;
@@ -74,11 +82,13 @@ pub fn check(src_path: &Path, bad: &mut bool) {
7482 * bad = true ;
7583 if latest_feature_comment_updated {
7684 eprintln ! (
77- "error: `Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't"
85+ "error in `rustdoc_json` tidy check: `Latest feature` comment was updated \
86+ whereas `FORMAT_VERSION` wasn't in `{RUSTDOC_JSON_TYPES}/lib.rs`"
7887 ) ;
7988 } else {
8089 eprintln ! (
81- "error: `Latest feature` comment was not updated whereas `FORMAT_VERSION` was"
90+ "error in `rustdoc_json` tidy check: `Latest feature` comment was not \
91+ updated whereas `FORMAT_VERSION` was in `{RUSTDOC_JSON_TYPES}/lib.rs`"
8292 ) ;
8393 }
8494 }
0 commit comments