@@ -22,9 +22,9 @@ use std::panic;
2222use std:: path:: { Path , PathBuf } ;
2323
2424pub use gimli;
25- pub use glob;
2625pub use object;
2726pub use regex;
27+ pub use walkdir;
2828pub use wasmparser;
2929
3030pub use cc:: { cc, extra_c_flags, extra_cxx_flags, Cc } ;
@@ -209,40 +209,34 @@ pub fn bin_name(name: &str) -> String {
209209 if is_windows ( ) { format ! ( "{name}.exe" ) } else { name. to_string ( ) }
210210}
211211
212- /// Remove all dynamic libraries possessing a name starting with `paths`.
212+ /// Count the number of files in the current
213+ /// working directory possessing the extension `ext`.
213214#[ track_caller]
214- pub fn remove_dylibs ( paths : & str ) {
215- let paths = format ! ( r"{paths}*" ) ;
216- remove_glob ( dynamic_lib_name ( & paths) . as_str ( ) ) ;
217- }
215+ pub fn count_files_with_extension ( ext : & str ) -> usize {
216+ use walkdir:: { DirEntry , WalkDir } ;
218217
219- /// Remove all rust libraries possessing a name starting with `paths`.
220- #[ track_caller]
221- pub fn remove_rlibs ( paths : & str ) {
222- let paths = format ! ( r"{paths}*" ) ;
223- remove_glob ( rust_lib_name ( & paths) . as_str ( ) ) ;
224- }
218+ let walker = WalkDir :: new ( cwd ( ) ) . into_iter ( ) ;
225219
226- #[ track_caller]
227- fn remove_glob ( paths : & str ) {
228- let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
229- paths
230- . filter_map ( |entry| entry. ok ( ) )
231- . filter ( |entry| entry. as_path ( ) . is_file ( ) )
232- . for_each ( |file| fs_wrapper:: remove_file ( & file) ) ;
233- }
220+ fn is_hidden ( entry : & DirEntry ) -> bool {
221+ entry. file_name ( ) . to_str ( ) . map ( |s| s. starts_with ( "." ) ) . unwrap_or ( false )
222+ }
234223
235- #[ track_caller]
236- fn count_glob ( paths : & str ) -> usize {
237- let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
238- paths. filter_map ( |entry| entry. ok ( ) ) . filter ( |entry| entry. as_path ( ) . is_file ( ) ) . count ( )
239- }
224+ let mut count = 0 ;
240225
241- /// Count the number of rust libraries possessing a name starting with `paths`.
242- #[ track_caller]
243- pub fn count_rlibs ( paths : & str ) -> usize {
244- let paths = format ! ( r"{paths}*" ) ;
245- count_glob ( rust_lib_name ( & paths) . as_str ( ) )
226+ for entry in walker. filter_entry ( |e| !is_hidden ( e) ) {
227+ let entry = entry. expect ( "failed to get DirEntry" ) ;
228+ if !entry. path ( ) . is_file ( ) {
229+ continue ;
230+ }
231+
232+ if !entry. path ( ) . extension ( ) . is_some_and ( |e| e == ext) {
233+ continue ;
234+ }
235+
236+ count += 1 ;
237+ }
238+
239+ count
246240}
247241
248242/// Return the current working directory.
0 commit comments