Skip to content

Commit

Permalink
remove glob and refactor accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 17, 2024
1 parent 98ea1f7 commit 261197e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 43 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3461,7 +3461,6 @@ name = "run_make_support"
version = "0.2.0"
dependencies = [
"gimli 0.28.1",
"glob",
"object 0.34.0",
"regex",
"similar",
Expand Down
1 change: 0 additions & 1 deletion src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ similar = "2.5.0"
wasmparser = "0.118.2"
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
gimli = "0.28.1"
glob = "0.3.1"
40 changes: 7 additions & 33 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use std::panic;
use std::path::{Path, PathBuf};

pub use gimli;
pub use glob;
pub use object;
pub use regex;
pub use wasmparser;
Expand Down Expand Up @@ -209,40 +208,15 @@ pub fn bin_name(name: &str) -> String {
if is_windows() { format!("{name}.exe") } else { name.to_string() }
}

/// Remove all dynamic libraries possessing a name starting with `paths`.
/// Count the number of files in the current
/// working directory possessing the extension `ext`.
#[track_caller]
pub fn remove_dylibs(paths: &str) {
let paths = format!(r"{paths}*");
remove_glob(dynamic_lib_name(&paths).as_str());
}

/// Remove all rust libraries possessing a name starting with `paths`.
#[track_caller]
pub fn remove_rlibs(paths: &str) {
let paths = format!(r"{paths}*");
remove_glob(rust_lib_name(&paths).as_str());
}

#[track_caller]
fn remove_glob(paths: &str) {
let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
paths
pub fn count_files_with_extension(ext: &str) -> usize {
fs_wrapper::read_dir(cwd())
.filter_map(|entry| entry.ok())
.filter(|entry| entry.as_path().is_file())
.for_each(|file| fs_wrapper::remove_file(&file));
}

#[track_caller]
fn count_glob(paths: &str) -> usize {
let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
paths.filter_map(|entry| entry.ok()).filter(|entry| entry.as_path().is_file()).count()
}

/// Count the number of rust libraries possessing a name starting with `paths`.
#[track_caller]
pub fn count_rlibs(paths: &str) -> usize {
let paths = format!(r"{paths}*");
count_glob(rust_lib_name(&paths).as_str())
.filter(|entry| entry.path().is_file())
.filter(|entry| entry.path().extension().unwrap() == ext)
.count()
}

/// Return the current working directory.
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/lib-trait-for-trait-no-ice/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// the lib crate-type flag was actually followed.
// See https://github.com/rust-lang/rust/issues/18943

use run_make_support::{count_rlibs, rustc};
use run_make_support::{fs_wrapper, rust_lib_name, rustc};

fn main() {
rustc().input("foo.rs").crate_type("lib").run();
assert_eq!(count_rlibs("foo"), 1);
fs_wrapper::remove_file(rust_lib_name("foo"));
}
4 changes: 2 additions & 2 deletions tests/run-make/mixing-libs/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

//@ ignore-cross-compile

use run_make_support::{remove_dylibs, rustc};
use run_make_support::{dynamic_lib_name, fs_wrapper, rustc};

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

// librlib's dynamic version needs to be removed here to prevent prog.rs from fetching
// the wrong one.
remove_dylibs("rlib");
fs_wrapper::remove_file(dynamic_lib_name("rlib"));
rustc().input("prog.rs").run_fail();
}
10 changes: 6 additions & 4 deletions tests/run-make/obey-crate-type-flag/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

//@ ignore-cross-compile

use run_make_support::{count_rlibs, remove_dylibs, remove_rlibs, rustc};
use run_make_support::{
count_files_with_extension, dynamic_lib_name, fs_wrapper, rust_lib_name, rustc,
};

fn main() {
rustc().input("test.rs").run();
remove_rlibs("test");
remove_dylibs("test");
fs_wrapper::remove_file(dynamic_lib_name("test"));
fs_wrapper::remove_file(rust_lib_name("test"));
rustc().crate_type("dylib").input("test.rs").run();
assert_eq!(count_rlibs("test"), 0);
assert_eq!(count_files_with_extension("rlib"), 0);
}

0 comments on commit 261197e

Please sign in to comment.