From 40cad01f2f9d830aeb798057a0aeb761316ebf28 Mon Sep 17 00:00:00 2001
From: Oneirical <manchot@videotron.ca>
Date: Wed, 19 Jun 2024 13:25:29 -0400
Subject: [PATCH 1/6] rewrite and rename include_bytes_deps to rmake

---
 src/tools/tidy/src/allowed_run_make_makefiles.txt |  1 -
 .../input.bin                                     |  0
 .../input.md                                      |  0
 .../input.txt                                     |  0
 .../main.rs                                       |  0
 tests/run-make/include-bytes-deps/rmake.rs        | 15 +++++++++++++++
 tests/run-make/include_bytes_deps/Makefile        |  7 -------
 7 files changed, 15 insertions(+), 8 deletions(-)
 rename tests/run-make/{include_bytes_deps => include-bytes-deps}/input.bin (100%)
 rename tests/run-make/{include_bytes_deps => include-bytes-deps}/input.md (100%)
 rename tests/run-make/{include_bytes_deps => include-bytes-deps}/input.txt (100%)
 rename tests/run-make/{include_bytes_deps => include-bytes-deps}/main.rs (100%)
 create mode 100644 tests/run-make/include-bytes-deps/rmake.rs
 delete mode 100644 tests/run-make/include_bytes_deps/Makefile

diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 2da4e476e9016..6d13559818669 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -46,7 +46,6 @@ run-make/fmt-write-bloat/Makefile
 run-make/foreign-double-unwind/Makefile
 run-make/foreign-exceptions/Makefile
 run-make/foreign-rust-exceptions/Makefile
-run-make/include_bytes_deps/Makefile
 run-make/incr-add-rust-src-component/Makefile
 run-make/incr-foreign-head-span/Makefile
 run-make/interdependent-c-libraries/Makefile
diff --git a/tests/run-make/include_bytes_deps/input.bin b/tests/run-make/include-bytes-deps/input.bin
similarity index 100%
rename from tests/run-make/include_bytes_deps/input.bin
rename to tests/run-make/include-bytes-deps/input.bin
diff --git a/tests/run-make/include_bytes_deps/input.md b/tests/run-make/include-bytes-deps/input.md
similarity index 100%
rename from tests/run-make/include_bytes_deps/input.md
rename to tests/run-make/include-bytes-deps/input.md
diff --git a/tests/run-make/include_bytes_deps/input.txt b/tests/run-make/include-bytes-deps/input.txt
similarity index 100%
rename from tests/run-make/include_bytes_deps/input.txt
rename to tests/run-make/include-bytes-deps/input.txt
diff --git a/tests/run-make/include_bytes_deps/main.rs b/tests/run-make/include-bytes-deps/main.rs
similarity index 100%
rename from tests/run-make/include_bytes_deps/main.rs
rename to tests/run-make/include-bytes-deps/main.rs
diff --git a/tests/run-make/include-bytes-deps/rmake.rs b/tests/run-make/include-bytes-deps/rmake.rs
new file mode 100644
index 0000000000000..6ca29fa664c98
--- /dev/null
+++ b/tests/run-make/include-bytes-deps/rmake.rs
@@ -0,0 +1,15 @@
+// include_bytes! and include_str! in `main.rs`
+// should register the included file as of #24423,
+// and this test checks that this is still the case.
+// See https://github.com/rust-lang/rust/pull/24423
+
+//FIXME(Oneirical): check if works without ignore freebsd
+
+use run_make_support::{invalid_utf8_contains, rustc};
+
+fn main() {
+    rustc().emit("dep-info").input("main.rs").run();
+    invalid_utf8_contains("main.d", "input.txt");
+    invalid_utf8_contains("main.d", "input.bin");
+    invalid_utf8_contains("main.d", "input.md");
+}
diff --git a/tests/run-make/include_bytes_deps/Makefile b/tests/run-make/include_bytes_deps/Makefile
deleted file mode 100644
index 696dfd207bbff..0000000000000
--- a/tests/run-make/include_bytes_deps/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-include ../tools.mk
-
-# ignore-freebsd
-
-all:
-	$(RUSTC) --emit dep-info main.rs
-	$(CGREP) "input.txt" "input.bin" "input.md" < $(TMPDIR)/main.d

