From e1f381b7c5082bf847587e8c02a44ad7444569dd Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 6 Jun 2024 15:20:42 -0400 Subject: [PATCH] Rewrite lto-readonly-lib to rmake --- src/tools/run-make-support/src/command.rs | 9 +++- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/link-args-order/rmake.rs | 50 ++++++++----------- tests/run-make/ls-metadata/rmake.rs | 10 ++-- tests/run-make/lto-readonly-lib/Makefile | 13 ----- tests/run-make/lto-readonly-lib/rmake.rs | 25 ++++++++++ 6 files changed, 59 insertions(+), 49 deletions(-) delete mode 100644 tests/run-make/lto-readonly-lib/Makefile create mode 100644 tests/run-make/lto-readonly-lib/rmake.rs diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs index b9e56ab632add..dab3dc1f5c96f 100644 --- a/src/tools/run-make-support/src/command.rs +++ b/src/tools/run-make-support/src/command.rs @@ -127,7 +127,14 @@ impl CompletedProcess { #[track_caller] pub fn assert_stderr_contains>(self, needle: S) -> Self { - assert!(self.stderr_utf8().contains(needle.as_ref())); + assert!( + self.stderr_utf8().contains(needle.as_ref()), + format!( + "The stderr {:?} did not contain the string {:?}", + self.stderr_utf8(), + needle.as_ref(), + ) + ); self } diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 4d826fd6c4358..38de4e7c2faec 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -129,7 +129,6 @@ run-make/lto-dylib-dep/Makefile run-make/lto-empty/Makefile run-make/lto-linkage-used-attr/Makefile run-make/lto-no-link-whole-rlib/Makefile -run-make/lto-readonly-lib/Makefile run-make/lto-smoke-c/Makefile run-make/macos-deployment-target/Makefile run-make/macos-fat-archive/Makefile diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs index cd921a031292b..9f5ec70e21bac 100644 --- a/tests/run-make/link-args-order/rmake.rs +++ b/tests/run-make/link-args-order/rmake.rs @@ -3,37 +3,29 @@ // checks that linker arguments remain intact and in the order they were originally passed in. // See https://github.com/rust-lang/rust/pull/70665 -use run_make_support::rustc; +use run_make_support::{assert_stderr_contains, rustc}; fn main() { - assert!( - String::from_utf8( - rustc() - .input("empty.rs") - .linker_flavor("ld") - .link_arg("a") - .link_args("\"b c\"") - .link_args("\"d e\"") - .link_arg("f") - .run_fail() - .stderr - ) - .unwrap() - .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") + assert_stderr_contains( + rustc() + .input("empty.rs") + .linker_flavor("ld") + .link_arg("a") + .link_args("\"b c\"") + .link_args("\"d e\"") + .link_arg("f") + .run_fail(), + "\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"", ); - assert!( - String::from_utf8( - rustc() - .input("empty.rs") - .linker_flavor("ld") - .pre_link_arg("a") - .pre_link_args("\"b c\"") - .pre_link_args("\"d e\"") - .pre_link_arg("f") - .run_fail() - .stderr - ) - .unwrap() - .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") + assert_stderr_contains( + rustc() + .input("empty.rs") + .linker_flavor("ld") + .pre_link_arg("a") + .pre_link_args("\"b c\"") + .pre_link_args("\"d e\"") + .pre_link_arg("f") + .run_fail(), + "\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"", ); } diff --git a/tests/run-make/ls-metadata/rmake.rs b/tests/run-make/ls-metadata/rmake.rs index 61dcd3774a193..0e60f2c46787a 100644 --- a/tests/run-make/ls-metadata/rmake.rs +++ b/tests/run-make/ls-metadata/rmake.rs @@ -7,11 +7,11 @@ //@ ignore-cross-compile use run_make_support::fs_wrapper; -use run_make_support::{rmake_out_path, rustc}; +use run_make_support::rustc; fn main() { - rustc().input("foo.rs"); - rustc().arg("-Zls=root").input(rmake_out_path("foo")); - fs_wrapper::create_file(rmake_out_path("bar")); - rustc().arg("-Zls=root").input(rmake_out_path("bar")); + rustc().input("foo.rs").run(); + rustc().arg("-Zls=root").input("foo").run(); + fs_wrapper::create_file("bar"); + rustc().arg("-Zls=root").input("bar").run(); } diff --git a/tests/run-make/lto-readonly-lib/Makefile b/tests/run-make/lto-readonly-lib/Makefile deleted file mode 100644 index 11d944e3e3d4b..0000000000000 --- a/tests/run-make/lto-readonly-lib/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) lib.rs - - # the compiler needs to copy and modify the rlib file when performing - # LTO, so we should ensure that it can cope with the original rlib - # being read-only. - chmod 444 $(TMPDIR)/*.rlib - - $(RUSTC) main.rs -C lto - $(call RUN,main) diff --git a/tests/run-make/lto-readonly-lib/rmake.rs b/tests/run-make/lto-readonly-lib/rmake.rs new file mode 100644 index 0000000000000..bf1dafee697dc --- /dev/null +++ b/tests/run-make/lto-readonly-lib/rmake.rs @@ -0,0 +1,25 @@ +// When the compiler is performing link time optimization, it will +// need to copy the original rlib file, set the copy's permissions to read/write, +// and modify that copy - even if the original +// file is read-only. This test creates a read-only rlib, and checks that +// compilation with LTO succeeds. +// See https://github.com/rust-lang/rust/pull/17619 + +//@ ignore-cross-compile + +use run_make_support::fs_wrapper; +use run_make_support::{cwd, run, rustc}; + +fn main() { + rustc().input("lib.rs").run(); + let entries = fs_wrapper::read_dir(cwd()); + for entry in entries { + if entry.path().extension().and_then(|s| s.to_str()) == Some("rlib") { + let mut perms = fs_wrapper::metadata(entry.path()).permissions(); + perms.set_readonly(true); + fs_wrapper::set_permissions(entry.path(), perms); + } + } + rustc().input("main.rs").arg("-Clto").run(); + run("main"); +}