@@ -4,11 +4,14 @@ use std::collections::BTreeSet;
44use std:: env;
55use std:: fs:: { self , write} ;
66use std:: path:: Path ;
7+ use std:: process:: Command ;
78
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+ } ;
912use tidy:: t;
1013use 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 ,
1215 collect_unstable_book_section_file_names, collect_unstable_feature_names,
1316} ;
1417
@@ -38,8 +41,15 @@ fn set_to_summary_str(set: &BTreeSet<String>, dir: &str) -> String {
3841 . fold ( "" . to_owned ( ) , |s, a| s + & a + "\n " )
3942}
4043
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) ;
4353 let compiler_env_vars =
4454 collect_unstable_book_section_file_names ( & path. join ( "src/compiler-environment-variables" ) ) ;
4555
@@ -112,14 +122,48 @@ fn copy_recursive(from: &Path, to: &Path) {
112122 }
113123}
114124
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+
115157fn main ( ) {
116158 let library_path_str = env:: args_os ( ) . nth ( 1 ) . expect ( "library/ path required" ) ;
117159 let compiler_path_str = env:: args_os ( ) . nth ( 2 ) . expect ( "compiler/ path required" ) ;
118160 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" ) ;
120163 let library_path = Path :: new ( & library_path_str) ;
121164 let compiler_path = Path :: new ( & compiler_path_str) ;
122165 let src_path = Path :: new ( & src_path_str) ;
166+ let rustc_path = Path :: new ( & rustc_path_str) ;
123167 let dest_path = Path :: new ( & dest_path_str) ;
124168
125169 let lang_features = collect_lang_features ( compiler_path, & mut false ) ;
@@ -128,6 +172,7 @@ fn main() {
128172 . filter ( |& ( ref name, _) | !lang_features. contains_key ( name) )
129173 . collect ( ) ;
130174 let env_vars = collect_env_vars ( compiler_path) ;
175+ let compiler_flags = collect_compiler_flags ( rustc_path) ;
131176
132177 let doc_src_path = src_path. join ( PATH_STR ) ;
133178
@@ -143,9 +188,14 @@ fn main() {
143188 & dest_path. join ( LIB_FEATURES_DIR ) ,
144189 & lib_features,
145190 ) ;
191+ generate_feature_files (
192+ & doc_src_path. join ( COMPILER_FLAGS_DIR ) ,
193+ & dest_path. join ( COMPILER_FLAGS_DIR ) ,
194+ & compiler_flags,
195+ ) ;
146196 generate_env_files ( & doc_src_path. join ( ENV_VARS_DIR ) , & dest_path. join ( ENV_VARS_DIR ) , & env_vars) ;
147197
148198 copy_recursive ( & doc_src_path, & dest_path) ;
149199
150- generate_summary ( & dest_path, & lang_features, & lib_features) ;
200+ generate_summary ( & dest_path, & lang_features, & lib_features, & compiler_flags ) ;
151201}
0 commit comments