Rollup merge of #127381 - Oneirical:testalt-consciousness, r=jieyouxu

Migrate `issue-83045`, `rustc-macro-dep-files` and `env-dep-info` `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).

Please try on musl.

try-job: dist-x86_64-musl
This commit is contained in:
Jubilee 2024-07-12 13:47:08 -07:00 committed by GitHub
commit 38c314e29d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 96 additions and 69 deletions

View File

@ -4,13 +4,15 @@ use std::path::Path;
use crate::{command, cwd, env_var, set_host_rpath};
/// Construct a new `rustc` invocation.
/// Construct a new `rustc` invocation. This will automatically set the library
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
#[track_caller]
pub fn rustc() -> Rustc {
Rustc::new()
}
/// Construct a plain `rustc` invocation with no flags set.
/// Construct a plain `rustc` invocation with no flags set. Note that [`set_host_rpath`]
/// still presets the environment variable `HOST_RPATH_DIR` by default.
#[track_caller]
pub fn bare_rustc() -> Rustc {
Rustc::bare()
@ -42,7 +44,8 @@ fn setup_common() -> Command {
impl Rustc {
// `rustc` invocation constructor methods
/// Construct a new `rustc` invocation.
/// Construct a new `rustc` invocation. This will automatically set the library
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
#[track_caller]
pub fn new() -> Self {
let mut cmd = setup_common();

View File

@ -23,7 +23,6 @@ run-make/dep-info/Makefile
run-make/dump-ice-to-disk/Makefile
run-make/dump-mono-stats/Makefile
run-make/emit-to-stdout/Makefile
run-make/env-dep-info/Makefile
run-make/export-executable-symbols/Makefile
run-make/extern-diff-internal-name/Makefile
run-make/extern-flag-disambiguates/Makefile
@ -57,7 +56,6 @@ run-make/issue-35164/Makefile
run-make/issue-36710/Makefile
run-make/issue-47551/Makefile
run-make/issue-69368/Makefile
run-make/issue-83045/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
run-make/issue-85401-static-mir/Makefile
run-make/issue-88756-default-output/Makefile
@ -114,7 +112,6 @@ run-make/return-non-c-like-enum-from-c/Makefile
run-make/rlib-format-packed-bundled-libs-2/Makefile
run-make/rlib-format-packed-bundled-libs-3/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/rustc-macro-dep-files/Makefile
run-make/sanitizer-cdylib-link/Makefile
run-make/sanitizer-dylib-link/Makefile
run-make/sanitizer-staticlib-link/Makefile

View File

@ -1,19 +0,0 @@
include ../tools.mk
# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC`
# instead of hardcoding them everywhere they're needed.
ifeq ($(IS_MUSL_HOST),1)
ADDITIONAL_ARGS := $(RUSTFLAGS)
endif
all:
EXISTING_ENV=1 EXISTING_OPT_ENV=1 $(RUSTC) --emit dep-info main.rs
$(CGREP) "# env-dep:EXISTING_ENV=1" < $(TMPDIR)/main.d
$(CGREP) "# env-dep:EXISTING_OPT_ENV=1" < $(TMPDIR)/main.d
$(CGREP) "# env-dep:NONEXISTENT_OPT_ENV" < $(TMPDIR)/main.d
$(CGREP) "# env-dep:ESCAPE\nESCAPE\\" < $(TMPDIR)/main.d
# Proc macro
$(BARE_RUSTC) $(ADDITIONAL_ARGS) --out-dir $(TMPDIR) macro_def.rs
EXISTING_PROC_MACRO_ENV=1 $(RUSTC) --emit dep-info macro_use.rs
$(CGREP) "# env-dep:EXISTING_PROC_MACRO_ENV=1" < $(TMPDIR)/macro_use.d
$(CGREP) "# env-dep:NONEXISTENT_PROC_MACEO_ENV" < $(TMPDIR)/macro_use.d

View File

@ -0,0 +1,6 @@
macro_use.d: macro_use.rs
macro_use.rs:
# env-dep:EXISTING_PROC_MACRO_ENV=1
# env-dep:NONEXISTENT_PROC_MACEO_ENV

View File

@ -0,0 +1,8 @@
main.d: main.rs
main.rs:
# env-dep:ESCAPE\nESCAPE\\
# env-dep:EXISTING_ENV=1
# env-dep:EXISTING_OPT_ENV=1
# env-dep:NONEXISTENT_OPT_ENV

View File

