@@ -4,12 +4,13 @@ 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_lang_features, collect_lib_features} ;
9
+ use tidy:: features:: { Feature , Features , Status , collect_lang_features, collect_lib_features} ;
9
10
use tidy:: t;
10
11
use 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,
13
14
} ;
14
15
15
16
fn 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 {
33
34
. fold ( "" . to_owned ( ) , |s, a| s + & a + "\n " )
34
35
}
35
36
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) ;
38
46
let compiler_env_vars =
39
47
collect_unstable_book_section_file_names ( & path. join ( "src/compiler-environment-variables" ) ) ;
40
48
@@ -97,21 +105,55 @@ fn copy_recursive(from: &Path, to: &Path) {
97
105
}
98
106
}
99
107
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
+
100
139
fn main ( ) {
101
140
let library_path_str = env:: args_os ( ) . nth ( 1 ) . expect ( "library/ path required" ) ;
102
141
let compiler_path_str = env:: args_os ( ) . nth ( 2 ) . expect ( "compiler/ path required" ) ;
103
142
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" ) ;
105
145
let library_path = Path :: new ( & library_path_str) ;
106
146
let compiler_path = Path :: new ( & compiler_path_str) ;
107
147
let src_path = Path :: new ( & src_path_str) ;
148
+ let rustc_path = Path :: new ( & rustc_path_str) ;
108
149
let dest_path = Path :: new ( & dest_path_str) ;
109
150
110
151
let lang_features = collect_lang_features ( compiler_path, & mut false ) ;
111
152
let lib_features = collect_lib_features ( library_path)
112
153
. into_iter ( )
113
154
. filter ( |& ( ref name, _) | !lang_features. contains_key ( name) )
114
155
. collect ( ) ;
156
+ let compiler_flags = collect_compiler_flags ( rustc_path) ;
115
157
116
158
let doc_src_path = src_path. join ( PATH_STR ) ;
117
159
@@ -127,8 +169,13 @@ fn main() {
127
169
& dest_path. join ( LIB_FEATURES_DIR ) ,
128
170
& lib_features,
129
171
) ;
172
+ generate_unstable_book_files (
173
+ & doc_src_path. join ( COMPILER_FLAGS_DIR ) ,
174
+ & dest_path. join ( COMPILER_FLAGS_DIR ) ,
175
+ & compiler_flags,
176
+ ) ;
130
177
131
178
copy_recursive ( & doc_src_path, & dest_path) ;
132
179
133
- generate_summary ( & dest_path, & lang_features, & lib_features) ;
180
+ generate_summary ( & dest_path, & lang_features, & lib_features, & compiler_flags ) ;
134
181
}
0 commit comments