Skip to content

Commit 2a76e63

Browse files
committed
rewrite pgo-gen to rmake
1 parent d929a42 commit 2a76e63

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,34 @@ pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>
247247
success.unwrap();
248248
}
249249

250+
/// Browse the directory `path` non-recursively and return the first file path which starts with `prefix` and has the
251+
/// file extension `extension`.
252+
#[track_caller]
253+
pub fn find_files_by_prefix_and_extension<P: AsRef<Path>>(
254+
path: P,
255+
prefix: &str,
256+
extension: &str,
257+
) -> Vec<PathBuf> {
258+
let mut matching_files = Vec::new();
259+
for entry in fs_wrapper::read_dir(path) {
260+
let entry = entry.expect("failed to read directory entry.");
261+
let path = entry.path();
262+
263+
if path.is_file()
264+
&& path.file_name().unwrap().to_str().unwrap().starts_with(prefix)
265+
&& path.extension().unwrap().to_str().unwrap() == extension
266+
{
267+
matching_files.push(path);
268+
}
269+
}
270+
271+
if matching_files.is_empty() {
272+
panic!("no files found with the given prefix and extension");
273+
} else {
274+
matching_files
275+
}
276+
}
277+
250278
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
251279
/// available on the platform!
252280
#[track_caller]

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ run-make/pdb-alt-path/Makefile
132132
run-make/pdb-buildinfo-cl-cmd/Makefile
133133
run-make/pgo-gen-lto/Makefile
134134
run-make/pgo-gen-no-imp-symbols/Makefile
135-
run-make/pgo-gen/Makefile
136135
run-make/pgo-indirect-call-promotion/Makefile
137136
run-make/pgo-use/Makefile
138137
run-make/pointer-auth-link-with-c/Makefile

tests/run-make/pgo-gen/Makefile

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// -C profile-generate, when used with rustc, is supposed to output
2+
// profile files (.profraw) after running a binary to analyze how the compiler
3+
// optimizes code. This test checks that these files are generated.
4+
// See https://github.com/rust-lang/rust/pull/48346
5+
6+
//@ needs-profiler-support
7+
//@ ignore-cross-compile
8+
9+
use run_make_support::{cwd, find_files_by_prefix_and_extension, run, rustc};
10+
11+
fn main() {
12+
rustc().arg("-g").profile_generate(cwd()).run();
13+
run("test");
14+
assert!(
15+
find_files_by_prefix_and_extension(cwd(), "default", "profraw").len() > 0,
16+
"no .profraw file generated"
17+
);
18+
}

0 commit comments

Comments
 (0)