From 73d7dc7f220c8e451defc1f3817b99ed70079a4e Mon Sep 17 00:00:00 2001
From: Oneirical <manchot@videotron.ca>
Date: Wed, 19 Jun 2024 14:06:17 -0400
Subject: [PATCH 2/6] rewrite optimization-remarks-dir-pgo to rmake

---
 .../tidy/src/allowed_run_make_makefiles.txt   |  1 -
 .../optimization-remarks-dir-pgo/Makefile     | 17 -----------------
 .../optimization-remarks-dir-pgo/rmake.rs     | 19 +++++++++++++++++++
 3 files changed, 19 insertions(+), 18 deletions(-)
 delete mode 100644 tests/run-make/optimization-remarks-dir-pgo/Makefile
 create mode 100644 tests/run-make/optimization-remarks-dir-pgo/rmake.rs

diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 6d13559818669..e26a1326f443a 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -101,7 +101,6 @@ run-make/no-alloc-shim/Makefile
 run-make/no-builtins-attribute/Makefile
 run-make/no-duplicate-libs/Makefile
 run-make/obey-crate-type-flag/Makefile
-run-make/optimization-remarks-dir-pgo/Makefile
 run-make/optimization-remarks-dir/Makefile
 run-make/output-type-permutations/Makefile
 run-make/panic-abort-eh_frame/Makefile
