@@ -4,12 +4,13 @@ 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_lang_features, collect_lib_features} ;
9+ use tidy:: features:: { Feature , Features , Status , collect_lang_features, collect_lib_features} ;
910use tidy:: t;
1011use tidy:: unstable_book:: {
11- LANG_FEATURES_DIR , LIB_FEATURES_DIR , PATH_STR , collect_unstable_book_section_file_names ,
12- collect_unstable_feature_names,
12+ COMPILER_FLAGS_DIR , LANG_FEATURES_DIR , LIB_FEATURES_DIR , PATH_STR ,
13+ collect_unstable_book_section_file_names , collect_unstable_feature_names,
1314} ;
1415
1516fn generate_stub_issue ( path : & Path , name : & str , issue : u32 , description : & str ) {
@@ -33,8 +34,15 @@ fn set_to_summary_str(set: &BTreeSet<String>, dir: &str) -> String {
3334 . fold ( "" . to_owned ( ) , |s, a| s + & a + "\n " )
3435}
3536
36- fn generate_summary ( path : & Path , lang_features : & Features , lib_features : & Features ) {
37- let compiler_flags = collect_unstable_book_section_file_names ( & path. join ( "src/compiler-flags" ) ) ;
37+ fn generate_summary (
38+ path : & Path ,
39+ lang_features : & Features ,
40+ lib_features : & Features ,
41+ compiler_flags : & Features ,
42+ ) {
43+ let compiler_flags =
44+ & collect_unstable_book_section_file_names ( & path. join ( "src/compiler-flags" ) )
45+ | & collect_unstable_feature_names ( & compiler_flags) ;
3846 let compiler_env_vars =
3947 collect_unstable_book_section_file_names ( & path. join ( "src/compiler-environment-variables" ) ) ;
4048
@@ -97,21 +105,55 @@ fn copy_recursive(from: &Path, to: &Path) {
97105 }
98106}
99107
108+ fn collect_compiler_flags ( rustc_path : impl AsRef < Path > ) -> Features {
109+ let mut rustc = Command :: new ( rustc_path. as_ref ( ) ) ;
110+ rustc. arg ( "-Zhelp" ) ;
111+
112+ let output = t ! ( rustc. output( ) ) ;
113+ let help_str = t ! ( String :: from_utf8( output. stdout) ) ;
114+ let parts = help_str. split ( "\n -Z" ) . collect :: < Vec < _ > > ( ) ;
115+
116+ let mut features = Features :: new ( ) ;
117+ for part in parts. into_iter ( ) . skip ( 1 ) {
118+ let ( name, description) =
119+ part. split_once ( "--" ) . expect ( "name and description should be delimited by '--'" ) ;
120+ let name = name. trim ( ) . trim_end_matches ( "=val" ) ;
121+ let description = description. trim ( ) ;
122+
123+ features. insert (
124+ name. replace ( '-' , "_" ) ,
125+ Feature {
126+ level : Status :: Unstable ,
127+ since : None ,
128+ has_gate_test : false ,
129+ tracking_issue : None ,
130+ file : "" . into ( ) ,
131+ line : 0 ,
132+ description : Some ( description. to_owned ( ) ) ,
133+ } ,
134+ ) ;
135+ }
136+ features
137+ }
138+
100139fn main ( ) {
101140 let library_path_str = env:: args_os ( ) . nth ( 1 ) . expect ( "library/ path required" ) ;
102141 let compiler_path_str = env:: args_os ( ) . nth ( 2 ) . expect ( "compiler/ path required" ) ;
103142 let src_path_str = env:: args_os ( ) . nth ( 3 ) . expect ( "src/ path required" ) ;
104- let dest_path_str = env:: args_os ( ) . nth ( 4 ) . expect ( "destination path required" ) ;
143+ let rustc_path_str = env:: args_os ( ) . nth ( 4 ) . expect ( "rustc path required" ) ;
144+ let dest_path_str = env:: args_os ( ) . nth ( 5 ) . expect ( "destination path required" ) ;
105145 let library_path = Path :: new ( & library_path_str) ;
106146 let compiler_path = Path :: new ( & compiler_path_str) ;
107147 let src_path = Path :: new ( & src_path_str) ;
148+ let rustc_path = Path :: new ( & rustc_path_str) ;
108149 let dest_path = Path :: new ( & dest_path_str) ;
109150
110151 let lang_features = collect_lang_features ( compiler_path, & mut false ) ;
111152 let lib_features = collect_lib_features ( library_path)
112153 . into_iter ( )
113154 . filter ( |& ( ref name, _) | !lang_features. contains_key ( name) )
114155 . collect ( ) ;
156+ let compiler_flags = collect_compiler_flags ( rustc_path) ;
115157
116158 let doc_src_path = src_path. join ( PATH_STR ) ;
117159
@@ -127,8 +169,13 @@ fn main() {
127169 & dest_path. join ( LIB_FEATURES_DIR ) ,
128170 & lib_features,
129171 ) ;
172+ generate_unstable_book_files (
173+ & doc_src_path. join ( COMPILER_FLAGS_DIR ) ,
174+ & dest_path. join ( COMPILER_FLAGS_DIR ) ,
175+ & compiler_flags,
176+ ) ;
130177
131178 copy_recursive ( & doc_src_path, & dest_path) ;
132179
133- generate_summary ( & dest_path, & lang_features, & lib_features) ;
180+ generate_summary ( & dest_path, & lang_features, & lib_features, & compiler_flags ) ;
134181}
0 commit comments