Skip to content

Commit c9be69f

Browse files
committed
Add shallow_find_files helper function to run-make-support
1 parent b15e72a commit c9be69f

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ pub fn shallow_find_files<P: AsRef<Path>, F: Fn(&PathBuf) -> bool>(
272272
for entry in fs_wrapper::read_dir(path) {
273273
let entry = entry.expect("failed to read directory entry.");
274274
let path = entry.path();
275+
275276
if path.is_file() && closure(&path) {
276277
matching_files.push(path);
277278
}

tests/run-make/pgo-gen/rmake.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
//@ needs-profiler-support
77
//@ ignore-cross-compile
88

9-
use run_make_support::{cwd, find_files_by_prefix_and_extension, run, rustc};
9+
use run_make_support::{cwd, has_extension, has_prefix, run, rustc, shallow_find_files};
1010

1111
fn main() {
12-
rustc().arg("-g").profile_generate(cwd()).run();
12+
rustc().arg("-g").profile_generate(cwd()).input("test.rs").run();
1313
run("test");
14-
assert!(
15-
find_files_by_prefix_and_extension(cwd(), "default", "profraw").len() > 0,
16-
"no .profraw file generated"
17-
);
14+
let profraw_files = shallow_find_files(cwd(), |path| {
15+
has_prefix(path, "default") && has_extension(path, "profraw")
16+
});
17+
assert!(!profraw_files.is_empty(), "no .profraw file generated");
1818
}

tests/run-make/pgo-use/rmake.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//@ ignore-cross-compile
1010

1111
use run_make_support::{
12-
cwd, find_files_by_prefix_and_extension, fs_wrapper, llvm_filecheck, llvm_profdata,
13-
run_with_args, rustc,
12+
cwd, fs_wrapper, has_extension, has_prefix, llvm_filecheck, llvm_profdata, run_with_args,
13+
rustc, shallow_find_files,
1414
};
1515

1616
fn main() {
@@ -28,11 +28,11 @@ fn main() {
2828
// Run it in order to generate some profiling data
2929
run_with_args("main", &["some-argument"]);
3030
// Postprocess the profiling data so it can be used by the compiler
31-
llvm_profdata()
32-
.merge()
33-
.output("merged.profdata")
34-
.input(find_files_by_prefix_and_extension(cwd(), "default", "profraw").get(0).unwrap())
35-
.run();
31+
let profraw_files = shallow_find_files(cwd(), |path| {
32+
has_prefix(path, "default") && has_extension(path, "profraw")
33+
});
34+
let profraw_file = profraw_files.get(0).unwrap();
35+
llvm_profdata().merge().output("merged.profdata").input(profraw_file).run();
3636
// Compile the test program again, making use of the profiling data
3737
rustc()
3838
.opt_level("2")
@@ -42,13 +42,14 @@ fn main() {
4242
.emit("llvm-ir")
4343
.input("main.rs")
4444
.run();
45-
// Check that the generate IR contains some things that we expect
46-
//
47-
// We feed the file into LLVM FileCheck tool *in reverse* so that we see the
45+
// Check that the generate IR contains some things that we expect.
46+
// We feed the file into LLVM FileCheck tool *with its lines reversed* so that we see the
4847
// line with the function name before the line with the function attributes.
4948
// FileCheck only supports checking that something matches on the next line,
5049
// but not if something matches on the previous line.
51-
let mut bytes = fs_wrapper::read("interesting.ll");
52-
bytes.reverse();
53-
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(bytes).run();
50+
let ir = fs_wrapper::read_to_string("main.ll");
51+
let lines: Vec<_> = ir.lines().rev().collect();
52+
let mut reversed_ir = lines.join("\n");
53+
reversed_ir.push('\n');
54+
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(reversed_ir.as_bytes()).run();
5455
}

0 commit comments

Comments
 (0)