From a3b7c2993ed969e4abb3ad196c7abe3e05d88a93 Mon Sep 17 00:00:00 2001 From: Oneirical <manchot@videotron.ca> Date: Fri, 14 Jun 2024 13:42:42 -0400 Subject: [PATCH 1/3] rewrite extern-flag-fun to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/extern-flag-fun/Makefile | 20 ----------- tests/run-make/extern-flag-fun/rmake.rs | 36 +++++++++++++++++++ 3 files changed, 36 insertions(+), 21 deletions(-) delete mode 100644 tests/run-make/extern-flag-fun/Makefile create mode 100644 tests/run-make/extern-flag-fun/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 be9df226d64e8..ec184c2c2146f 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -43,7 +43,6 @@ run-make/error-writing-dependencies/Makefile run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile run-make/extern-flag-disambiguates/Makefile -run-make/extern-flag-fun/Makefile run-make/extern-flag-pathless/Makefile run-make/extern-flag-rename-transitive/Makefile run-make/extern-fn-explicit-align/Makefile diff --git a/tests/run-make/extern-flag-fun/Makefile b/tests/run-make/extern-flag-fun/Makefile deleted file mode 100644 index 687cdfd76755b..0000000000000 --- a/tests/run-make/extern-flag-fun/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) bar.rs --crate-type=rlib - $(RUSTC) bar.rs --crate-type=rlib -C extra-filename=-a - $(RUSTC) bar-alt.rs --crate-type=rlib - $(RUSTC) foo.rs --extern bar=no-exist && exit 1 || exit 0 - $(RUSTC) foo.rs --extern bar=foo.rs && exit 1 || exit 0 - $(RUSTC) foo.rs \ - --extern bar=$(TMPDIR)/libbar.rlib \ - --extern bar=$(TMPDIR)/libbar-alt.rlib \ - && exit 1 || exit 0 - $(RUSTC) foo.rs \ - --extern bar=$(TMPDIR)/libbar.rlib \ - --extern bar=$(TMPDIR)/libbar-a.rlib - $(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib - # Try to be sneaky and load a private crate from with a non-private name. - $(RUSTC) rustc.rs -Zforce-unstable-if-unmarked --crate-type=rlib - $(RUSTC) gated_unstable.rs --extern alloc=$(TMPDIR)/librustc.rlib 2>&1 | $(CGREP) 'rustc_private' diff --git a/tests/run-make/extern-flag-fun/rmake.rs b/tests/run-make/extern-flag-fun/rmake.rs new file mode 100644 index 0000000000000..10fec6e30b423 --- /dev/null +++ b/tests/run-make/extern-flag-fun/rmake.rs @@ -0,0 +1,36 @@ +// The --extern flag can override the default crate search of +// the compiler and directly fetch a given path. There are a few rules +// to follow: for example, there can't be more than one rlib, the crates must +// be valid ("no-exist" in this test), and private crates can't be loaded +// as non-private. This test checks that these rules are enforced. +// See https://github.com/rust-lang/rust/pull/15319 + +//@ ignore-cross-compile + +use run_make_support::{rust_lib_name, rustc}; + +fn main() { + rustc().input("bar.rs").crate_type("rlib").run(); + rustc().input("bar.rs").crate_type("rlib").extra_filename("-a").run(); + rustc().input("bar-alt.rs").crate_type("rlib").run(); + rustc().input("foo.rs").extern_("bar", "no-exist").run_fail(); + rustc().input("foo.rs").extern_("bar", "foo.rs").run_fail(); + rustc() + .input("foo.rs") + .extern_("bar", rust_lib_name("bar")) + .extern_("bar", rust_lib_name("bar-alt")) + .run_fail(); + rustc() + .input("foo.rs") + .extern_("bar", rust_lib_name("bar")) + .extern_("bar", rust_lib_name("bar-a")) + .run(); + rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).run(); + // Try to be sneaky and load a private crate from with a non-private name. + rustc().input("rustc.rs").arg("-Zforce-unstable-if-unmarked").crate_type("rlib").run(); + rustc() + .input("gated_unstable.rs") + .extern_("alloc", rust_lib_name("rustc")) + .run_fail() + .assert_stderr_contains("rustc_private"); +} From ab715107042fc547501713e0601268fd1f953ce1 Mon Sep 17 00:00:00 2001 From: Oneirical <manchot@videotron.ca> Date: Fri, 14 Jun 2024 15:10:34 -0400 Subject: [PATCH 2/3] rewrite incremental-debugger-visualiser to rmake --- src/tools/run-make-support/src/lib.rs | 22 +++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../incremental-debugger-visualizer/Makefile | 49 --------------- .../incremental-debugger-visualizer/rmake.rs | 61 +++++++++++++++++++ 4 files changed, 83 insertions(+), 50 deletions(-) delete mode 100644 tests/run-make/incremental-debugger-visualizer/Makefile create mode 100644 tests/run-make/incremental-debugger-visualizer/rmake.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index ba4524c150c46..784bbe572ab30 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -271,6 +271,28 @@ pub fn set_host_rpath(cmd: &mut Command) { }); } +/// Read the contents of a file that cannot simply be read by +/// read_to_string, due to invalid utf8 data, then assert that it contains `expected`. +#[track_caller] +pub fn invalid_utf8_contains_str<P: AsRef<Path>>(path: P, expected: &str) { + use std::io::Read; + let mut file = std::fs::File::open(path).unwrap(); + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer).unwrap(); + assert!(String::from_utf8_lossy(&buffer).contains(expected)); +} + +/// Read the contents of a file that cannot simply be read by +/// read_to_string, due to invalid utf8 data, then assert that it does not contain `expected`. +#[track_caller] +pub fn invalid_utf8_not_contains_str<P: AsRef<Path>>(path: P, expected: &str) { + use std::io::Read; + let mut file = std::fs::File::open(path).unwrap(); + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer).unwrap(); + assert!(!String::from_utf8_lossy(&buffer).contains(expected)); +} + /// Copy a directory into another. pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) { fn copy_dir_all_inner(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> { diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index ec184c2c2146f..7a08a9ab1a26f 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -67,7 +67,6 @@ run-make/inaccessible-temp-dir/Makefile run-make/include_bytes_deps/Makefile run-make/incr-add-rust-src-component/Makefile run-make/incr-foreign-head-span/Makefile -run-make/incremental-debugger-visualizer/Makefile run-make/incremental-session-fail/Makefile run-make/inline-always-many-cgu/Makefile run-make/interdependent-c-libraries/Makefile diff --git a/tests/run-make/incremental-debugger-visualizer/Makefile b/tests/run-make/incremental-debugger-visualizer/Makefile deleted file mode 100644 index 8cfe41597adf8..0000000000000 --- a/tests/run-make/incremental-debugger-visualizer/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -include ../tools.mk - -# This test makes sure that changes to files referenced via #[debugger_visualizer] -# are picked up when compiling incrementally. - -# We have to copy the source to $(TMPDIR) because Github CI mounts the source -# directory as readonly. We need to apply modifications to some of the source -# file. -SRC_DIR := $(TMPDIR)/src -INCR_CACHE_DIR := $(TMPDIR)/incremental - -all: - rm -rf $(TMPDIR)/* - mkdir $(SRC_DIR) - cp ./foo.rs $(SRC_DIR) - echo "GDB script v1" > $(SRC_DIR)/foo.py - echo "Natvis v1" > $(SRC_DIR)/foo.natvis - $(RUSTC) $(SRC_DIR)/foo.rs \ - --crate-type=rlib \ - --emit metadata \ - -C incremental=$(INCR_CACHE_DIR) \ - -Z incremental-verify-ich - $(CGREP) "GDB script v1" < $(TMPDIR)/libfoo.rmeta - $(CGREP) "Natvis v1" < $(TMPDIR)/libfoo.rmeta - - # Change only the GDB script and check that the change has been picked up - echo "GDB script v2" > $(SRC_DIR)/foo.py - $(RUSTC) $(SRC_DIR)/foo.rs \ - --crate-type=rlib \ - --emit metadata \ - -C incremental=$(INCR_CACHE_DIR) \ - -Z incremental-verify-ich - - $(CGREP) "GDB script v2" < $(TMPDIR)/libfoo.rmeta - $(CGREP) -v "GDB script v1" < $(TMPDIR)/libfoo.rmeta - $(CGREP) "Natvis v1" < $(TMPDIR)/libfoo.rmeta - - # Now change the Natvis version and check that the change has been picked up - echo "Natvis v2" > $(SRC_DIR)/foo.natvis - $(RUSTC) $(SRC_DIR)/foo.rs \ - --crate-type=rlib \ - --emit metadata \ - -C incremental=$(INCR_CACHE_DIR) \ - -Z incremental-verify-ich - - $(CGREP) "GDB script v2" < $(TMPDIR)/libfoo.rmeta - $(CGREP) -v "GDB script v1" < $(TMPDIR)/libfoo.rmeta - $(CGREP) "Natvis v2" < $(TMPDIR)/libfoo.rmeta - $(CGREP) -v "Natvis v1" < $(TMPDIR)/libfoo.rmeta diff --git a/tests/run-make/incremental-debugger-visualizer/rmake.rs b/tests/run-make/incremental-debugger-visualizer/rmake.rs new file mode 100644 index 0000000000000..74de4e9909b34 --- /dev/null +++ b/tests/run-make/incremental-debugger-visualizer/rmake.rs @@ -0,0 +1,61 @@ +// This test makes sure that changes to files referenced via //[debugger_visualizer] +// are picked up when compiling incrementally. + +// We have to copy the source to $(TMPDIR) because Github CI mounts the source +// directory as readonly. We need to apply modifications to some of the source +// file. + +use run_make_support::{ + fs_wrapper, invalid_utf8_contains_str, invalid_utf8_not_contains_str, rustc, +}; +use std::io::Read; + +fn main() { + fs_wrapper::create_file("foo.py"); + fs_wrapper::write("foo.py", "GDB script v1"); + fs_wrapper::create_file("foo.natvis"); + fs_wrapper::write("foo.py", "Natvis v1"); + rustc() + .input("foo.rs") + .crate_type("rlib") + .emit("metadata") + .incremental("incremental") + .arg("-Zincremental-verify-ich") + .run(); + + invalid_utf8_contains_str("libfoo.rmeta", "GDB script v1"); + invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1"); + + // Change only the GDB script and check that the change has been picked up + fs_wrapper::remove_file("foo.py"); + fs_wrapper::create_file("foo.py"); + fs_wrapper::write("foo.py", "GDB script v2"); + rustc() + .input("foo.rs") + .crate_type("rlib") + .emit("metadata") + .incremental("incremental") + .arg("-Zincremental-verify-ich") + .run(); + + invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2"); + invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1"); + invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1"); + + // Now change the Natvis version and check that the change has been picked up + fs_wrapper::remove_file("foo.natvis"); + fs_wrapper::create_file("foo.natvis"); + fs_wrapper::write("foo.py", "Natvis v2"); + rustc() + .input("foo.rs") + .crate_type("rlib") + .emit("metadata") + .incremental("incremental") + .arg("-Zincremental-verify-ich") + .run(); + + invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2"); + invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1"); + invalid_utf8_not_contains_str("libfoo.rmeta", "Natvis v1"); + invalid_utf8_contains_str("libfoo.rmeta", "Natvis v2"); +} From cdfcc9442e08f863a96e9099c7dfb79cd5dfb52b Mon Sep 17 00:00:00 2001 From: Oneirical <manchot@videotron.ca> Date: Fri, 14 Jun 2024 15:28:15 -0400 Subject: [PATCH 3/3] rewrite incremental-session-fail to rmake --- src/tools/run-make-support/src/lib.rs | 30 +++++++++------- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/extern-flag-fun/rmake.rs | 6 ++-- .../incremental-debugger-visualizer/rmake.rs | 35 ++++++++----------- .../incremental-session-fail/Makefile | 14 -------- .../incremental-session-fail/rmake.rs | 15 ++++++++ 6 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 tests/run-make/incremental-session-fail/Makefile create mode 100644 tests/run-make/incremental-session-fail/rmake.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 784bbe572ab30..8d9976e27a585 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -274,23 +274,29 @@ pub fn set_host_rpath(cmd: &mut Command) { /// Read the contents of a file that cannot simply be read by /// read_to_string, due to invalid utf8 data, then assert that it contains `expected`. #[track_caller] -pub fn invalid_utf8_contains_str<P: AsRef<Path>>(path: P, expected: &str) { - use std::io::Read; - let mut file = std::fs::File::open(path).unwrap(); - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer).unwrap(); - assert!(String::from_utf8_lossy(&buffer).contains(expected)); +pub fn invalid_utf8_contains<P: AsRef<Path>>(path: P, expected: &str) { + let buffer = fs_wrapper::read(path.as_ref()); + if !String::from_utf8_lossy(&buffer).contains(expected) { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&buffer)); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was not found in file"); + } } /// Read the contents of a file that cannot simply be read by /// read_to_string, due to invalid utf8 data, then assert that it does not contain `expected`. #[track_caller] -pub fn invalid_utf8_not_contains_str<P: AsRef<Path>>(path: P, expected: &str) { - use std::io::Read; - let mut file = std::fs::File::open(path).unwrap(); - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer).unwrap(); - assert!(!String::from_utf8_lossy(&buffer).contains(expected)); +pub fn invalid_utf8_not_contains<P: AsRef<Path>>(path: P, expected: &str) { + let buffer = fs_wrapper::read(path.as_ref()); + if String::from_utf8_lossy(&buffer).contains(expected) { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&buffer)); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was unexpectedly found in file"); + } } /// Copy a directory into another. diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 7a08a9ab1a26f..1bc196419d021 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -67,7 +67,6 @@ run-make/inaccessible-temp-dir/Makefile run-make/include_bytes_deps/Makefile run-make/incr-add-rust-src-component/Makefile run-make/incr-foreign-head-span/Makefile -run-make/incremental-session-fail/Makefile run-make/inline-always-many-cgu/Makefile run-make/interdependent-c-libraries/Makefile run-make/intrinsic-unreachable/Makefile diff --git a/tests/run-make/extern-flag-fun/rmake.rs b/tests/run-make/extern-flag-fun/rmake.rs index 10fec6e30b423..c1825f6bbb888 100644 --- a/tests/run-make/extern-flag-fun/rmake.rs +++ b/tests/run-make/extern-flag-fun/rmake.rs @@ -5,21 +5,23 @@ // as non-private. This test checks that these rules are enforced. // See https://github.com/rust-lang/rust/pull/15319 -//@ ignore-cross-compile - use run_make_support::{rust_lib_name, rustc}; fn main() { rustc().input("bar.rs").crate_type("rlib").run(); + // Exactly the same rlib as the first line, only the filename changes. rustc().input("bar.rs").crate_type("rlib").extra_filename("-a").run(); rustc().input("bar-alt.rs").crate_type("rlib").run(); + // The crate must be valid. rustc().input("foo.rs").extern_("bar", "no-exist").run_fail(); rustc().input("foo.rs").extern_("bar", "foo.rs").run_fail(); + // Compilation fails with two different rlibs. rustc() .input("foo.rs") .extern_("bar", rust_lib_name("bar")) .extern_("bar", rust_lib_name("bar-alt")) .run_fail(); + // Even though this one has seemingly two rlibs, they are one and the same. rustc() .input("foo.rs") .extern_("bar", rust_lib_name("bar")) diff --git a/tests/run-make/incremental-debugger-visualizer/rmake.rs b/tests/run-make/incremental-debugger-visualizer/rmake.rs index 74de4e9909b34..1ef3af873530e 100644 --- a/tests/run-make/incremental-debugger-visualizer/rmake.rs +++ b/tests/run-make/incremental-debugger-visualizer/rmake.rs @@ -1,20 +1,15 @@ -// This test makes sure that changes to files referenced via //[debugger_visualizer] -// are picked up when compiling incrementally. +// This test ensures that changes to files referenced via #[debugger_visualizer] +// (in this case, foo.py and foo.natvis) are picked up when compiling incrementally. +// See https://github.com/rust-lang/rust/pull/111641 -// We have to copy the source to $(TMPDIR) because Github CI mounts the source -// directory as readonly. We need to apply modifications to some of the source -// file. - -use run_make_support::{ - fs_wrapper, invalid_utf8_contains_str, invalid_utf8_not_contains_str, rustc, -}; +use run_make_support::{fs_wrapper, invalid_utf8_contains, invalid_utf8_not_contains, rustc}; use std::io::Read; fn main() { fs_wrapper::create_file("foo.py"); fs_wrapper::write("foo.py", "GDB script v1"); fs_wrapper::create_file("foo.natvis"); - fs_wrapper::write("foo.py", "Natvis v1"); + fs_wrapper::write("foo.natvis", "Natvis v1"); rustc() .input("foo.rs") .crate_type("rlib") @@ -23,8 +18,8 @@ fn main() { .arg("-Zincremental-verify-ich") .run(); - invalid_utf8_contains_str("libfoo.rmeta", "GDB script v1"); - invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1"); + invalid_utf8_contains("libfoo.rmeta", "GDB script v1"); + invalid_utf8_contains("libfoo.rmeta", "Natvis v1"); // Change only the GDB script and check that the change has been picked up fs_wrapper::remove_file("foo.py"); @@ -38,14 +33,14 @@ fn main() { .arg("-Zincremental-verify-ich") .run(); - invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2"); - invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1"); - invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1"); + invalid_utf8_contains("libfoo.rmeta", "GDB script v2"); + invalid_utf8_not_contains("libfoo.rmeta", "GDB script v1"); + invalid_utf8_contains("libfoo.rmeta", "Natvis v1"); // Now change the Natvis version and check that the change has been picked up fs_wrapper::remove_file("foo.natvis"); fs_wrapper::create_file("foo.natvis"); - fs_wrapper::write("foo.py", "Natvis v2"); + fs_wrapper::write("foo.natvis", "Natvis v2"); rustc() .input("foo.rs") .crate_type("rlib") @@ -54,8 +49,8 @@ fn main() { .arg("-Zincremental-verify-ich") .run(); - invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2"); - invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1"); - invalid_utf8_not_contains_str("libfoo.rmeta", "Natvis v1"); - invalid_utf8_contains_str("libfoo.rmeta", "Natvis v2"); + invalid_utf8_contains("libfoo.rmeta", "GDB script v2"); + invalid_utf8_not_contains("libfoo.rmeta", "GDB script v1"); + invalid_utf8_not_contains("libfoo.rmeta", "Natvis v1"); + invalid_utf8_contains("libfoo.rmeta", "Natvis v2"); } diff --git a/tests/run-make/incremental-session-fail/Makefile b/tests/run-make/incremental-session-fail/Makefile deleted file mode 100644 index f43eece2eb709..0000000000000 --- a/tests/run-make/incremental-session-fail/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -include ../tools.mk - -SESSION_DIR := $(TMPDIR)/session -OUTPUT_FILE := $(TMPDIR)/build-output - -all: - echo $(TMPDIR) - # Make it so that rustc will fail to create a session directory. - touch $(SESSION_DIR) - # Check exit code is 1 for an error, and not 101 for ICE. - $(RUSTC) foo.rs --crate-type=rlib -C incremental=$(SESSION_DIR) > $(OUTPUT_FILE) 2>&1; [ $$? -eq 1 ] - $(CGREP) "could not create incremental compilation crate directory" < $(OUTPUT_FILE) - # -v tests are fragile, hopefully this text won't change - $(CGREP) -v "internal compiler error" < $(OUTPUT_FILE) diff --git a/tests/run-make/incremental-session-fail/rmake.rs b/tests/run-make/incremental-session-fail/rmake.rs new file mode 100644 index 0000000000000..0283709f2cf8c --- /dev/null +++ b/tests/run-make/incremental-session-fail/rmake.rs @@ -0,0 +1,15 @@ +// Failing to create the directory where output incremental +// files would be stored used to cause an ICE (Internal Compiler +// Error). This was patched in #85698, and this test checks that +// the ensuing compilation failure is not an ICE. +// See https://github.com/rust-lang/rust/pull/85698 + +use run_make_support::{fs_wrapper, rustc}; + +fn main() { + fs_wrapper::create_file("session"); + // rustc should fail to create the session directory here. + let out = rustc().input("foo.rs").crate_type("rlib").incremental("session").run_fail(); + out.assert_stderr_contains("could not create incremental compilation crate directory"); + out.assert_stderr_not_contains("internal compiler error"); +}