Skip to content

Commit 00da98a

Browse files
committed
Auto merge of rust-lang#126801 - Oneirical:seek-and-testroy, r=<try>
Migrate `remap-path-prefix`, `debug-assertions` and `emit-stack-sizes` `run-make` tests to rmake 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). Needs OSX/MSVC try jobs. try-job: aarch64-apple try-job: x86_64-msvc
2 parents 99f77a2 + 2e1fd8f commit 00da98a

File tree

12 files changed

+167
-78
lines changed

12 files changed

+167
-78
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3401,6 +3401,7 @@ name = "run_make_support"
34013401
version = "0.2.0"
34023402
dependencies = [
34033403
"ar",
3404+
"bstr",
34043405
"gimli 0.28.1",
34053406
"object 0.34.0",
34063407
"regex",

src/tools/run-make-support/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.2.0"
44
edition = "2021"
55

66
[dependencies]
7+
bstr = "1.6.0"
78
object = "0.34.0"
89
similar = "2.5.0"
910
wasmparser = "0.118.2"

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

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::io;
2121
use std::panic;
2222
use std::path::{Path, PathBuf};
2323

24+
pub use bstr;
2425
pub use gimli;
2526
pub use object;
2627
pub use regex;

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

+11
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ impl Rustc {
106106
self
107107
}
108108

109+
/// Remap source path prefixes in all output.
110+
pub fn remap_path_prefix<P: AsRef<Path>>(&mut self, from: P, to: P) -> &mut Self {
111+
let from = from.as_ref().to_string_lossy();
112+
let to = to.as_ref().to_string_lossy();
113+
114+
self.cmd.arg("--remap-path-prefix");
115+
self.cmd.arg(format!("{from}={to}"));
116+
117+
self
118+
}
119+
109120
/// Specify path to the input file.
110121
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
111122
self.cmd.arg(path.as_ref());

src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ run-make/cross-lang-lto-clang/Makefile
1818
run-make/cross-lang-lto-pgo-smoketest/Makefile
1919
run-make/cross-lang-lto-upstream-rlibs/Makefile
2020
run-make/cross-lang-lto/Makefile
21-
run-make/debug-assertions/Makefile
2221
run-make/dep-info-doesnt-run-much/Makefile
2322
run-make/dep-info-spaces/Makefile
2423
run-make/dep-info/Makefile
@@ -27,7 +26,6 @@ run-make/dump-mono-stats/Makefile
2726
run-make/dylib-chain/Makefile
2827
run-make/emit-path-unhashed/Makefile
2928
run-make/emit-shared-files/Makefile
30-
run-make/emit-stack-sizes/Makefile
3129
run-make/emit-to-stdout/Makefile
3230
run-make/env-dep-info/Makefile
3331
run-make/export-executable-symbols/Makefile
@@ -148,7 +146,6 @@ run-make/raw-dylib-link-ordinal/Makefile
148146
run-make/raw-dylib-stdcall-ordinal/Makefile
149147
run-make/redundant-libs/Makefile
150148
run-make/remap-path-prefix-dwarf/Makefile
151-
run-make/remap-path-prefix/Makefile
152149
run-make/reproducible-build-2/Makefile
153150
run-make/reproducible-build/Makefile
154151
run-make/return-non-c-like-enum-from-c/Makefile

tests/run-make/debug-assertions/Makefile

-27
This file was deleted.

tests/run-make/debug-assertions/debug.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
#![allow(internal_features)]
12
#![feature(rustc_attrs)]
23
#![deny(warnings)]
34

4-
use std::env;
55
use std::thread;
66

77
fn main() {
8-
let should_fail = env::args().nth(1) == Some("bad".to_string());
9-
10-
assert_eq!(thread::spawn(debug_assert_eq).join().is_err(), should_fail);
11-
assert_eq!(thread::spawn(debug_assert).join().is_err(), should_fail);
12-
assert_eq!(thread::spawn(overflow).join().is_err(), should_fail);
8+
assert!(thread::spawn(debug_assert_eq).join().is_ok());
9+
assert!(thread::spawn(debug_assert).join().is_ok());
10+
assert!(thread::spawn(overflow).join().is_ok());
1311
}
1412

1513
fn debug_assert_eq() {
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// debug.rs contains some "debug assertion" statements which
2+
// should only be enabled in either non-optimized builds or when
3+
// `-C debug-assertions` is set to yes. These debug assertions
4+
// are guaranteed to fail, so this test checks that the run command
5+
// fails where debug assertions should be activated, and succeeds where
6+
// debug assertions should be disabled.
7+
// See https://github.com/rust-lang/rust/pull/22980
8+
9+
//@ ignore-cross-compile
10+
//@ needs-unwind
11+
12+
use run_make_support::{run, run_fail, rustc};
13+
14+
fn main() {
15+
rustc().input("debug.rs").arg("-Cdebug-assertions=no").run();
16+
run("debug");
17+
rustc().input("debug.rs").opt_level("0").run();
18+
run_fail("debug");
19+
rustc().input("debug.rs").opt_level("1").run();
20+
run("debug");
21+
rustc().input("debug.rs").opt_level("2").run();
22+
run("debug");
23+
rustc().input("debug.rs").opt_level("3").run();
24+
run("debug");
25+
rustc().input("debug.rs").opt_level("s").run();
26+
run("debug");
27+
rustc().input("debug.rs").opt_level("z").run();
28+
run("debug");
29+
rustc().input("debug.rs").opt().run();
30+
run("debug");
31+
rustc().input("debug.rs").run();
32+
run_fail("debug");
33+
rustc().input("debug.rs").opt().arg("-Cdebug-assertions=yes").run();
34+
run_fail("debug");
35+
rustc().input("debug.rs").opt_level("1").arg("-Cdebug-assertions=yes").run();
36+
run_fail("debug");
37+
}

tests/run-make/emit-stack-sizes/Makefile

-12
This file was deleted.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Running rustc with the -Z emit-stack-sizes
2+
// flag enables diagnostics to seek stack overflows
3+
// at compile time. This test compiles a rust file
4+
// with this flag, then checks that the output object
5+
// file contains the section "stack_sizes", where
6+
// this diagnostics information should be located.
7+
// See https://github.com/rust-lang/rust/pull/51946
8+
9+
//@ ignore-windows
10+
//@ ignore-apple
11+
// Reason: this feature only works when the output object format is ELF.
12+
// This won't be the case on Windows/OSX - for example, OSX produces a Mach-O binary.
13+
14+
use run_make_support::{llvm_readobj, rustc};
15+
16+
fn main() {
17+
rustc().opt_level("3").arg("-Zemit-stack-sizes").emit("obj").input("foo.rs").run();
18+
llvm_readobj()
19+
.arg("--section-headers")
20+
.input("foo.o")
21+
.run()
22+
.assert_stdout_contains(".stack_sizes");
23+
}

tests/run-make/remap-path-prefix/Makefile

-30
This file was deleted.
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Generating metadata alongside remap-path-prefix would fail to actually remap the path
2+
// in the metadata. After this was fixed in #85344, this test checks that "auxiliary" is being
3+
// successfully remapped to "/the/aux" in the rmeta files.
4+
// See https://github.com/rust-lang/rust/pull/85344
5+
6+
// FIXME(Oneirical): check if works without ignore-windows
7+
8+
use run_make_support::bstr::ByteSlice;
9+
use run_make_support::{bstr, fs_wrapper, is_darwin, rustc};
10+
11+
fn main() {
12+
let mut out_simple = rustc();
13+
let mut out_object = rustc();
14+
let mut out_macro = rustc();
15+
let mut out_diagobj = rustc();
16+
out_simple
17+
.remap_path_prefix("auxiliary", "/the/aux")
18+
.crate_type("lib")
19+
.emit("metadata")
20+
.input("auxiliary/lib.rs");
21+
out_object
22+
.remap_path_prefix("auxiliary", "/the/aux")
23+
.crate_type("lib")
24+
.emit("metadata")
25+
.input("auxiliary/lib.rs");
26+
out_macro
27+
.remap_path_prefix("auxiliary", "/the/aux")
28+
.crate_type("lib")
29+
.emit("metadata")
30+
.input("auxiliary/lib.rs");
31+
out_diagobj
32+
.remap_path_prefix("auxiliary", "/the/aux")
33+
.crate_type("lib")
34+
.emit("metadata")
35+
.input("auxiliary/lib.rs");
36+
37+
out_simple.run();
38+
rmeta_contains("/the/aux/lib.rs");
39+
rmeta_not_contains("auxiliary");
40+
41+
out_object.arg("-Zremap-path-scope=object");
42+
out_macro.arg("-Zremap-path-scope=macro");
43+
out_diagobj.arg("-Zremap-path-scope=diagnostics,object");
44+
if is_darwin() {
45+
out_object.arg("-Csplit-debuginfo=off");
46+
out_macro.arg("-Csplit-debuginfo=off");
47+
out_diagobj.arg("-Csplit-debuginfo=off");
48+
}
49+
50+
out_object.run();
51+
rmeta_contains("/the/aux/lib.rs");
52+
rmeta_not_contains("auxiliary");
53+
out_macro.run();
54+
rmeta_contains("/the/aux/lib.rs");
55+
rmeta_not_contains("auxiliary");
56+
out_diagobj.run();
57+
rmeta_contains("/the/aux/lib.rs");
58+
rmeta_not_contains("auxiliary");
59+
}
60+
61+
//FIXME(Oneirical): These could be generalized into run_make_support
62+
// helper functions.
63+
fn rmeta_contains(expected: &str) {
64+
// Normalize to account for path differences in Windows.
65+
if !bstr::BString::from(fs_wrapper::read("liblib.rmeta"))
66+
.replace(b"\\", b"/")
67+
.contains_str(expected)
68+
{
69+
eprintln!("=== FILE CONTENTS (LOSSY) ===");
70+
eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta")));
71+
eprintln!("=== SPECIFIED TEXT ===");
72+
eprintln!("{}", expected);
73+
panic!("specified text was not found in file");
74+
}
75+
}
76+
77+
fn rmeta_not_contains(expected: &str) {
78+
// Normalize to account for path differences in Windows.
79+
if bstr::BString::from(fs_wrapper::read("liblib.rmeta"))
80+
.replace(b"\\", b"/")
81+
.contains_str(expected)
82+
{
83+
eprintln!("=== FILE CONTENTS (LOSSY) ===");
84+
eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta")));
85+
eprintln!("=== SPECIFIED TEXT ===");
86+
eprintln!("{}", expected);
87+
panic!("specified text was not found in file");
88+
}
89+
}

0 commit comments

Comments
 (0)