1
1
//! Tidy check to ensure that `FORMAT_VERSION` was correctly updated if `rustdoc-json-types` was
2
2
//! updated as well.
3
3
4
- use std:: ffi:: OsStr ;
5
4
use std:: path:: Path ;
6
- use std:: process:: Command ;
7
5
use std:: str:: FromStr ;
8
6
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
-
13
7
const RUSTDOC_JSON_TYPES : & str = "src/rustdoc-json-types" ;
14
8
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 ) {
30
10
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 ;
50
14
} ;
51
15
52
16
// 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" ) {
54
18
Some ( output) => {
55
19
if !output
56
20
. lines ( )
@@ -68,7 +32,7 @@ pub fn check(src_path: &Path, bad: &mut bool) {
68
32
}
69
33
}
70
34
// 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" ) ) {
72
36
Some ( output) => {
73
37
let mut format_version_updated = false ;
74
38
let mut latest_feature_comment_updated = false ;
0 commit comments