@@ -23,6 +23,7 @@ use std::path::{Path, PathBuf};
2323
2424pub use bstr;
2525pub use gimli;
26+ pub use glob;
2627pub use object;
2728pub use regex;
2829pub use wasmparser;
@@ -223,6 +224,42 @@ pub fn bin_name(name: &str) -> String {
223224 if is_windows ( ) { format ! ( "{name}.exe" ) } else { name. to_string ( ) }
224225}
225226
227+ /// Remove all dynamic libraries possessing a name starting with `paths`.
228+ #[ track_caller]
229+ pub fn remove_dylibs ( paths : & str ) {
230+ let paths = format ! ( r"{paths}*" ) ;
231+ remove_glob ( dynamic_lib_name ( & paths) . as_str ( ) ) ;
232+ }
233+
234+ /// Remove all rust libraries possessing a name starting with `paths`.
235+ #[ track_caller]
236+ pub fn remove_rlibs ( paths : & str ) {
237+ let paths = format ! ( r"{paths}*" ) ;
238+ remove_glob ( rust_lib_name ( & paths) . as_str ( ) ) ;
239+ }
240+
241+ #[ track_caller]
242+ fn remove_glob ( paths : & str ) {
243+ let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
244+ paths
245+ . filter_map ( |entry| entry. ok ( ) )
246+ . filter ( |entry| entry. as_path ( ) . is_file ( ) )
247+ . for_each ( |file| fs_wrapper:: remove_file ( & file) ) ;
248+ }
249+
250+ #[ track_caller]
251+ fn count_glob ( paths : & str ) -> usize {
252+ let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
253+ paths. filter_map ( |entry| entry. ok ( ) ) . filter ( |entry| entry. as_path ( ) . is_file ( ) ) . count ( )
254+ }
255+
256+ /// Count the number of rust libraries possessing a name starting with `paths`.
257+ #[ track_caller]
258+ pub fn count_rlibs ( paths : & str ) -> usize {
259+ let paths = format ! ( r"{paths}*" ) ;
260+ count_glob ( rust_lib_name ( & paths) . as_str ( ) )
261+ }
262+
226263/// Return the current working directory.
227264#[ must_use]
228265pub fn cwd ( ) -> PathBuf {
0 commit comments