Add shallow_find_files helper function to run-make-support

This commit is contained in:
Oneirical 2024-06-27 13:51:53 -04:00
parent b15e72a9ed
commit c9be69fd0a
3 changed files with 21 additions and 19 deletions

View File

@ -272,6 +272,7 @@ pub fn shallow_find_files<P: AsRef<Path>, F: Fn(&PathBuf) -> bool>(
for entry in fs_wrapper::read_dir(path) {
let entry = entry.expect("failed to read directory entry.");
let path = entry.path();
if path.is_file() && closure(&path) {
matching_files.push(path);
}

View File

@ -6,13 +6,13 @@
//@ needs-profiler-support
//@ ignore-cross-compile
use run_make_support::{cwd, find_files_by_prefix_and_extension, run, rustc};
use run_make_support::{cwd, has_extension, has_prefix, run, rustc, shallow_find_files};
fn main() {
rustc().arg("-g").profile_generate(cwd()).run();
rustc().arg("-g").profile_generate(cwd()).input("test.rs").run();
run("test");
assert!(
find_files_by_prefix_and_extension(cwd(), "default", "profraw").len() > 0,
"no .profraw file generated"
);
let profraw_files = shallow_find_files(cwd(), |path| {
has_prefix(path, "default") && has_extension(path, "profraw")
});
assert!(!profraw_files.is_empty(), "no .profraw file generated");
}

View File

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