@@ -23,6 +23,7 @@ use std::path::{Path, PathBuf};
23
23
24
24
pub use bstr;
25
25
pub use gimli;
26
+ pub use glob;
26
27
pub use object;
27
28
pub use regex;
28
29
pub use wasmparser;
@@ -223,6 +224,42 @@ pub fn bin_name(name: &str) -> String {
223
224
if is_windows ( ) { format ! ( "{name}.exe" ) } else { name. to_string ( ) }
224
225
}
225
226
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
+
226
263
/// Return the current working directory.
227
264
#[ must_use]
228
265
pub fn cwd ( ) -> PathBuf {
0 commit comments