@@ -4,11 +4,14 @@ use std::collections::BTreeSet;
4
4
use std:: env;
5
5
use std:: fs:: { self , write} ;
6
6
use std:: path:: Path ;
7
+ use std:: process:: Command ;
7
8
8
- use tidy:: features:: { Features , collect_env_vars, collect_lang_features, collect_lib_features} ;
9
+ use tidy:: features:: {
10
+ Feature , Features , Status , collect_env_vars, collect_lang_features, collect_lib_features,
11
+ } ;
9
12
use tidy:: t;
10
13
use tidy:: unstable_book:: {
11
- ENV_VARS_DIR , LANG_FEATURES_DIR , LIB_FEATURES_DIR , PATH_STR ,
14
+ COMPILER_FLAGS_DIR , ENV_VARS_DIR , LANG_FEATURES_DIR , LIB_FEATURES_DIR , PATH_STR ,
12
15
collect_unstable_book_section_file_names, collect_unstable_feature_names,
13
16
} ;
14
17
@@ -38,8 +41,15 @@ fn set_to_summary_str(set: &BTreeSet<String>, dir: &str) -> String {
38
41
. fold ( "" . to_owned ( ) , |s, a| s + & a + "\n " )
39
42
}
40
43
41
- fn generate_summary ( path : & Path , lang_features : & Features , lib_features : & Features ) {
42
- let compiler_flags = collect_unstable_book_section_file_names ( & path. join ( "src/compiler-flags" ) ) ;
44
+ fn generate_summary (
45
+ path : & Path ,
46
+ lang_features : & Features ,
47
+ lib_features : & Features ,
48
+ compiler_flags : & Features ,
49
+ ) {
50
+ let compiler_flags =
51
+ & collect_unstable_book_section_file_names ( & path. join ( "src/compiler-flags" ) )
52
+ | & collect_unstable_feature_names ( & compiler_flags) ;
43
53
let compiler_env_vars =
44
54
collect_unstable_book_section_file_names ( & path. join ( "src/compiler-environment-variables" ) ) ;
45
55
@@ -112,14 +122,48 @@ fn copy_recursive(from: &Path, to: &Path) {
112
122
}
113
123
}
114
124
125
+ fn collect_compiler_flags ( rustc_path : impl AsRef < Path > ) -> Features {
126
+ let mut rustc = Command :: new ( rustc_path. as_ref ( ) ) ;
127
+ rustc. arg ( "-Zhelp" ) ;
128
+
129
+ let output = t ! ( rustc. output( ) ) ;
130
+ let help_str = t ! ( String :: from_utf8( output. stdout) ) ;
131
+ let parts = help_str. split ( "\n -Z" ) . collect :: < Vec < _ > > ( ) ;
132
+ assert ! ( !parts[ 1 ..] . is_empty( ) , "no -Z options were found" ) ;
133
+
134
+ let mut features = Features :: new ( ) ;
135
+ for part in parts. into_iter ( ) . skip ( 1 ) {
136
+ let ( name, description) =
137
+ part. split_once ( "--" ) . expect ( "name and description should be delimited by '--'" ) ;
138
+ let name = name. trim ( ) . trim_end_matches ( "=val" ) ;
139
+ let description = description. trim ( ) ;
140
+
141
+ features. insert (
142
+ name. replace ( '-' , "_" ) ,
143
+ Feature {
144
+ level : Status :: Unstable ,
145
+ since : None ,
146
+ has_gate_test : false ,
147
+ tracking_issue : None ,
148
+ file : "" . into ( ) ,
149
+ line : 0 ,
150
+ description : Some ( description. to_owned ( ) ) ,
151
+ } ,
152
+ ) ;
153
+ }
154
+ features
155
+ }
156
+
115
157
fn main ( ) {
116
158
let library_path_str = env:: args_os ( ) . nth ( 1 ) . expect ( "library/ path required" ) ;
117
159
let compiler_path_str = env:: args_os ( ) . nth ( 2 ) . expect ( "compiler/ path required" ) ;
118
160
let src_path_str = env:: args_os ( ) . nth ( 3 ) . expect ( "src/ path required" ) ;
119
- let dest_path_str = env:: args_os ( ) . nth ( 4 ) . expect ( "destination path required" ) ;
161
+ let rustc_path_str = env:: args_os ( ) . nth ( 4 ) . expect ( "rustc path required" ) ;
162
+ let dest_path_str = env:: args_os ( ) . nth ( 5 ) . expect ( "destination path required" ) ;
120
163
let library_path = Path :: new ( & library_path_str) ;
121
164
let compiler_path = Path :: new ( & compiler_path_str) ;
122
165
let src_path = Path :: new ( & src_path_str) ;
166
+ let rustc_path = Path :: new ( & rustc_path_str) ;
123
167
let dest_path = Path :: new ( & dest_path_str) ;
124
168
125
169
let lang_features = collect_lang_features ( compiler_path, & mut false ) ;
@@ -128,6 +172,7 @@ fn main() {
128
172
. filter ( |& ( ref name, _) | !lang_features. contains_key ( name) )
129
173
. collect ( ) ;
130
174
let env_vars = collect_env_vars ( compiler_path) ;
175
+ let compiler_flags = collect_compiler_flags ( rustc_path) ;
131
176
132
177
let doc_src_path = src_path. join ( PATH_STR ) ;
133
178
@@ -143,9 +188,14 @@ fn main() {
143
188
& dest_path. join ( LIB_FEATURES_DIR ) ,
144
189
& lib_features,
145
190
) ;
191
+ generate_feature_files (
192
+ & doc_src_path. join ( COMPILER_FLAGS_DIR ) ,
193
+ & dest_path. join ( COMPILER_FLAGS_DIR ) ,
194
+ & compiler_flags,
195
+ ) ;
146
196
generate_env_files ( & doc_src_path. join ( ENV_VARS_DIR ) , & dest_path. join ( ENV_VARS_DIR ) , & env_vars) ;
147
197
148
198
copy_recursive ( & doc_src_path, & dest_path) ;
149
199
150
- generate_summary ( & dest_path, & lang_features, & lib_features) ;
200
+ generate_summary ( & dest_path, & lang_features, & lib_features, & compiler_flags ) ;
151
201
}
0 commit comments