Skip to content

Commit cbc62cb

Browse files
committed
shallow_find_files function for run_make_support
1 parent ece7d98 commit cbc62cb

File tree

4 files changed

+14
-45
lines changed

4 files changed

+14
-45
lines changed

src/tools/run-make-support/src/lib.rs

-37
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::path::{Path, PathBuf};
2323

2424
pub use bstr;
2525
pub use gimli;
26-
pub use glob;
2726
pub use object;
2827
pub use regex;
2928
pub use wasmparser;
@@ -224,42 +223,6 @@ pub fn bin_name(name: &str) -> String {
224223
if is_windows() { format!("{name}.exe") } else { name.to_string() }
225224
}
226225

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-
263226
/// Return the current working directory.
264227
#[must_use]
265228
pub fn cwd() -> PathBuf {

tests/run-make/lib-trait-for-trait-no-ice/rmake.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
// the lib crate-type flag was actually followed.
66
// See https://github.com/rust-lang/rust/issues/18943
77

8-
use run_make_support::{count_rlibs, rustc};
8+
use run_make_support::{rust_lib_name, rustc};
9+
use std::path::Path;
910

1011
fn main() {
1112
rustc().input("foo.rs").crate_type("lib").run();
12-
assert_eq!(count_rlibs("foo"), 1);
13+
assert!(Path::new(&rust_lib_name("foo")).exists());
1314
}

tests/run-make/mixing-libs/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
//@ ignore-cross-compile
88

9-
use run_make_support::{remove_dylibs, rustc};
9+
use run_make_support::{dynamic_lib_name, fs_wrapper, rustc};
1010

1111
fn main() {
1212
rustc().input("rlib.rs").crate_type("rlib").crate_type("dylib").run();
@@ -16,6 +16,6 @@ fn main() {
1616

1717
// librlib's dynamic version needs to be removed here to prevent prog.rs from fetching
1818
// the wrong one.
19-
remove_dylibs("rlib");
19+
fs_wrapper::remove_file(dynamic_lib_name("rlib"));
2020
rustc().input("prog.rs").run_fail();
2121
}

tests/run-make/obey-crate-type-flag/rmake.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55

66
//@ ignore-cross-compile
77

8-
use run_make_support::{count_rlibs, remove_dylibs, remove_rlibs, rustc};
8+
use run_make_support::{
9+
cwd, dynamic_lib_name, fs_wrapper, has_extension, rust_lib_name, rustc, shallow_find_files,
10+
};
11+
use std::path::Path;
912

1013
fn main() {
1114
rustc().input("test.rs").run();
12-
remove_rlibs("test");
13-
remove_dylibs("test");
15+
assert!(Path::new(&dynamic_lib_name("test")).exists());
16+
assert!(Path::new(&rust_lib_name("test")).exists());
17+
18+
fs_wrapper::remove_file(rust_lib_name("test"));
1419
rustc().crate_type("dylib").input("test.rs").run();
15-
assert_eq!(count_rlibs("test"), 0);
20+
assert!(shallow_find_files(cwd(), |path| { has_extension(path, "rlib") }).is_empty());
1621
}

0 commit comments

Comments
 (0)