@@ -9,33 +9,41 @@ use build_helper::ci::CiEnv;
9
9
use build_helper:: git:: { GitConfig , get_closest_upstream_commit} ;
10
10
use build_helper:: stage0_parser:: parse_stage0_file;
11
11
12
+ const RUSTDOC_JSON_TYPES : & str = "src/rustdoc-json-types" ;
13
+
12
14
fn git_diff < S : AsRef < OsStr > > ( base_commit : & str , extra_arg : S ) -> Option < String > {
13
15
let output = Command :: new ( "git" ) . arg ( "diff" ) . arg ( base_commit) . arg ( extra_arg) . output ( ) . ok ( ) ?;
14
16
Some ( String :: from_utf8_lossy ( & output. stdout ) . into ( ) )
15
17
}
16
18
19
+ fn error_if_in_ci ( ci_env : CiEnv , msg : & str , bad : & mut bool ) {
20
+ if ci_env. is_running_in_ci ( ) {
21
+ * bad = true ;
22
+ eprintln ! ( "error in `rustdoc_json` tidy check: {msg}" ) ;
23
+ } else {
24
+ eprintln ! ( "{msg}. Skipping `rustdoc_json` tidy check" ) ;
25
+ }
26
+ }
27
+
17
28
pub fn check ( src_path : & Path , bad : & mut bool ) {
18
29
println ! ( "Checking tidy rustdoc_json..." ) ;
19
30
let stage0 = parse_stage0_file ( ) ;
31
+ let ci_env = CiEnv :: current ( ) ;
20
32
let base_commit = match get_closest_upstream_commit (
21
33
None ,
22
34
& GitConfig {
23
35
nightly_branch : & stage0. config . nightly_branch ,
24
36
git_merge_commit_email : & stage0. config . git_merge_commit_email ,
25
37
} ,
26
- CiEnv :: current ( ) ,
38
+ ci_env ,
27
39
) {
28
40
Ok ( Some ( commit) ) => commit,
29
41
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) ;
32
43
return ;
33
44
}
34
45
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, & format ! ( "failed to retrieve base commit: {error}" ) , bad) ;
39
47
return ;
40
48
}
41
49
} ;
@@ -45,7 +53,7 @@ pub fn check(src_path: &Path, bad: &mut bool) {
45
53
Some ( output) => {
46
54
if !output
47
55
. 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 ) )
49
57
{
50
58
// `rustdoc-json-types` was not modified so nothing more to check here.
51
59
println ! ( "`rustdoc-json-types` was not modified." ) ;
@@ -74,11 +82,13 @@ pub fn check(src_path: &Path, bad: &mut bool) {
74
82
* bad = true ;
75
83
if latest_feature_comment_updated {
76
84
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`"
78
87
) ;
79
88
} else {
80
89
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`"
82
92
) ;
83
93
}
84
94
}
0 commit comments