Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6eab187

Browse files
committedJul 3, 2024
Auto merge of #126709 - Oneirical:exitestial-crisis, r=<try>
Migrate `include_bytes_deps`, `optimization-remarks-dir-pgo`, `optimization-remarks-dir`, `issue-40535` and `rmeta-preferred` `run-make` tests to rmake Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). Needs BSD tryjob. try-job: aarch64-apple try-job: x86_64-msvc try-job: armhf-gnu try-job: test-various
2 parents c872a14 + 2496742 commit 6eab187

File tree

19 files changed

+159
-70
lines changed

19 files changed

+159
-70
lines changed
 

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

+34
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,40 @@ pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>
261261
success.unwrap();
262262
}
263263

264+
/// Browse the directory `path` non-recursively and return all files which respect the parameters
265+
/// outlined by `closure`.
266+
#[track_caller]
267+
pub fn shallow_find_files<P: AsRef<Path>, F: Fn(&PathBuf) -> bool>(
268+
path: P,
269+
closure: F,
270+
) -> Vec<PathBuf> {
271+
let mut matching_files = Vec::new();
272+
for entry in fs_wrapper::read_dir(path) {
273+
let entry = entry.expect("failed to read directory entry.");
274+
let path = entry.path();
275+
276+
if path.is_file() && closure(&path) {
277+
matching_files.push(path);
278+
}
279+
}
280+
matching_files
281+
}
282+
283+
/// Returns true if the filename at `path` starts with `prefix`.
284+
pub fn has_prefix<P: AsRef<Path>>(path: P, prefix: &str) -> bool {
285+
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().starts_with(prefix))
286+
}
287+
288+
/// Returns true if the filename at `path` has the extension `extension`.
289+
pub fn has_extension<P: AsRef<Path>>(path: P, extension: &str) -> bool {
290+
path.as_ref().extension().is_some_and(|ext| ext == extension)
291+
}
292+
293+
/// Returns true if the filename at `path` does not contain `expected`.
294+
pub fn not_contains<P: AsRef<Path>>(path: P, expected: &str) -> bool {
295+
!path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected))
296+
}
297+
264298
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
265299
/// available on the platform!
266300
#[track_caller]

‎src/tools/tidy/src/allowed_run_make_makefiles.txt

-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ run-make/fmt-write-bloat/Makefile
4747
run-make/foreign-double-unwind/Makefile
4848
run-make/foreign-exceptions/Makefile
4949
run-make/foreign-rust-exceptions/Makefile
50-
run-make/include_bytes_deps/Makefile
5150
run-make/incr-add-rust-src-component/Makefile
5251
run-make/incr-foreign-head-span/Makefile
5352
run-make/interdependent-c-libraries/Makefile
@@ -65,7 +64,6 @@ run-make/issue-33329/Makefile
6564
run-make/issue-35164/Makefile
6665
run-make/issue-36710/Makefile
6766
run-make/issue-37839/Makefile
68-
run-make/issue-40535/Makefile
6967
run-make/issue-47384/Makefile
7068
run-make/issue-47551/Makefile
7169
run-make/issue-69368/Makefile
@@ -105,8 +103,6 @@ run-make/no-alloc-shim/Makefile
105103
run-make/no-builtins-attribute/Makefile
106104
run-make/no-duplicate-libs/Makefile
107105
run-make/obey-crate-type-flag/Makefile
108-
run-make/optimization-remarks-dir-pgo/Makefile
109-
run-make/optimization-remarks-dir/Makefile
110106
run-make/output-type-permutations/Makefile
111107
run-make/panic-abort-eh_frame/Makefile
112108
run-make/pass-linker-flags-flavor/Makefile
@@ -140,7 +136,6 @@ run-make/rlib-chain/Makefile
140136
run-make/rlib-format-packed-bundled-libs-2/Makefile
141137
run-make/rlib-format-packed-bundled-libs-3/Makefile
142138
run-make/rlib-format-packed-bundled-libs/Makefile
143-
run-make/rmeta-preferred/Makefile
144139
run-make/rustc-macro-dep-files/Makefile
145140
run-make/sanitizer-cdylib-link/Makefile
146141
run-make/sanitizer-dylib-link/Makefile
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// include_bytes! and include_str! in `main.rs`
2+
// should register the included file as of #24423,
3+
// and this test checks that this is still the case.
4+
// See https://github.com/rust-lang/rust/pull/24423
5+
6+
use run_make_support::{invalid_utf8_contains, rustc};
7+
8+
fn main() {
9+
rustc().emit("dep-info").input("main.rs").run();
10+
invalid_utf8_contains("main.d", "input.txt");
11+
invalid_utf8_contains("main.d", "input.bin");
12+
invalid_utf8_contains("main.d", "input.md");
13+
}

‎tests/run-make/include_bytes_deps/Makefile

-7
This file was deleted.

