Skip to content

Commit

Permalink
Auto merge of rust-lang#126490 - Oneirical:testicide, r=<try>
Browse files Browse the repository at this point in the history
Migrate `extern-flag-fun`, `incremental-debugger-visualiser` and `incremental-session-fail` `run-make` tests to `rmake.rs`

Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

try-job: arm-android
try-job: armhf-gnu
try-job: test-various
try-job: x86_64-msvc
try-job: dist-i686-mingw
  • Loading branch information
bors committed Jun 16, 2024
2 parents 55cac26 + abf6b17 commit eb51c63
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 86 deletions.
22 changes: 22 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
3 changes: 0 additions & 3 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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
Expand All @@ -65,8 +64,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
run-make/intrinsic-unreachable/Makefile
Expand Down
20 changes: 0 additions & 20 deletions tests/run-make/extern-flag-fun/Makefile

This file was deleted.

36 changes: 36 additions & 0 deletions tests/run-make/extern-flag-fun/rmake.rs
Original file line number Diff line number Diff line change
@@ -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");
}
49 changes: 0 additions & 49 deletions tests/run-make/incremental-debugger-visualizer/Makefile

This file was deleted.

58 changes: 58 additions & 0 deletions tests/run-make/incremental-debugger-visualizer/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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

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.natvis", "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.natvis", "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");
}
14 changes: 0 additions & 14 deletions tests/run-make/incremental-session-fail/Makefile

This file was deleted.

15 changes: 15 additions & 0 deletions tests/run-make/incremental-session-fail/rmake.rs
Original file line number Diff line number Diff line change
@@ -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");
}

0 comments on commit eb51c63

Please sign in to comment.