4
4
use std:: ffi:: OsStr ;
5
5
use std:: path:: Path ;
6
6
use std:: process:: Command ;
7
+ use std:: str:: FromStr ;
7
8
8
9
use build_helper:: ci:: CiEnv ;
9
10
use build_helper:: git:: { GitConfig , get_closest_upstream_commit} ;
@@ -71,9 +72,22 @@ pub fn check(src_path: &Path, bad: &mut bool) {
71
72
Some ( output) => {
72
73
let mut format_version_updated = false ;
73
74
let mut latest_feature_comment_updated = false ;
75
+ let mut new_version = None ;
76
+ let mut old_version = None ;
74
77
for line in output. lines ( ) {
75
78
if line. starts_with ( "+pub const FORMAT_VERSION: u32 =" ) {
76
79
format_version_updated = true ;
80
+ new_version = line
81
+ . split ( '=' )
82
+ . nth ( 1 )
83
+ . and_then ( |s| s. trim ( ) . split ( ';' ) . next ( ) )
84
+ . and_then ( |s| u32:: from_str ( s. trim ( ) ) . ok ( ) ) ;
85
+ } else if line. starts_with ( "-pub const FORMAT_VERSION: u32 =" ) {
86
+ old_version = line
87
+ . split ( '=' )
88
+ . nth ( 1 )
89
+ . and_then ( |s| s. trim ( ) . split ( ';' ) . next ( ) )
90
+ . and_then ( |s| u32:: from_str ( s. trim ( ) ) . ok ( ) ) ;
77
91
} else if line. starts_with ( "+// Latest feature:" ) {
78
92
latest_feature_comment_updated = true ;
79
93
}
@@ -92,6 +106,17 @@ pub fn check(src_path: &Path, bad: &mut bool) {
92
106
) ;
93
107
}
94
108
}
109
+ match ( new_version, old_version) {
110
+ ( Some ( new_version) , Some ( old_version) ) if new_version != old_version + 1 => {
111
+ * bad = true ;
112
+ eprintln ! (
113
+ "error in `rustdoc_json` tidy check: invalid `FORMAT_VERSION` increase in \
114
+ `{RUSTDOC_JSON_TYPES}/lib.rs`, should be `{}`, found `{new_version}`",
115
+ old_version + 1 ,
116
+ ) ;
117
+ }
118
+ _ => { }
119
+ }
95
120
}
96
121
None => {
97
122
* bad = true ;
0 commit comments