diff --git a/tests/run-make/optimization-remarks-dir-pgo/Makefile b/tests/run-make/optimization-remarks-dir-pgo/Makefile
deleted file mode 100644
index 57ffd6e70f00b..0000000000000
--- a/tests/run-make/optimization-remarks-dir-pgo/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# needs-profiler-support
-# ignore-cross-compile
-
-include ../tools.mk
-
-PROFILE_DIR=$(TMPDIR)/profiles
-
-check_hotness:
-	$(RUSTC) -Cprofile-generate="$(TMPDIR)"/profdata -O foo.rs -o$(TMPDIR)/foo
-	$(TMPDIR)/foo
-	"$(LLVM_BIN_DIR)"/llvm-profdata merge \
-		-o "$(TMPDIR)"/merged.profdata \
-		"$(TMPDIR)"/profdata/*.profraw
-	$(RUSTC) -Cprofile-use=$(TMPDIR)/merged.profdata -O foo.rs -Cremark=all -Zremark-dir=$(PROFILE_DIR)
-
-	# Check that PGO hotness is included in the remark files
-	cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e "Hotness"
diff --git a/tests/run-make/optimization-remarks-dir-pgo/rmake.rs b/tests/run-make/optimization-remarks-dir-pgo/rmake.rs
new file mode 100644
index 0000000000000..678d9c2de8b40
--- /dev/null
+++ b/tests/run-make/optimization-remarks-dir-pgo/rmake.rs
@@ -0,0 +1,19 @@
+// This test checks the -Zremark-dir flag, which writes LLVM
+// optimization remarks to the YAML format. When using PGO (Profile
+// Guided Optimization), the Hotness attribute should be included in
+// the output remark files.
+// See https://github.com/rust-lang/rust/pull/114439
+
+//@ needs-profiler-support
+//@ ignore-cross-compile
+
+use run_make_support::{run, llvm_profdata, rustc, invalid_utf8_contains};
+
+fn main() {
+    rustc().profile_generate("profdata").opt().input("foo.rs").output("foo").run();
+    run("foo");
+    llvm_profdata().merge().output("merged.profdata").input("profdata/default_15907418011457399462_0.profraw").run();
+    rustc().profile_use("merged.profdata").opt().input("foo.rs").arg("-Cremark=all").arg("-Zremark-dir=profiles").run();
+    // Check that PGO hotness is included in the remark files
+    invalid_utf8_contains("profiles/foo.cba44757bc0621b9-cgu.0.opt.opt.yaml", "Hotness");
+}

From 651f02363d96ce75ae297d70104153a8b3b0981f Mon Sep 17 00:00:00 2001
From: Oneirical <manchot@videotron.ca>
Date: Wed, 19 Jun 2024 14:30:47 -0400
Subject: [PATCH 3/6] rewrite optimization-remarks-dir to rmake

---
 .../tidy/src/allowed_run_make_makefiles.txt   |  1 -
 .../optimization-remarks-dir-pgo/rmake.rs     | 16 +++++++++---
 .../optimization-remarks-dir/Makefile         | 12 ---------
 .../optimization-remarks-dir/rmake.rs         | 26 +++++++++++++++++++
 4 files changed, 39 insertions(+), 16 deletions(-)
 delete mode 100644 tests/run-make/optimization-remarks-dir/Makefile
 create mode 100644 tests/run-make/optimization-remarks-dir/rmake.rs

diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index e26a1326f443a..4516bf86e2b35 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -101,7 +101,6 @@ run-make/no-alloc-shim/Makefile
 run-make/no-builtins-attribute/Makefile
 run-make/no-duplicate-libs/Makefile
 run-make/obey-crate-type-flag/Makefile
-run-make/optimization-remarks-dir/Makefile
 run-make/output-type-permutations/Makefile
 run-make/panic-abort-eh_frame/Makefile
 run-make/pass-linker-flags-flavor/Makefile
diff --git a/tests/run-make/optimization-remarks-dir-pgo/rmake.rs b/tests/run-make/optimization-remarks-dir-pgo/rmake.rs
index 678d9c2de8b40..e527dcb0befa5 100644
--- a/tests/run-make/optimization-remarks-dir-pgo/rmake.rs
+++ b/tests/run-make/optimization-remarks-dir-pgo/rmake.rs
@@ -7,13 +7,23 @@
 //@ needs-profiler-support
 //@ ignore-cross-compile
 
-use run_make_support::{run, llvm_profdata, rustc, invalid_utf8_contains};
+use run_make_support::{invalid_utf8_contains, llvm_profdata, run, rustc};
 
 fn main() {
     rustc().profile_generate("profdata").opt().input("foo.rs").output("foo").run();
     run("foo");
-    llvm_profdata().merge().output("merged.profdata").input("profdata/default_15907418011457399462_0.profraw").run();
-    rustc().profile_use("merged.profdata").opt().input("foo.rs").arg("-Cremark=all").arg("-Zremark-dir=profiles").run();
+    llvm_profdata()
+        .merge()
+        .output("merged.profdata")
+        .input("profdata/default_15907418011457399462_0.profraw")
+        .run();
+    rustc()
+        .profile_use("merged.profdata")
+        .opt()
+        .input("foo.rs")
+        .arg("-Cremark=all")
+        .arg("-Zremark-dir=profiles")
+        .run();
     // Check that PGO hotness is included in the remark files
     invalid_utf8_contains("profiles/foo.cba44757bc0621b9-cgu.0.opt.opt.yaml", "Hotness");
 }
diff --git a/tests/run-make/optimization-remarks-dir/Makefile b/tests/run-make/optimization-remarks-dir/Makefile
deleted file mode 100644
index a8342c8ad14d5..0000000000000
--- a/tests/run-make/optimization-remarks-dir/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-include ../tools.mk
-
-PROFILE_DIR=$(TMPDIR)/profiles
-
-all: check_inline check_filter
-
-check_inline:
-	$(RUSTC) -O foo.rs --crate-type=lib -Cremark=all -Zremark-dir=$(PROFILE_DIR)
-	cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e "inline"
-check_filter:
-	$(RUSTC) -O foo.rs --crate-type=lib -Cremark=foo -Zremark-dir=$(PROFILE_DIR)
-	cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e -v "inline"
diff --git a/tests/run-make/optimization-remarks-dir/rmake.rs b/tests/run-make/optimization-remarks-dir/rmake.rs
new file mode 100644
index 0000000000000..d0c4ccd72d13a
--- /dev/null
+++ b/tests/run-make/optimization-remarks-dir/rmake.rs
@@ -0,0 +1,26 @@
+// In this test, the function `bar` has #[inline(never)] and the function `foo`
+// does not. This test outputs LLVM optimization remarks twice - first for all
+// functions (including `bar`, and the `inline` mention), and then for only `foo`
+// (should not have the `inline` mention).
+// See https://github.com/rust-lang/rust/pull/113040
+
+use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, rustc};
+
+fn main() {
+    rustc()
+        .opt()
+        .input("foo.rs")
+        .crate_type("lib")
+        .arg("-Cremark=all")
+        .arg("-Zremark-dir=profiles_all")
+        .run();
+    invalid_utf8_contains("profiles_all/foo.5be5606e1f6aa79b-cgu.0.opt.opt.yaml", "inline");
+    rustc()
+        .opt()
+        .input("foo.rs")
+        .crate_type("lib")
+        .arg("-Cremark=foo")
+        .arg("-Zremark-dir=profiles_foo")
+        .run();
+    invalid_utf8_not_contains("profiles_foo/foo.5be5606e1f6aa79b-cgu.0.opt.opt.yaml", "inline");
+}

From 5e23dfea9dee65b8a5b7ed54354b4c46d38f12ca Mon Sep 17 00:00:00 2001
From: Oneirical <manchot@videotron.ca>
Date: Wed, 19 Jun 2024 14:55:22 -0400
Subject: [PATCH 4/6] rewrite and rename issue-40535 to rmake

---
 src/tools/tidy/src/allowed_run_make_makefiles.txt  |  1 -
 tests/run-make/issue-40535/Makefile                | 13 -------------
 .../bar.rs                                         |  0
 .../baz.rs                                         |  0
 .../foo.rs                                         |  0
 tests/run-make/metadata-only-crate-no-ice/rmake.rs | 14 ++++++++++++++
 6 files changed, 14 insertions(+), 14 deletions(-)
 delete mode 100644 tests/run-make/issue-40535/Makefile
 rename tests/run-make/{issue-40535 => metadata-only-crate-no-ice}/bar.rs (100%)
 rename tests/run-make/{issue-40535 => metadata-only-crate-no-ice}/baz.rs (100%)
 rename tests/run-make/{issue-40535 => metadata-only-crate-no-ice}/foo.rs (100%)
 create mode 100644 tests/run-make/metadata-only-crate-no-ice/rmake.rs

diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 4516bf86e2b35..4fbfa442fcc54 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -63,7 +63,6 @@ run-make/issue-33329/Makefile
 run-make/issue-35164/Makefile
 run-make/issue-36710/Makefile
 run-make/issue-37839/Makefile
-run-make/issue-40535/Makefile
 run-make/issue-47551/Makefile
 run-make/issue-69368/Makefile
 run-make/issue-83045/Makefile
diff --git a/tests/run-make/issue-40535/Makefile b/tests/run-make/issue-40535/Makefile
deleted file mode 100644
index 155c88252144d..0000000000000
--- a/tests/run-make/issue-40535/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-include ../tools.mk
-
-# The ICE occurred in the following situation:
-# * `foo` declares `extern crate bar, baz`, depends only on `bar` (forgetting `baz` in `Cargo.toml`)
-# * `bar` declares and depends on `extern crate baz`
-# * All crates built in metadata-only mode (`cargo check`)
-all:
-	# cc https://github.com/rust-lang/rust/issues/40623
-	$(RUSTC) baz.rs --emit=metadata
-	$(RUSTC) bar.rs --emit=metadata --extern baz=$(TMPDIR)/libbaz.rmeta
-	$(RUSTC) foo.rs --emit=metadata --extern bar=$(TMPDIR)/libbar.rmeta 2>&1 | \
-		$(CGREP) -v "unexpectedly panicked"
-	# ^ Succeeds if it doesn't find the ICE message
diff --git a/tests/run-make/issue-40535/bar.rs b/tests/run-make/metadata-only-crate-no-ice/bar.rs
similarity index 100%
rename from tests/run-make/issue-40535/bar.rs
rename to tests/run-make/metadata-only-crate-no-ice/bar.rs
diff --git a/tests/run-make/issue-40535/baz.rs b/tests/run-make/metadata-only-crate-no-ice/baz.rs
similarity index 100%
rename from tests/run-make/issue-40535/baz.rs
rename to tests/run-make/metadata-only-crate-no-ice/baz.rs
diff --git a/tests/run-make/issue-40535/foo.rs b/tests/run-make/metadata-only-crate-no-ice/foo.rs
similarity index 100%
rename from tests/run-make/issue-40535/foo.rs
rename to tests/run-make/metadata-only-crate-no-ice/foo.rs
diff --git a/tests/run-make/metadata-only-crate-no-ice/rmake.rs b/tests/run-make/metadata-only-crate-no-ice/rmake.rs
new file mode 100644
index 0000000000000..825da12cfd1bc
--- /dev/null
+++ b/tests/run-make/metadata-only-crate-no-ice/rmake.rs
@@ -0,0 +1,14 @@
+// In a dependency hierarchy, metadata-only crates could cause an Internal
+// Compiler Error (ICE) due to a compiler bug - not correctly fetching sources for
+// metadata-only crates. This test is a minimal reproduction of a program that triggered
+// this bug, and checks that no ICE occurs.
+// See https://github.com/rust-lang/rust/issues/40535
+
+use run_make_support::rustc;
+
+fn main() {
+    rustc().input("baz.rs").emit("metadata").run();
+    rustc().input("bar.rs").emit("metadata").extern_("baz", "libbaz.rmeta").run();
+    // There should be no internal compiler error message.
+    rustc().input("foo.rs").emit("metadata").extern_("bar", "libbaz.rmeta").run().assert_stderr_not_contains("unexpectedly panicked");
+}

From b167a15d64c0777afa6b90d7883368c629049a16 Mon Sep 17 00:00:00 2001
From: Oneirical <manchot@videotron.ca>
Date: Wed, 19 Jun 2024 15:46:27 -0400
Subject: [PATCH 5/6] rewrite rmeta-preferred to rmake

---
 .../tidy/src/allowed_run_make_makefiles.txt    |  1 -
 tests/run-make/include-bytes-deps/rmake.rs     |  2 --
 .../metadata-only-crate-no-ice/rmake.rs        |  4 ++--
 tests/run-make/rmeta-preferred/Makefile        | 16 ----------------
 tests/run-make/rmeta-preferred/rmake.rs        | 18 ++++++++++++++++++
 5 files changed, 20 insertions(+), 21 deletions(-)
 delete mode 100644 tests/run-make/rmeta-preferred/Makefile
 create mode 100644 tests/run-make/rmeta-preferred/rmake.rs

diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 4fbfa442fcc54..70c1b055c6e40 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -132,7 +132,6 @@ run-make/return-non-c-like-enum-from-c/Makefile
 run-make/rlib-format-packed-bundled-libs-2/Makefile
 run-make/rlib-format-packed-bundled-libs-3/Makefile
 run-make/rlib-format-packed-bundled-libs/Makefile
-run-make/rmeta-preferred/Makefile
 run-make/rustc-macro-dep-files/Makefile
 run-make/sanitizer-cdylib-link/Makefile
 run-make/sanitizer-dylib-link/Makefile
diff --git a/tests/run-make/include-bytes-deps/rmake.rs b/tests/run-make/include-bytes-deps/rmake.rs
index 6ca29fa664c98..ea371ddae5675 100644
--- a/tests/run-make/include-bytes-deps/rmake.rs
+++ b/tests/run-make/include-bytes-deps/rmake.rs
@@ -3,8 +3,6 @@
 // and this test checks that this is still the case.
 // See https://github.com/rust-lang/rust/pull/24423
 
-//FIXME(Oneirical): check if works without ignore freebsd
-
 use run_make_support::{invalid_utf8_contains, rustc};
 
 fn main() {
diff --git a/tests/run-make/metadata-only-crate-no-ice/rmake.rs b/tests/run-make/metadata-only-crate-no-ice/rmake.rs
index 825da12cfd1bc..e6f852fca413a 100644
--- a/tests/run-make/metadata-only-crate-no-ice/rmake.rs
+++ b/tests/run-make/metadata-only-crate-no-ice/rmake.rs
@@ -9,6 +9,6 @@ use run_make_support::rustc;
 fn main() {
     rustc().input("baz.rs").emit("metadata").run();
     rustc().input("bar.rs").emit("metadata").extern_("baz", "libbaz.rmeta").run();
-    // There should be no internal compiler error message.
-    rustc().input("foo.rs").emit("metadata").extern_("bar", "libbaz.rmeta").run().assert_stderr_not_contains("unexpectedly panicked");
+    // There should be no internal compiler error.
+    rustc().input("foo.rs").emit("metadata").extern_("bar", "libbaz.rmeta").run();
 }
diff --git a/tests/run-make/rmeta-preferred/Makefile b/tests/run-make/rmeta-preferred/Makefile
deleted file mode 100644
index 3bf12cced29ab..0000000000000
--- a/tests/run-make/rmeta-preferred/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-# Test that using rlibs and rmeta dep crates work together. Specifically, that
-# there can be both an rmeta and an rlib file and rustc will prefer the rmeta
-# file.
-#
-# This behavior is simply making sure this doesn't accidentally change; in this
-# case we want to make sure that the rlib isn't being used as that would cause
-# bugs in -Zbinary-dep-depinfo (see #68298).
-
-all:
-	$(RUSTC) rmeta_aux.rs --crate-type=rlib --emit link,metadata
-	$(RUSTC) lib.rs --crate-type=rlib --emit dep-info -Zbinary-dep-depinfo
-	$(CGREP) "librmeta_aux.rmeta" < $(TMPDIR)/lib.d
-	$(CGREP) -v "librmeta_aux.rlib" < $(TMPDIR)/lib.d
diff --git a/tests/run-make/rmeta-preferred/rmake.rs b/tests/run-make/rmeta-preferred/rmake.rs
new file mode 100644
index 0000000000000..09cba06e2f509
--- /dev/null
+++ b/tests/run-make/rmeta-preferred/rmake.rs
@@ -0,0 +1,18 @@
+// This test compiles `lib.rs`'s dependency, `rmeta_aux.rs`, as both an rlib
+// and an rmeta crate. By default, rustc should give the metadata crate (rmeta)
+// precedence over the rust-lib (rlib). This test inspects the contents of the binary
+// and that the correct (rmeta) crate was used.
+// rlibs being preferred could indicate a resurgence of the -Zbinary-dep-depinfo bug
+// seen in #68298.
+// See https://github.com/rust-lang/rust/pull/37681
+
+//@ ignore-cross-compile
+
+use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, rustc};
+
+fn main() {
+    rustc().input("rmeta_aux.rs").crate_type("rlib").emit("link,metadata").run();
+    rustc().input("lib.rs").crate_type("rlib").emit("dep-info").arg("-Zbinary-dep-depinfo").run();
+    invalid_utf8_contains("lib.d", "librmeta_aux.rmeta");
+    invalid_utf8_not_contains("lib.d", "librmeta_aux.rlib");
+}

From 3ea36f5bb6845bc0c0737d174e49fd3ff9380708 Mon Sep 17 00:00:00 2001
From: Oneirical <manchot@videotron.ca>
Date: Thu, 20 Jun 2024 16:02:22 -0400
Subject: [PATCH 6/6] add shallow_find_files helper function to
 run-make-support

---
 src/tools/run-make-support/src/lib.rs         | 34 +++++++++++++++++++
 .../optimization-remarks-dir-pgo/rmake.rs     | 26 ++++++++++----
 .../optimization-remarks-dir/rmake.rs         | 19 +++++++++--
 3 files changed, 69 insertions(+), 10 deletions(-)

diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index 9a180fe4ad19a..af5ae6a8e608c 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -261,6 +261,40 @@ pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>
     success.unwrap();
 }
 
+/// Browse the directory `path` non-recursively and return all files which respect the parameters
+/// outlined by `closure`.
+#[track_caller]
+pub fn shallow_find_files<P: AsRef<Path>, F: Fn(&PathBuf) -> bool>(
+    path: P,
+    closure: F,
+) -> Vec<PathBuf> {
+    let mut matching_files = Vec::new();
+    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);
+        }
+    }
+    matching_files
+}
+
+/// Returns true if the filename at `path` starts with `prefix`.
+pub fn has_prefix<P: AsRef<Path>>(path: P, prefix: &str) -> bool {
+    path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().starts_with(prefix))
+}
+
+/// Returns true if the filename at `path` has the extension `extension`.
+pub fn has_extension<P: AsRef<Path>>(path: P, extension: &str) -> bool {
+    path.as_ref().extension().is_some_and(|ext| ext == extension)
+}
+
+/// Returns true if the filename at `path` does not contain `expected`.
+pub fn not_contains<P: AsRef<Path>>(path: P, expected: &str) -> bool {
+    !path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected))
+}
+
 /// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
 /// available on the platform!
 #[track_caller]
diff --git a/tests/run-make/optimization-remarks-dir-pgo/rmake.rs b/tests/run-make/optimization-remarks-dir-pgo/rmake.rs
index e527dcb0befa5..228c43cc5f18a 100644
--- a/tests/run-make/optimization-remarks-dir-pgo/rmake.rs
+++ b/tests/run-make/optimization-remarks-dir-pgo/rmake.rs
@@ -7,16 +7,20 @@
 //@ needs-profiler-support
 //@ ignore-cross-compile
 
-use run_make_support::{invalid_utf8_contains, llvm_profdata, run, rustc};
+use run_make_support::{
+    has_extension, has_prefix, invalid_utf8_contains, llvm_profdata, run, rustc, shallow_find_files,
+};
 
 fn main() {
     rustc().profile_generate("profdata").opt().input("foo.rs").output("foo").run();
     run("foo");
-    llvm_profdata()
-        .merge()
-        .output("merged.profdata")
-        .input("profdata/default_15907418011457399462_0.profraw")
-        .run();
+    // The profdata filename is a long sequence of numbers, fetch it by prefix and extension
+    // to keep the test working even if the filename changes.
+    let profdata_files = shallow_find_files("profdata", |path| {
+        has_prefix(path, "default") && has_extension(path, "profraw")
+    });
+    let profdata_file = profdata_files.get(0).unwrap();
+    llvm_profdata().merge().output("merged.profdata").input(profdata_file).run();
     rustc()
         .profile_use("merged.profdata")
         .opt()
@@ -25,5 +29,13 @@ fn main() {
         .arg("-Zremark-dir=profiles")
         .run();
     // Check that PGO hotness is included in the remark files
-    invalid_utf8_contains("profiles/foo.cba44757bc0621b9-cgu.0.opt.opt.yaml", "Hotness");
+    let remark_files = shallow_find_files("profiles", |path| {
+        has_prefix(path, "foo") && has_extension(path, "yaml")
+    });
+    assert!(!remark_files.is_empty());
+    for file in remark_files {
+        if !file.to_str().unwrap().contains("codegen") {
+            invalid_utf8_contains(file, "Hotness")
+        };
+    }
 }
diff --git a/tests/run-make/optimization-remarks-dir/rmake.rs b/tests/run-make/optimization-remarks-dir/rmake.rs
index d0c4ccd72d13a..afcb8c3e3ebdb 100644
--- a/tests/run-make/optimization-remarks-dir/rmake.rs
+++ b/tests/run-make/optimization-remarks-dir/rmake.rs
@@ -4,7 +4,10 @@
 // (should not have the `inline` mention).
 // See https://github.com/rust-lang/rust/pull/113040
 
-use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, rustc};
+use run_make_support::{
+    has_extension, has_prefix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains,
+    rustc, shallow_find_files,
+};
 
 fn main() {
     rustc()
@@ -14,7 +17,12 @@ fn main() {
         .arg("-Cremark=all")
         .arg("-Zremark-dir=profiles_all")
         .run();
-    invalid_utf8_contains("profiles_all/foo.5be5606e1f6aa79b-cgu.0.opt.opt.yaml", "inline");
+    let all_remark_files = shallow_find_files("profiles_all", |path| {
+        has_prefix(path, "foo") && has_extension(path, "yaml") && not_contains(path, "codegen")
+    });
+    for file in all_remark_files {
+        invalid_utf8_contains(file, "inline")
+    }
     rustc()
         .opt()
         .input("foo.rs")
@@ -22,5 +30,10 @@ fn main() {
         .arg("-Cremark=foo")
         .arg("-Zremark-dir=profiles_foo")
         .run();
-    invalid_utf8_not_contains("profiles_foo/foo.5be5606e1f6aa79b-cgu.0.opt.opt.yaml", "inline");
+    let foo_remark_files = shallow_find_files("profiles_foo", |path| {
+        has_prefix(path, "foo") && has_extension(path, "yaml")
+    });
+    for file in foo_remark_files {
+        invalid_utf8_not_contains(file, "inline")
+    }
 }