Skip to content

Commit eb51c63

Browse files
committed
Auto merge of rust-lang#126490 - Oneirical:testicide, r=<try>
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
2 parents 55cac26 + abf6b17 commit eb51c63

File tree

8 files changed

+131
-86
lines changed

8 files changed

+131
-86
lines changed

src/tools/run-make-support/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,28 @@ pub fn set_host_rpath(cmd: &mut Command) {
271271
});
272272
}
273273

274+
/// Read the contents of a file that cannot simply be read by
275+
/// read_to_string, due to invalid utf8 data, then assert that it contains `expected`.
276+
#[track_caller]
277+
pub fn invalid_utf8_contains_str<P: AsRef<Path>>(path: P, expected: &str) {
278+
use std::io::Read;
279+
let mut file = std::fs::File::open(path).unwrap();
280+
let mut buffer = Vec::new();
281+
file.read_to_end(&mut buffer).unwrap();
282+
assert!(String::from_utf8_lossy(&buffer).contains(expected));
283+
}
284+
285+
/// Read the contents of a file that cannot simply be read by
286+
/// read_to_string, due to invalid utf8 data, then assert that it does not contain `expected`.
287+
#[track_caller]
288+
pub fn invalid_utf8_not_contains_str<P: AsRef<Path>>(path: P, expected: &str) {
289+
use std::io::Read;
290+
let mut file = std::fs::File::open(path).unwrap();
291+
let mut buffer = Vec::new();
292+
file.read_to_end(&mut buffer).unwrap();
293+
assert!(!String::from_utf8_lossy(&buffer).contains(expected));
294+
}
295+
274296
/// Copy a directory into another.
275297
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
276298
fn copy_dir_all_inner(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {

src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ run-make/error-writing-dependencies/Makefile
4040
run-make/export-executable-symbols/Makefile
4141
run-make/extern-diff-internal-name/Makefile
4242
run-make/extern-flag-disambiguates/Makefile
43-
run-make/extern-flag-fun/Makefile
4443
run-make/extern-flag-pathless/Makefile
4544
run-make/extern-flag-rename-transitive/Makefile
4645
run-make/extern-fn-explicit-align/Makefile
@@ -65,8 +64,6 @@ run-make/inaccessible-temp-dir/Makefile
6564
run-make/include_bytes_deps/Makefile
6665
run-make/incr-add-rust-src-component/Makefile
6766
run-make/incr-foreign-head-span/Makefile
68-
run-make/incremental-debugger-visualizer/Makefile
69-
run-make/incremental-session-fail/Makefile
7067
run-make/inline-always-many-cgu/Makefile
7168
run-make/interdependent-c-libraries/Makefile
7269
run-make/intrinsic-unreachable/Makefile

tests/run-make/extern-flag-fun/Makefile

-20
This file was deleted.
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// The --extern flag can override the default crate search of
2+
// the compiler and directly fetch a given path. There are a few rules
3+
// to follow: for example, there can't be more than one rlib, the crates must
4+
// be valid ("no-exist" in this test), and private crates can't be loaded
5+
// as non-private. This test checks that these rules are enforced.
6+
// See https://github.com/rust-lang/rust/pull/15319
7+
8+
//@ ignore-cross-compile
9+
10+
use run_make_support::{rust_lib_name, rustc};
11+
12+
fn main() {
13+
rustc().input("bar.rs").crate_type("rlib").run();
14+
rustc().input("bar.rs").crate_type("rlib").extra_filename("-a").run();
15+
rustc().input("bar-alt.rs").crate_type("rlib").run();
16+
rustc().input("foo.rs").extern_("bar", "no-exist").run_fail();
17+
rustc().input("foo.rs").extern_("bar", "foo.rs").run_fail();
18+
rustc()
19+
.input("foo.rs")
20+
.extern_("bar", rust_lib_name("bar"))
21+
.extern_("bar", rust_lib_name("bar-alt"))
22+
.run_fail();
23+
rustc()
24+
.input("foo.rs")
25+
.extern_("bar", rust_lib_name("bar"))
26+
.extern_("bar", rust_lib_name("bar-a"))
27+
.run();
28+
rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).run();
29+
// Try to be sneaky and load a private crate from with a non-private name.
30+
rustc().input("rustc.rs").arg("-Zforce-unstable-if-unmarked").crate_type("rlib").run();
31+
rustc()
32+
.input("gated_unstable.rs")
33+
.extern_("alloc", rust_lib_name("rustc"))
34+
.run_fail()
35+
.assert_stderr_contains("rustc_private");
36+
}

tests/run-make/incremental-debugger-visualizer/Makefile

-49
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// This test ensures that changes to files referenced via //[debugger_visualizer]
2+
// (in this case, foo.py and foo.natvis) are picked up when compiling incrementally.
3+
// See https://github.com/rust-lang/rust/pull/111641
4+
5+
use run_make_support::{
6+
fs_wrapper, invalid_utf8_contains_str, invalid_utf8_not_contains_str, rustc,
7+
};
8+
use std::io::Read;
9+
10+
fn main() {
11+
fs_wrapper::create_file("foo.py");
12+
fs_wrapper::write("foo.py", "GDB script v1");
13+
fs_wrapper::create_file("foo.natvis");
14+
fs_wrapper::write("foo.natvis", "Natvis v1");
15+
rustc()
16+
.input("foo.rs")
17+
.crate_type("rlib")
18+
.emit("metadata")
19+
.incremental("incremental")
20+
.arg("-Zincremental-verify-ich")
21+
.run();
22+
23+
invalid_utf8_contains_str("libfoo.rmeta", "GDB script v1");
24+
invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1");
25+
26+
// Change only the GDB script and check that the change has been picked up
27+
fs_wrapper::remove_file("foo.py");
28+
fs_wrapper::create_file("foo.py");
29+
fs_wrapper::write("foo.py", "GDB script v2");
30+
rustc()
31+
.input("foo.rs")
32+
.crate_type("rlib")
33+
.emit("metadata")
34+
.incremental("incremental")
35+
.arg("-Zincremental-verify-ich")
36+
.run();
37+
38+
invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2");
39+
invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1");
40+
invalid_utf8_contains_str("libfoo.rmeta", "Natvis v1");
41+
42+
// Now change the Natvis version and check that the change has been picked up
43+
fs_wrapper::remove_file("foo.natvis");
44+
fs_wrapper::create_file("foo.natvis");
45+
fs_wrapper::write("foo.natvis", "Natvis v2");
46+
rustc()
47+
.input("foo.rs")
48+
.crate_type("rlib")
49+
.emit("metadata")
50+
.incremental("incremental")
51+
.arg("-Zincremental-verify-ich")
52+
.run();
53+
54+
invalid_utf8_contains_str("libfoo.rmeta", "GDB script v2");
55+
invalid_utf8_not_contains_str("libfoo.rmeta", "GDB script v1");
56+
invalid_utf8_not_contains_str("libfoo.rmeta", "Natvis v1");
57+
invalid_utf8_contains_str("libfoo.rmeta", "Natvis v2");
58+
}

tests/run-make/incremental-session-fail/Makefile

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Failing to create the directory where output incremental
2+
// files would be stored used to cause an ICE (Internal Compiler
3+
// Error). This was patched in #85698, and this test checks that
4+
// the ensuing compilation failure is not an ICE.
5+
// See https://github.com/rust-lang/rust/pull/85698
6+
7+
use run_make_support::{fs_wrapper, rustc};
8+
9+
fn main() {
10+
fs_wrapper::create_file("session");
11+
// rustc should fail to create the session directory here.
12+
let out = rustc().input("foo.rs").crate_type("rlib").incremental("session").run_fail();
13+
out.assert_stderr_contains("could not create incremental compilation crate directory");
14+
out.assert_stderr_not_contains("internal compiler error");
15+
}

0 commit comments

Comments
 (0)