From 9d6863e7973df15c09e712c0bbdab2d09e93ab76 Mon Sep 17 00:00:00 2001 From: Jerry Wang Date: Sat, 15 Jun 2024 21:47:27 -0400 Subject: [PATCH] Migrate `run-make/comment-section` to `rmake.rs` --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/comment-section/Makefile | 18 -------- tests/run-make/comment-section/main.rs | 1 + tests/run-make/comment-section/rmake.rs | 44 +++++++++++++++++++ 4 files changed, 45 insertions(+), 19 deletions(-) delete mode 100644 tests/run-make/comment-section/Makefile create mode 100644 tests/run-make/comment-section/main.rs create mode 100644 tests/run-make/comment-section/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 f45e9e766a99b..4a7f553dcd6dd 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -11,7 +11,6 @@ run-make/c-unwind-abi-catch-panic/Makefile run-make/cat-and-grep-sanity-check/Makefile run-make/cdylib-dylib-linkage/Makefile run-make/cdylib-fewer-symbols/Makefile -run-make/comment-section/Makefile run-make/compiler-lookup-paths-2/Makefile run-make/compiler-lookup-paths/Makefile run-make/compiler-rt-works-on-mingw/Makefile diff --git a/tests/run-make/comment-section/Makefile b/tests/run-make/comment-section/Makefile deleted file mode 100644 index d0b98176ffed9..0000000000000 --- a/tests/run-make/comment-section/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Both GCC and Clang write by default a `.comment` section with compiler information. Rustc received a similar .comment section, so this tests checks that this section properly appears. -# See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc - -include ../tools.mk - -# only-linux - -all: - echo 'fn main(){}' | $(RUSTC) - --emit=link,obj -Csave-temps --target=$(TARGET) - - # Check linked output has a `.comment` section with the expected content. - readelf -p '.comment' $(TMPDIR)/rust_out | $(CGREP) -F 'rustc version 1.' - - # Check all object files (including temporary outputs) have a `.comment` - # section with the expected content. - set -e; for f in $(TMPDIR)/*.o; do \ - readelf -p '.comment' $$f | $(CGREP) -F 'rustc version 1.'; \ - done diff --git a/tests/run-make/comment-section/main.rs b/tests/run-make/comment-section/main.rs new file mode 100644 index 0000000000000..f328e4d9d04c3 --- /dev/null +++ b/tests/run-make/comment-section/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/run-make/comment-section/rmake.rs b/tests/run-make/comment-section/rmake.rs new file mode 100644 index 0000000000000..68f012a55501c --- /dev/null +++ b/tests/run-make/comment-section/rmake.rs @@ -0,0 +1,44 @@ +// Both GCC and Clang write by default a `.comment` section with compiler information. +// Rustc received a similar .comment section, so this tests checks that this section +// properly appears. +// See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc + +//@ only-linux + +use std::path::PathBuf; + +use run_make_support::llvm_readobj; +use run_make_support::rustc; +use run_make_support::{cwd, env_var, read_dir, run_in_tmpdir}; + +fn main() { + let target = env_var("TARGET"); + + run_in_tmpdir(|| { + let p = cwd(); + + rustc().input("main.rs").emit("link,obj").arg("-Csave-temps").target(&target).run(); + + // Check linked output has a `.comment` section with the expected content. + llvm_readobj() + .gnu_elf_style() + .section(".comment") + .arg(PathBuf::from(&p).join("main")) + .run() + .assert_stdout_contains("rustc version 1."); + + // Check all object files (including temporary outputs) have a `.comment` + // section with the expected content. + read_dir(p, |f| { + if f.extension() != Some(".o".as_ref()) { + return; + } + llvm_readobj() + .gnu_elf_style() + .section(".comment") + .arg(&f) + .run() + .assert_stdout_contains("rustc version 1."); + }); + }) +}