Skip to content

Commit

Permalink
Auto merge of #126801 - Oneirical:seek-and-testroy, r=<try>
Browse files Browse the repository at this point in the history
Migrate `remap-path-prefix`, `debug-assertions` and `emit-stack-sizes` `run-make` tests to rmake

Part of #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
  • Loading branch information
bors committed Jun 21, 2024
2 parents c1b336c + 2931afd commit 578c14a
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 78 deletions.
11 changes: 11 additions & 0 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ impl Rustc {
self
}

/// Remap source path prefixes in all output.
pub fn remap_path_prefix<P: AsRef<Path>>(&mut self, from: P, to: P) -> &mut Self {
let from = from.as_ref().to_string_lossy();
let to = to.as_ref().to_string_lossy();

self.cmd.arg("--remap-path-prefix");
self.cmd.arg(format!("{from}={to}"));

self
}

/// Specify path to the input file.
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
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 @@ -19,7 +19,6 @@ run-make/cross-lang-lto-clang/Makefile
run-make/cross-lang-lto-pgo-smoketest/Makefile
run-make/cross-lang-lto-upstream-rlibs/Makefile
run-make/cross-lang-lto/Makefile
run-make/debug-assertions/Makefile
run-make/dep-info-doesnt-run-much/Makefile
run-make/dep-info-spaces/Makefile
run-make/dep-info/Makefile
Expand All @@ -28,7 +27,6 @@ run-make/dump-mono-stats/Makefile
run-make/dylib-chain/Makefile
run-make/emit-path-unhashed/Makefile
run-make/emit-shared-files/Makefile
run-make/emit-stack-sizes/Makefile
run-make/emit-to-stdout/Makefile
run-make/env-dep-info/Makefile
run-make/error-writing-dependencies/Makefile
Expand Down Expand Up @@ -157,7 +155,6 @@ run-make/redundant-libs/Makefile
run-make/relocation-model/Makefile
run-make/relro-levels/Makefile
run-make/remap-path-prefix-dwarf/Makefile
run-make/remap-path-prefix/Makefile
run-make/reproducible-build-2/Makefile
run-make/reproducible-build/Makefile
run-make/return-non-c-like-enum-from-c/Makefile
Expand Down
27 changes: 0 additions & 27 deletions tests/run-make/debug-assertions/Makefile

This file was deleted.

10 changes: 4 additions & 6 deletions tests/run-make/debug-assertions/debug.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#![allow(internal_features)]
#![feature(rustc_attrs)]
#![deny(warnings)]

use std::env;
use std::thread;

fn main() {
let should_fail = env::args().nth(1) == Some("bad".to_string());

assert_eq!(thread::spawn(debug_assert_eq).join().is_err(), should_fail);
assert_eq!(thread::spawn(debug_assert).join().is_err(), should_fail);
assert_eq!(thread::spawn(overflow).join().is_err(), should_fail);
assert!(thread::spawn(debug_assert_eq).join().is_ok());
assert!(thread::spawn(debug_assert).join().is_ok());
assert!(thread::spawn(overflow).join().is_ok());
}

fn debug_assert_eq() {
Expand Down
37 changes: 37 additions & 0 deletions tests/run-make/debug-assertions/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// debug.rs contains some "debug assertion" statements which
// should only be enabled in either non-optimized builds or when
// `-C debug-assertions` is set to yes. These debug assertions
// are guaranteed to fail, so this test checks that the run command
// fails where debug assertions should be activated, and succeeds where
// debug assertions should be disabled.
// See https://github.com/rust-lang/rust/pull/22980

//@ ignore-cross-compile
//@ needs-unwind

use run_make_support::{run, run_fail, rustc};

fn main() {
rustc().input("debug.rs").arg("-Cdebug-assertions=no").run();
run("debug");
rustc().input("debug.rs").opt_level("0").run();
run_fail("debug");
rustc().input("debug.rs").opt_level("1").run();
run("debug");
rustc().input("debug.rs").opt_level("2").run();
run("debug");
rustc().input("debug.rs").opt_level("3").run();
run("debug");
rustc().input("debug.rs").opt_level("s").run();
run("debug");
rustc().input("debug.rs").opt_level("z").run();
run("debug");
rustc().input("debug.rs").opt().run();
run("debug");
rustc().input("debug.rs").run();
run_fail("debug");
rustc().input("debug.rs").opt().arg("-Cdebug-assertions=yes").run();
run_fail("debug");
rustc().input("debug.rs").opt_level("1").arg("-Cdebug-assertions=yes").run();
run_fail("debug");
}
12 changes: 0 additions & 12 deletions tests/run-make/emit-stack-sizes/Makefile

This file was deleted.

23 changes: 23 additions & 0 deletions tests/run-make/emit-stack-sizes/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Running rustc with the -Z emit-stack-sizes
// flag enables diagnostics to seek stack overflows
// at compile time. This test compiles a rust file
// with this flag, then checks that the output object
// file contains the section "stack_sizes", where
// this diagnostics information should be located.
// See https://github.com/rust-lang/rust/pull/51946
// FIXME(Oneirical): temporarily disabled ignore flags for test
// here is ignore-windows
// and ignore-apple
// Supposedly, this feature only works when the output object format is ELF so we ignore
// Apple and Windows

use run_make_support::{llvm_readobj, rustc};

fn main() {
rustc().opt_level("3").arg("-Zemit-stack-sizes").emit("obj").input("foo.rs").run();
llvm_readobj()
.arg("--section-headers")
.input("foo.o")
.run()
.assert_stdout_contains(".stack_sizes");
}
30 changes: 0 additions & 30 deletions tests/run-make/remap-path-prefix/Makefile

This file was deleted.

58 changes: 58 additions & 0 deletions tests/run-make/remap-path-prefix/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Generating metadata alongside remap-path-prefix would fail to actually remap the path
// in the metadata. After this was fixed in #85344, this test checks that "auxiliary" is being
// successfully remapped to "/the/aux" in the rmeta files.
// See https://github.com/rust-lang/rust/pull/85344

// FIXME(Oneirical): check if works without ignore-windows

use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, is_darwin, rustc};

fn main() {
let mut out_simple = rustc();
let mut out_object = rustc();
let mut out_macro = rustc();
let mut out_diagobj = rustc();
out_simple
.remap_path_prefix("auxiliary", "/the/aux")
.crate_type("lib")
.emit("metadata")
.input("auxiliary/lib.rs");
out_object
.remap_path_prefix("auxiliary", "/the/aux")
.crate_type("lib")
.emit("metadata")
.input("auxiliary/lib.rs");
out_macro
.remap_path_prefix("auxiliary", "/the/aux")
.crate_type("lib")
.emit("metadata")
.input("auxiliary/lib.rs");
out_diagobj
.remap_path_prefix("auxiliary", "/the/aux")
.crate_type("lib")
.emit("metadata")
.input("auxiliary/lib.rs");

out_simple.run();
invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
invalid_utf8_not_contains("liblib.rmeta", "auxiliary");

out_object.arg("-Zremap-path-scope=object");
out_macro.arg("-Zremap-path-scope=macro");
out_diagobj.arg("-Zremap-path-scope=diagnostics,object");
if is_darwin() {
out_object.arg("-Csplit-debuginfo=off");
out_macro.arg("-Csplit-debuginfo=off");
out_diagobj.arg("-Csplit-debuginfo=off");
}

out_object.run();
invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
out_macro.run();
invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
out_diagobj.run();
invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
}

0 comments on commit 578c14a

Please sign in to comment.