Skip to content

Commit cbf8157

Browse files
committed
Rework count function without glob
1 parent 348c183 commit cbf8157

File tree

6 files changed

+20
-17
lines changed

6 files changed

+20
-17
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3461,7 +3461,6 @@ name = "run_make_support"
34613461
version = "0.2.0"
34623462
dependencies = [
34633463
"gimli 0.28.1",
3464-
"glob",
34653464
"object 0.34.0",
34663465
"regex",
34673466
"similar",

src/tools/run-make-support/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ similar = "2.5.0"
99
wasmparser = "0.118.2"
1010
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
1111
gimli = "0.28.1"
12-
glob = "0.3.1"

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::panic;
2222
use std::path::{Path, PathBuf};
2323

2424
pub use gimli;
25-
pub use glob;
2625
pub use object;
2726
pub use regex;
2827
pub use wasmparser;
@@ -248,14 +247,14 @@ pub fn uname() -> String {
248247
/// Inside a glob pattern of files (paths), read their contents and count the
249248
/// number of regex matches with a given expression (re).
250249
#[track_caller]
251-
pub fn count_regex_matches_in_file_glob(re: &str, paths: &str) -> usize {
250+
pub fn count_regex_matches_in_files_with_extension(re: &str, ext: &str) -> usize {
252251
let re = regex::Regex::new(re).expect(format!("Regex expression {re} is not valid.").as_str());
253-
let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
254252
use io::BufRead;
255-
paths
253+
fs_wrapper::read_dir(cwd())
256254
.filter_map(|entry| entry.ok())
257-
.filter(|entry| entry.as_path().is_file())
258-
.filter_map(|path| fs::File::open(&path).ok())
255+
.filter(|entry| entry.path().is_file())
256+
.filter(|entry| entry.path().extension().unwrap() == ext)
257+
.filter_map(|entry| fs::File::open(&entry.path()).ok())
259258
.map(|file| io::BufReader::new(file))
260259
.flat_map(|reader| reader.lines().filter_map(|entry| entry.ok()))
261260
.filter(|line| re.is_match(line))

tests/run-make/sepcomp-cci-copies/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// created for each source module (see `rustc_const_eval::monomorphize::partitioning`).
55
// See https://github.com/rust-lang/rust/pull/16367
66

7-
use run_make_support::{count_regex_matches_in_file_glob, rustc};
7+
use run_make_support::{count_regex_matches_in_files_with_extension, rustc};
88

99
fn main() {
1010
rustc().input("cci_lib.rs").run();
1111
rustc().input("foo.rs").emit("llvm-ir").codegen_units(6).arg("-Zinline-in-all-cgus").run();
12-
assert_eq!(count_regex_matches_in_file_glob(r#"define\ .*cci_fn"#, "foo.*.ll"), 2);
12+
assert_eq!(count_regex_matches_in_files_with_extension(r#"define\ .*cci_fn"#, "ll"), 2);
1313
}

tests/run-make/sepcomp-inlining/rmake.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
// in only one compilation unit.
66
// See https://github.com/rust-lang/rust/pull/16367
77

8-
use run_make_support::{count_regex_matches_in_file_glob, glob, regex, rustc};
8+
use run_make_support::{count_regex_matches_in_files_with_extension, glob, regex, rustc};
99

1010
fn main() {
1111
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).arg("-Zinline-in-all-cgus").run();
12-
assert_eq!(count_regex_matches_in_file_glob(r#"define\ i32\ .*inlined"#, "foo.*.ll"), 0);
13-
assert_eq!(count_regex_matches_in_file_glob(r#"define\ internal\ .*inlined"#, "foo.*.ll"), 2);
14-
assert_eq!(count_regex_matches_in_file_glob(r#"define\ hidden\ i32\ .*normal"#, "foo.*.ll"), 1);
12+
assert_eq!(count_regex_matches_in_files_with_extension(r#"define\ i32\ .*inlined"#, "ll"), 0);
1513
assert_eq!(
16-
count_regex_matches_in_file_glob(r#"declare\ hidden\ i32\ .*normal"#, "foo.*.ll"),
14+
count_regex_matches_in_files_with_extension(r#"define\ internal\ .*inlined"#, "ll"),
15+
2
16+
);
17+
assert_eq!(
18+
count_regex_matches_in_files_with_extension(r#"define\ hidden\ i32\ .*normal"#, "ll"),
19+
1
20+
);
21+
assert_eq!(
22+
count_regex_matches_in_files_with_extension(r#"declare\ hidden\ i32\ .*normal"#, "ll"),
1723
2
1824
);
1925
}

tests/run-make/sepcomp-separate/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// wind up in three different compilation units.
44
// See https://github.com/rust-lang/rust/pull/16367
55

6-
use run_make_support::{count_regex_matches_in_file_glob, rustc};
6+
use run_make_support::{count_regex_matches_in_files_with_extension, rustc};
77

88
fn main() {
99
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).run();
10-
assert_eq!(count_regex_matches_in_file_glob(r#"define\ .*magic_fn"#, "foo.*.ll"), 3);
10+
assert_eq!(count_regex_matches_in_files_with_extension(r#"define\ .*magic_fn"#, "ll"), 3);
1111
}

0 commit comments

Comments
 (0)