@@ -14,7 +14,6 @@ use watchman_client::prelude::*;
14
14
15
15
use crate :: compiler_state:: ProjectSet ;
16
16
use crate :: config:: Config ;
17
- use crate :: config:: SchemaLocation ;
18
17
19
18
type FnvIndexMap < K , V > = IndexMap < K , V , FnvBuildHasher > ;
20
19
@@ -45,28 +44,28 @@ pub fn get_watchman_expr(config: &Config) -> Expr {
45
44
expressions. push ( expr_any ( generated_sources_dir_exprs) ) ;
46
45
}
47
46
48
- let output_dir_paths = get_output_dir_paths ( config ) ;
47
+ let output_dir_paths = config . get_output_dir_paths ( ) ;
49
48
if !output_dir_paths. is_empty ( ) {
50
49
let output_dir_expr = expr_files_in_dirs ( output_dir_paths) ;
51
50
expressions. push ( output_dir_expr) ;
52
51
}
53
52
54
- let schema_file_paths = get_schema_file_paths ( config ) ;
53
+ let schema_file_paths = config . get_schema_file_paths ( ) ;
55
54
if !schema_file_paths. is_empty ( ) {
56
55
let schema_file_expr = Expr :: Name ( NameTerm {
57
- paths : get_schema_file_paths ( config ) ,
56
+ paths : config . get_schema_file_paths ( ) ,
58
57
wholename : true ,
59
58
} ) ;
60
59
expressions. push ( schema_file_expr) ;
61
60
}
62
61
63
- let schema_dir_paths = get_schema_dir_paths ( config ) ;
62
+ let schema_dir_paths = config . get_schema_dir_paths ( ) ;
64
63
if !schema_dir_paths. is_empty ( ) {
65
64
let schema_dir_expr = expr_graphql_files_in_dirs ( schema_dir_paths) ;
66
65
expressions. push ( schema_dir_expr) ;
67
66
}
68
67
69
- let extension_roots = get_extension_roots ( config ) ;
68
+ let extension_roots = config . get_extension_roots ( ) ;
70
69
if !extension_roots. is_empty ( ) {
71
70
let extensions_expr = expr_graphql_files_in_dirs ( extension_roots) ;
72
71
expressions. push ( extensions_expr) ;
@@ -122,98 +121,6 @@ fn get_project_file_ext_expr(typegen_language: TypegenLanguage) -> Expr {
122
121
} )
123
122
}
124
123
125
- /// Compute all root paths that we need to query Watchman with. All files
126
- /// relevant to the compiler should be in these directories.
127
- pub fn get_all_roots ( config : & Config ) -> Vec < PathBuf > {
128
- let source_roots = get_source_roots ( config) ;
129
- let extra_sources_roots = get_generated_sources_roots ( config) ;
130
- let output_roots = get_output_dir_paths ( config) ;
131
- let extension_roots = get_extension_roots ( config) ;
132
- let schema_file_roots = get_schema_file_roots ( config) ;
133
- let schema_dir_roots = get_schema_dir_paths ( config) ;
134
- unify_roots (
135
- source_roots
136
- . into_iter ( )
137
- . chain ( extra_sources_roots)
138
- . chain ( output_roots)
139
- . chain ( extension_roots)
140
- . chain ( schema_file_roots)
141
- . chain ( schema_dir_roots)
142
- . collect ( ) ,
143
- )
144
- }
145
-
146
- /// Returns all root directories of JS source files for the config.
147
- fn get_source_roots ( config : & Config ) -> Vec < PathBuf > {
148
- config. sources . keys ( ) . cloned ( ) . collect ( )
149
- }
150
-
151
- /// Returns all root directories of JS source files for the config.
152
- fn get_generated_sources_roots ( config : & Config ) -> Vec < PathBuf > {
153
- config. generated_sources . keys ( ) . cloned ( ) . collect ( )
154
- }
155
-
156
- /// Returns all root directories of GraphQL schema extension files for the
157
- /// config.
158
- fn get_extension_roots ( config : & Config ) -> Vec < PathBuf > {
159
- config
160
- . projects
161
- . values ( )
162
- . flat_map ( |project_config| project_config. schema_extensions . iter ( ) . cloned ( ) )
163
- . collect ( )
164
- }
165
-
166
- /// Returns all output and extra artifact output directories for the config.
167
- fn get_output_dir_paths ( config : & Config ) -> Vec < PathBuf > {
168
- let output_dirs = config
169
- . projects
170
- . values ( )
171
- . filter_map ( |project_config| project_config. output . clone ( ) ) ;
172
-
173
- let extra_artifact_output_dirs = config
174
- . projects
175
- . values ( )
176
- . filter_map ( |project_config| project_config. extra_artifacts_output . clone ( ) ) ;
177
-
178
- output_dirs. chain ( extra_artifact_output_dirs) . collect ( )
179
- }
180
-
181
- /// Returns all paths that contain GraphQL schema files for the config.
182
- fn get_schema_file_paths ( config : & Config ) -> Vec < PathBuf > {
183
- config
184
- . projects
185
- . values ( )
186
- . filter_map ( |project_config| match & project_config. schema_location {
187
- SchemaLocation :: File ( schema_file) => Some ( schema_file. clone ( ) ) ,
188
- SchemaLocation :: Directory ( _) => None ,
189
- } )
190
- . collect ( )
191
- }
192
-
193
- /// Returns all GraphQL schema directories for the config.
194
- fn get_schema_dir_paths ( config : & Config ) -> Vec < PathBuf > {
195
- config
196
- . projects
197
- . values ( )
198
- . filter_map ( |project_config| match & project_config. schema_location {
199
- SchemaLocation :: File ( _) => None ,
200
- SchemaLocation :: Directory ( schema_dir) => Some ( schema_dir. clone ( ) ) ,
201
- } )
202
- . collect ( )
203
- }
204
-
205
- /// Returns root directories that contain GraphQL schema files.
206
- fn get_schema_file_roots ( config : & Config ) -> impl Iterator < Item = PathBuf > {
207
- get_schema_file_paths ( config)
208
- . into_iter ( )
209
- . map ( |schema_path| {
210
- schema_path
211
- . parent ( )
212
- . expect ( "A schema in the project root directory is currently not supported." )
213
- . to_owned ( )
214
- } )
215
- }
216
-
217
124
fn expr_files_in_dirs ( roots : Vec < PathBuf > ) -> Expr {
218
125
expr_any (
219
126
roots
@@ -244,47 +151,3 @@ fn expr_any(expressions: Vec<Expr>) -> Expr {
244
151
_ => Expr :: Any ( expressions) ,
245
152
}
246
153
}
247
-
248
- /// Finds the roots of a set of paths. This filters any paths
249
- /// that are a subdirectory of other paths in the input.
250
- fn unify_roots ( mut paths : Vec < PathBuf > ) -> Vec < PathBuf > {
251
- paths. sort ( ) ;
252
- let mut roots = Vec :: new ( ) ;
253
- for path in paths {
254
- match roots. last ( ) {
255
- Some ( prev) if path. starts_with ( prev) => {
256
- // skip
257
- }
258
- _ => {
259
- roots. push ( path) ;
260
- }
261
- }
262
- }
263
- roots
264
- }
265
-
266
- #[ cfg( test) ]
267
- mod test {
268
- use super :: * ;
269
-
270
- #[ test]
271
- fn test_unify_roots ( ) {
272
- assert_eq ! ( unify_roots( vec![ ] ) . len( ) , 0 ) ;
273
- assert_eq ! (
274
- unify_roots( vec![ "Apps" . into( ) , "Libraries" . into( ) ] ) ,
275
- & [ PathBuf :: from( "Apps" ) , PathBuf :: from( "Libraries" ) ]
276
- ) ;
277
- assert_eq ! (
278
- unify_roots( vec![ "Apps" . into( ) , "Apps/Foo" . into( ) ] ) ,
279
- & [ PathBuf :: from( "Apps" ) ]
280
- ) ;
281
- assert_eq ! (
282
- unify_roots( vec![ "Apps/Foo" . into( ) , "Apps" . into( ) ] ) ,
283
- & [ PathBuf :: from( "Apps" ) ]
284
- ) ;
285
- assert_eq ! (
286
- unify_roots( vec![ "Foo" . into( ) , "Foo2" . into( ) ] ) ,
287
- & [ PathBuf :: from( "Foo" ) , PathBuf :: from( "Foo2" ) , ]
288
- ) ;
289
- }
290
- }
0 commit comments