@@ -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,47 @@ 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
+
133
+ let mut features = Features :: new ( ) ;
134
+ for part in parts. into_iter ( ) . skip ( 1 ) {
135
+ let ( name, description) =
136
+ part. split_once ( "--" ) . expect ( "name and description should be delimited by '--'" ) ;
137
+ let name = name. trim ( ) . trim_end_matches ( "=val" ) ;
138
+ let description = description. trim ( ) ;
139
+
140
+ features. insert (
141
+ name. replace ( '-' , "_" ) ,
142
+ Feature {
143
+ level : Status :: Unstable ,
144
+ since : None ,
145
+ has_gate_test : false ,
146
+ tracking_issue : None ,
147
+ file : "" . into ( ) ,
148
+ line : 0 ,
149
+ description : Some ( description. to_owned ( ) ) ,
150
+ } ,
151
+ ) ;
152
+ }
153
+ features
154
+ }
155
+
115
156
fn main ( ) {
116
157
let library_path_str = env:: args_os ( ) . nth ( 1 ) . expect ( "library/ path required" ) ;
117
158
let compiler_path_str = env:: args_os ( ) . nth ( 2 ) . expect ( "compiler/ path required" ) ;
118
159
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" ) ;
160
+ let rustc_path_str = env:: args_os ( ) . nth ( 4 ) . expect ( "rustc path required" ) ;
161
+ let dest_path_str = env:: args_os ( ) . nth ( 5 ) . expect ( "destination path required" ) ;
120
162
let library_path = Path :: new ( & library_path_str) ;
121
163
let compiler_path = Path :: new ( & compiler_path_str) ;
122
164
let src_path = Path :: new ( & src_path_str) ;
165
+ let rustc_path = Path :: new ( & rustc_path_str) ;
123
166
let dest_path = Path :: new ( & dest_path_str) ;
124
167
125
168
let lang_features = collect_lang_features ( compiler_path, & mut false ) ;
@@ -128,6 +171,7 @@ fn main() {
128
171
. filter ( |& ( ref name, _) | !lang_features. contains_key ( name) )
129
172
. collect ( ) ;
130
173
let env_vars = collect_env_vars ( compiler_path) ;
174
+ let compiler_flags = collect_compiler_flags ( rustc_path) ;
131
175
132
176
let doc_src_path = src_path. join ( PATH_STR ) ;
133
177
@@ -143,9 +187,14 @@ fn main() {
143
187
& dest_path. join ( LIB_FEATURES_DIR ) ,
144
188
& lib_features,
145
189
) ;
190
+ generate_feature_files (
191
+ & doc_src_path. join ( COMPILER_FLAGS_DIR ) ,
192
+ & dest_path. join ( COMPILER_FLAGS_DIR ) ,
193
+ & compiler_flags,
194
+ ) ;
146
195
generate_env_files ( & doc_src_path. join ( ENV_VARS_DIR ) , & dest_path. join ( ENV_VARS_DIR ) , & env_vars) ;
147
196
148
197
copy_recursive ( & doc_src_path, & dest_path) ;
149
198
150
- generate_summary ( & dest_path, & lang_features, & lib_features) ;
199
+ generate_summary ( & dest_path, & lang_features, & lib_features, & compiler_flags ) ;
151
200
}
0 commit comments