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
-
8
- use build_helper:: ci:: CiEnv ;
9
- use build_helper:: git:: { GitConfig , get_closest_upstream_commit} ;
10
- use build_helper:: stage0_parser:: parse_stage0_file;
11
5
12
6
const RUSTDOC_JSON_TYPES : & str = "src/rustdoc-json-types" ;
13
7
14
- fn git_diff < S : AsRef < OsStr > > ( base_commit : & str , extra_arg : S ) -> Option < String > {
15
- let output = Command :: new ( "git" ) . arg ( "diff" ) . arg ( base_commit) . arg ( extra_arg) . output ( ) . ok ( ) ?;
16
- Some ( String :: from_utf8_lossy ( & output. stdout ) . into ( ) )
17
- }
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
-
28
- pub fn check ( src_path : & Path , bad : & mut bool ) {
8
+ pub fn check ( src_path : & Path , ci_info : & crate :: CiInfo , bad : & mut bool ) {
29
9
println ! ( "Checking tidy rustdoc_json..." ) ;
30
- let stage0 = parse_stage0_file ( ) ;
31
- let ci_env = CiEnv :: current ( ) ;
32
- let base_commit = match get_closest_upstream_commit (
33
- None ,
34
- & GitConfig {
35
- nightly_branch : & stage0. config . nightly_branch ,
36
- git_merge_commit_email : & stage0. config . git_merge_commit_email ,
37
- } ,
38
- ci_env,
39
- ) {
40
- Ok ( Some ( commit) ) => commit,
41
- Ok ( None ) => {
42
- error_if_in_ci ( ci_env, "no base commit found" , bad) ;
43
- return ;
44
- }
45
- Err ( error) => {
46
- error_if_in_ci ( ci_env, & format ! ( "failed to retrieve base commit: {error}" ) , bad) ;
47
- return ;
48
- }
10
+ let Some ( base_commit) = & ci_info. base_commit else {
11
+ eprintln ! ( "No base commit, skipping rustdoc_json check" ) ;
12
+ return ;
49
13
} ;
50
14
51
15
// First we check that `src/rustdoc-json-types` was modified.
52
- match git_diff ( & base_commit, "--name-status" ) {
16
+ match crate :: git_diff ( & base_commit, "--name-status" ) {
53
17
Some ( output) => {
54
18
if !output
55
19
. lines ( )
@@ -67,7 +31,7 @@ pub fn check(src_path: &Path, bad: &mut bool) {
67
31
}
68
32
}
69
33
// Then we check that if `FORMAT_VERSION` was updated, the `Latest feature:` was also updated.
70
- match git_diff ( & base_commit, src_path. join ( "rustdoc-json-types" ) ) {
34
+ match crate :: git_diff ( & base_commit, src_path. join ( "rustdoc-json-types" ) ) {
71
35
Some ( output) => {
72
36
let mut format_version_updated = false ;
73
37
let mut latest_feature_comment_updated = false ;
0 commit comments