@ -0,0 +1,21 @@
// Inside dep-info emit files, #71858 made it so all accessed environment
// variables are usefully printed. This test checks that this feature works
// as intended by checking if the environment variables used in compilation
// appear in the output dep-info files.
// See https://github.com/rust-lang/rust/issues/40364
use run_make_support::{diff, rustc};
fn main() {
rustc()
.env("EXISTING_ENV", "1")
.env("EXISTING_OPT_ENV", "1")
.emit("dep-info")
.input("main.rs")
.run();
diff().expected_file("correct_main.d").actual_file("main.d").run();
// Procedural macro
rustc().input("macro_def.rs").run();
rustc().env("EXISTING_PROC_MACRO_ENV", "1").emit("dep-info").input("macro_use.rs").run();
diff().expected_file("correct_macro.d").actual_file("macro_use.d").run();
}

View File

@ -0,0 +1,38 @@
// This test case creates a situation where the crate loader would run
// into an ICE (internal compiler error) when confronted with an invalid setup where it cannot
// find the dependency of a direct dependency.
//
// The test case makes sure that the compiler produces the expected
// error message but does not ICE immediately after.
//
// See https://github.com/rust-lang/rust/issues/83045
//@ only-x86_64
//@ only-linux
// Reason: This is a platform-independent issue, no need to waste time testing
// everywhere.
// NOTE: We use `bare_rustc` below so that the compiler can't find liba.rlib
// If we used `rustc` the additional '-L rmake_out' option would allow rustc to
// actually find the crate.
use run_make_support::{bare_rustc, fs_wrapper, rust_lib_name, rustc};
fn main() {
rustc().crate_name("a").crate_type("rlib").input("a.rs").arg("--verbose").run();
rustc()
.crate_name("b")
.crate_type("rlib")
.extern_("a", rust_lib_name("a"))
.input("b.rs")
.arg("--verbose")
.run();
bare_rustc()
.extern_("b", rust_lib_name("b"))
.crate_type("rlib")
.edition("2018")
.input("c.rs")
.run_fail()
.assert_stderr_contains("E0463")
.assert_stderr_not_contains("internal compiler error");
}

View File

@ -1,33 +0,0 @@
include ../tools.mk
# This test case creates a situation where the crate loader would run
# into an ICE when confronted with an invalid setup where it cannot
# find the dependency of a direct dependency.
#
# The test case makes sure that the compiler produces the expected
# error message but does not ICE immediately after.
#
# See https://github.com/rust-lang/rust/issues/83045
# This is a platform-independent issue, no need to waste time testing
# everywhere.
# only-x86_64
# only-linux
# NOTE: We use BARE_RUSTC below so that the compiler can't find liba.rlib
# If we used RUSTC the additional '-L TMPDIR' option would allow rustc to
# actually find the crate.
#
# We check that we get the expected error message
# But that we do not get an ICE
all:
$(RUSTC) --crate-name=a --crate-type=rlib a.rs --verbose
$(RUSTC) --crate-name=b --crate-type=rlib --extern a=$(TMPDIR)/liba.rlib b.rs --verbose
$(BARE_RUSTC) --out-dir $(TMPDIR) \
--extern b=$(TMPDIR)/libb.rlib \
--crate-type=rlib \
--edition=2018 \
c.rs 2>&1 | tee $(TMPDIR)/output.txt || exit 0
$(CGREP) E0463 < $(TMPDIR)/output.txt
$(CGREP) -v "internal compiler error" < $(TMPDIR)/output.txt

View File

@ -1,11 +0,0 @@
include ../tools.mk
# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC`
# instead of hardcoding them everywhere they're needed.
ifeq ($(IS_MUSL_HOST),1)
ADDITIONAL_ARGS := $(RUSTFLAGS)
endif
all:
$(BARE_RUSTC) $(ADDITIONAL_ARGS) foo.rs --out-dir $(TMPDIR)
$(RUSTC) bar.rs --target $(TARGET) --emit dep-info
$(CGREP) -v "proc-macro source" < $(TMPDIR)/bar.d

View File

@ -0,0 +1,3 @@
bar.d: bar.rs
bar.rs:

View File

@ -0,0 +1,14 @@
// --emit dep-info used to print all macro-generated code it could
// find as if it was part of a nonexistent file named "proc-macro source",
// which is not a valid path. After this was fixed in #36776, this test checks
// that macro code is not falsely seen as coming from a different file in dep-info.
// See https://github.com/rust-lang/rust/issues/36625
use run_make_support::{diff, rustc, target};
fn main() {
rustc().input("foo.rs").run();
rustc().input("bar.rs").target(target()).emit("dep-info").run();
// The emitted file should not contain "proc-macro source".
diff().expected_file("correct.d").actual_file("bar.d").run();
}