‎tests/run-make/issue-40535/Makefile

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// In a dependency hierarchy, metadata-only crates could cause an Internal
2+
// Compiler Error (ICE) due to a compiler bug - not correctly fetching sources for
3+
// metadata-only crates. This test is a minimal reproduction of a program that triggered
4+
// this bug, and checks that no ICE occurs.
5+
// See https://github.com/rust-lang/rust/issues/40535
6+
7+
use run_make_support::rustc;
8+
9+
fn main() {
10+
rustc().input("baz.rs").emit("metadata").run();
11+
rustc().input("bar.rs").emit("metadata").extern_("baz", "libbaz.rmeta").run();
12+
// There should be no internal compiler error.
13+
rustc().input("foo.rs").emit("metadata").extern_("bar", "libbaz.rmeta").run();
14+
}

‎tests/run-make/optimization-remarks-dir-pgo/Makefile

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This test checks the -Zremark-dir flag, which writes LLVM
2+
// optimization remarks to the YAML format. When using PGO (Profile
3+
// Guided Optimization), the Hotness attribute should be included in
4+
// the output remark files.
5+
// See https://github.com/rust-lang/rust/pull/114439
6+
7+
//@ needs-profiler-support
8+
//@ ignore-cross-compile
9+
10+
use run_make_support::{
11+
has_extension, has_prefix, invalid_utf8_contains, llvm_profdata, run, rustc, shallow_find_files,
12+
};
13+
14+
fn main() {
15+
rustc().profile_generate("profdata").opt().input("foo.rs").output("foo").run();
16+
run("foo");
17+
// The profdata filename is a long sequence of numbers, fetch it by prefix and extension
18+
// to keep the test working even if the filename changes.
19+
let profdata_files = shallow_find_files("profdata", |path| {
20+
has_prefix(path, "default") && has_extension(path, "profraw")
21+
});
22+
let profdata_file = profdata_files.get(0).unwrap();
23+
llvm_profdata().merge().output("merged.profdata").input(profdata_file).run();
24+
rustc()
25+
.profile_use("merged.profdata")
26+
.opt()
27+
.input("foo.rs")
28+
.arg("-Cremark=all")
29+
.arg("-Zremark-dir=profiles")
30+
.run();
31+
// Check that PGO hotness is included in the remark files
32+
let remark_files = shallow_find_files("profiles", |path| {
33+
has_prefix(path, "foo") && has_extension(path, "yaml")
34+
});
35+
assert!(!remark_files.is_empty());
36+
for file in remark_files {
37+
if !file.to_str().unwrap().contains("codegen") {
38+
invalid_utf8_contains(file, "Hotness")
39+
};
40+
}
41+
}

‎tests/run-make/optimization-remarks-dir/Makefile

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// In this test, the function `bar` has #[inline(never)] and the function `foo`
2+
// does not. This test outputs LLVM optimization remarks twice - first for all
3+
// functions (including `bar`, and the `inline` mention), and then for only `foo`
4+
// (should not have the `inline` mention).
5+
// See https://github.com/rust-lang/rust/pull/113040
6+
7+
use run_make_support::{
8+
has_extension, has_prefix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains,
9+
rustc, shallow_find_files,
10+
};
11+
12+
fn main() {
13+
rustc()
14+
.opt()
15+
.input("foo.rs")
16+
.crate_type("lib")
17+
.arg("-Cremark=all")
18+
.arg("-Zremark-dir=profiles_all")
19+
.run();
20+
let all_remark_files = shallow_find_files("profiles_all", |path| {
21+
has_prefix(path, "foo") && has_extension(path, "yaml") && not_contains(path, "codegen")
22+
});
23+
for file in all_remark_files {
24+
invalid_utf8_contains(file, "inline")
25+
}
26+
rustc()
27+
.opt()
28+
.input("foo.rs")
29+
.crate_type("lib")
30+
.arg("-Cremark=foo")
31+
.arg("-Zremark-dir=profiles_foo")
32+
.run();
33+
let foo_remark_files = shallow_find_files("profiles_foo", |path| {
34+
has_prefix(path, "foo") && has_extension(path, "yaml")
35+
});
36+
for file in foo_remark_files {
37+
invalid_utf8_not_contains(file, "inline")
38+
}
39+
}

‎tests/run-make/rmeta-preferred/Makefile

-16
This file was deleted.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test compiles `lib.rs`'s dependency, `rmeta_aux.rs`, as both an rlib
2+
// and an rmeta crate. By default, rustc should give the metadata crate (rmeta)
3+
// precedence over the rust-lib (rlib). This test inspects the contents of the binary
4+
// and that the correct (rmeta) crate was used.
5+
// rlibs being preferred could indicate a resurgence of the -Zbinary-dep-depinfo bug
6+
// seen in #68298.
7+
// See https://github.com/rust-lang/rust/pull/37681
8+
9+
//@ ignore-cross-compile
10+
11+
use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, rustc};
12+
13+
fn main() {
14+
rustc().input("rmeta_aux.rs").crate_type("rlib").emit("link,metadata").run();
15+
rustc().input("lib.rs").crate_type("rlib").emit("dep-info").arg("-Zbinary-dep-depinfo").run();
16+
invalid_utf8_contains("lib.d", "librmeta_aux.rmeta");
17+
invalid_utf8_not_contains("lib.d", "librmeta_aux.rlib");
18+
}

0 commit comments

Comments
 (0)
Failed to load comments.