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
+ use std:: path:: Path ;
4
6
use std:: process:: Command ;
5
7
6
8
use build_helper:: ci:: CiEnv ;
7
9
use build_helper:: git:: { GitConfig , get_closest_upstream_commit} ;
8
10
use build_helper:: stage0_parser:: parse_stage0_file;
9
11
10
- fn git_diff ( base_commit : & str , extra_arg : & str ) -> Option < String > {
12
+ fn git_diff < S : AsRef < OsStr > > ( base_commit : & str , extra_arg : S ) -> Option < String > {
11
13
let output = Command :: new ( "git" ) . arg ( "diff" ) . arg ( base_commit) . arg ( extra_arg) . output ( ) . ok ( ) ?;
12
14
Some ( String :: from_utf8_lossy ( & output. stdout ) . into ( ) )
13
15
}
14
16
15
- pub fn check ( bad : & mut bool ) {
17
+ pub fn check ( src_path : & Path , bad : & mut bool ) {
16
18
println ! ( "Checking tidy rustdoc_json..." ) ;
17
19
let stage0 = parse_stage0_file ( ) ;
18
20
let base_commit = match get_closest_upstream_commit (
@@ -26,13 +28,13 @@ pub fn check(bad: &mut bool) {
26
28
Ok ( Some ( commit) ) => commit,
27
29
Ok ( None ) => {
28
30
* bad = true ;
29
- eprintln ! ( "No base commit found, skipping rustdoc_json check" ) ;
31
+ eprintln ! ( "error: no base commit found for rustdoc_json check" ) ;
30
32
return ;
31
33
}
32
34
Err ( error) => {
33
35
* bad = true ;
34
36
eprintln ! (
35
- "Failed to retrieve base commit for rustdoc_json check because of `{error}`, skipping it "
37
+ "error: failed to retrieve base commit for rustdoc_json check because of `{error}`"
36
38
) ;
37
39
return ;
38
40
}
@@ -46,17 +48,18 @@ pub fn check(bad: &mut bool) {
46
48
. any ( |line| line. starts_with ( "M" ) && line. contains ( "src/rustdoc-json-types" ) )
47
49
{
48
50
// `rustdoc-json-types` was not modified so nothing more to check here.
51
+ println ! ( "`rustdoc-json-types` was not modified." ) ;
49
52
return ;
50
53
}
51
54
}
52
55
None => {
53
56
* bad = true ;
54
- eprintln ! ( "Failed to run `git diff`" ) ;
57
+ eprintln ! ( "error: failed to run `git diff` in rustdoc_json check " ) ;
55
58
return ;
56
59
}
57
60
}
58
61
// Then we check that if `FORMAT_VERSION` was updated, the `Latest feature:` was also updated.
59
- match git_diff ( & base_commit, "src/ rustdoc-json-types") {
62
+ match git_diff ( & base_commit, src_path . join ( " rustdoc-json-types") ) {
60
63
Some ( output) => {
61
64
let mut format_version_updated = false ;
62
65
let mut latest_feature_comment_updated = false ;
@@ -71,18 +74,18 @@ pub fn check(bad: &mut bool) {
71
74
* bad = true ;
72
75
if latest_feature_comment_updated {
73
76
eprintln ! (
74
- "`Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't"
77
+ "error: `Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't"
75
78
) ;
76
79
} else {
77
80
eprintln ! (
78
- "`Latest feature` comment was not updated whereas `FORMAT_VERSION` was"
81
+ "error: `Latest feature` comment was not updated whereas `FORMAT_VERSION` was"
79
82
) ;
80
83
}
81
84
}
82
85
}
83
86
None => {
84
87
* bad = true ;
85
- eprintln ! ( "Failed to run `git diff`" ) ;
88
+ eprintln ! ( "error: failed to run `git diff` in rustdoc_json check " ) ;
86
89
return ;
87
90
}
88
91
}
0 commit comments