Rollup merge of #126500 - Oneirical:test-for-the-holy-grail, r=jieyouxu

Migrate `error-found-staticlib-instead-crate`, `output-filename-conflicts-with-directory`, `output-filename-overwrites-input`, `native-link-modifier-verbatim-rustc` and `native-link-verbatim-linker` `run-make` tests to `rmake.rs` format

Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).
This commit is contained in:
Guillaume Gomez 2024-06-18 15:30:45 +02:00 committed by GitHub
commit 6b9bcdca35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 134 additions and 58 deletions

View File

@ -35,7 +35,6 @@ 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-found-staticlib-instead-crate/Makefile
run-make/error-writing-dependencies/Makefile
run-make/export-executable-symbols/Makefile
run-make/extern-diff-internal-name/Makefile
@ -132,8 +131,6 @@ run-make/missing-crate-dependency/Makefile
run-make/mixing-libs/Makefile
run-make/msvc-opt-minsize/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/native-link-modifier-verbatim-linker/Makefile
run-make/native-link-modifier-verbatim-rustc/Makefile
run-make/native-link-modifier-whole-archive/Makefile
run-make/no-alloc-shim/Makefile
run-make/no-builtins-attribute/Makefile
@ -142,8 +139,6 @@ run-make/no-duplicate-libs/Makefile
run-make/obey-crate-type-flag/Makefile
run-make/optimization-remarks-dir-pgo/Makefile
run-make/optimization-remarks-dir/Makefile
run-make/output-filename-conflicts-with-directory/Makefile
run-make/output-filename-overwrites-input/Makefile
run-make/output-type-permutations/Makefile
run-make/override-aliased-flags/Makefile
run-make/overwrite-input/Makefile

View File

@ -1,5 +0,0 @@
include ../tools.mk
all:
$(RUSTC) foo.rs --crate-type staticlib
$(RUSTC) bar.rs 2>&1 | $(CGREP) "found staticlib"

View File

@ -0,0 +1,11 @@
// When rustc is looking for a crate but is given a staticlib instead,
// the error message should be helpful and indicate precisely the cause
// of the compilation failure.
// See https://github.com/rust-lang/rust/pull/21978
use run_make_support::rustc;
fn main() {
rustc().input("foo.rs").crate_type("staticlib").run();
rustc().input("bar.rs").run_fail().assert_stderr_contains("found staticlib");
}

View File

@ -1,15 +0,0 @@
# ignore-cross-compile
# ignore-apple
include ../tools.mk
all:
# Verbatim allows specify precise name.
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_some_strange_name.ext
$(RUSTC) main.rs -l static:+verbatim=local_some_strange_name.ext
# With verbatim any other name cannot be used (local).
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/liblocal_native_dep.a
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.a
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.lib
$(RUSTC) main.rs -l static:+verbatim=local_native_dep 2>&1 | $(CGREP) "local_native_dep"

View File

@ -0,0 +1,41 @@
// `verbatim` is a native link modifier that forces rustc to only accept libraries with
// a specified name. This test checks that this modifier works as intended.
// This test is the same as native-link-modifier-rustc, but without rlibs.
// See https://github.com/rust-lang/rust/issues/99425
//@ ignore-apple
// Reason: linking fails due to the unusual ".ext" staticlib name.
use run_make_support::rustc;
fn main() {
// Verbatim allows for the specification of a precise name
// - in this case, the unconventional ".ext" extension.
rustc()
.input("local_native_dep.rs")
.crate_type("staticlib")
.output("local_some_strange_name.ext")
.run();
rustc().input("main.rs").arg("-lstatic:+verbatim=local_some_strange_name.ext").run();
// This section voluntarily avoids using static_lib_name helpers to be verbatim.
// With verbatim, even these common library names are refused
// - it wants local_native_dep without
// any file extensions.
rustc()
.input("local_native_dep.rs")
.crate_type("staticlib")
.output("liblocal_native_dep.a")
.run();
rustc().input("local_native_dep.rs").crate_type("staticlib").output("local_native_dep.a").run();
rustc()
.input("local_native_dep.rs")
.crate_type("staticlib")
.output("local_native_dep.lib")
.run();
rustc()
.input("main.rs")
.arg("-lstatic:+verbatim=local_native_dep")
.run_fail()
.assert_stderr_contains("local_native_dep");
}

View File

@ -1,12 +0,0 @@
include ../tools.mk
all:
# Verbatim allows specify precise name.
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_some_strange_name.ext
$(RUSTC) rust_dep.rs -l static:+verbatim=upstream_some_strange_name.ext --crate-type rlib
# With verbatim any other name cannot be used (upstream).
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/libupstream_native_dep.a
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.a
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.lib
$(RUSTC) rust_dep.rs -l static:+verbatim=upstream_native_dep --crate-type rlib 2>&1 | $(CGREP) "upstream_native_dep"

View File

@ -0,0 +1,47 @@
// `verbatim` is a native link modifier that forces rustc to only accept libraries with
// a specified name. This test checks that this modifier works as intended.
// This test is the same as native-link-modifier-linker, but with rlibs.
// See https://github.com/rust-lang/rust/issues/99425
use run_make_support::rustc;
fn main() {
// Verbatim allows for the specification of a precise name
// - in this case, the unconventional ".ext" extension.
rustc()
.input("upstream_native_dep.rs")
.crate_type("staticlib")
.output("upstream_some_strange_name.ext")
.run();
rustc()
.input("rust_dep.rs")
.crate_type("rlib")
.arg("-lstatic:+verbatim=upstream_some_strange_name.ext")
.run();
// This section voluntarily avoids using static_lib_name helpers to be verbatim.
// With verbatim, even these common library names are refused
// - it wants upstream_native_dep without
// any file extensions.
rustc()
.input("upstream_native_dep.rs")
.crate_type("staticlib")
.output("libupstream_native_dep.a")
.run();
rustc()
.input("upstream_native_dep.rs")
.crate_type("staticlib")
.output("upstream_native_dep.a")
.run();
rustc()
.input("upstream_native_dep.rs")
.crate_type("staticlib")
.output("upstream_native_dep.lib")
.run();
rustc()
.input("rust_dep.rs")
.crate_type("rlib")
.arg("-lstatic:+verbatim=upstream_native_dep")
.run_fail()
.assert_stderr_contains("upstream_native_dep");
}

View File

@ -1,7 +0,0 @@
include ../tools.mk
all:
cp foo.rs $(TMPDIR)/foo.rs
mkdir $(TMPDIR)/foo
$(RUSTC) $(TMPDIR)/foo.rs -o $(TMPDIR)/foo 2>&1 \
| $(CGREP) -e "the generated executable for the input file \".*foo\.rs\" conflicts with the existing directory \".*foo\""

View File

@ -0,0 +1,14 @@
// ignore-tidy-linelength
// When the compiled executable would conflict with a directory, a
// rustc error should be displayed instead of a verbose and
// potentially-confusing linker error.
// See https://github.com/rust-lang/rust/pull/47203
use run_make_support::{fs_wrapper, rustc};
fn main() {
fs_wrapper::create_dir("foo");
rustc().input("foo.rs").output("foo").run_fail().assert_stderr_contains(
r#"the generated executable for the input file "foo.rs" conflicts with the existing directory "foo""#,
);
}

View File

@ -1,14 +0,0 @@
# ignore-cross-compile
include ../tools.mk
all:
cp foo.rs $(TMPDIR)/foo
$(RUSTC) $(TMPDIR)/foo -o $(TMPDIR)/foo 2>&1 \
| $(CGREP) -e "the input file \".*foo\" would be overwritten by the generated executable"
cp bar.rs $(TMPDIR)/bar.rlib
$(RUSTC) $(TMPDIR)/bar.rlib -o $(TMPDIR)/bar.rlib 2>&1 \
| $(CGREP) -e "the input file \".*bar.rlib\" would be overwritten by the generated executable"
$(RUSTC) foo.rs 2>&1 && $(RUSTC) -Z ls=root $(TMPDIR)/foo 2>&1
cp foo.rs $(TMPDIR)/foo.rs
$(RUSTC) $(TMPDIR)/foo.rs -o $(TMPDIR)/foo.rs 2>&1 \
| $(CGREP) -e "the input file \".*foo.rs\" would be overwritten by the generated executable"

View File

@ -0,0 +1,21 @@
// If rustc is invoked on a file that would be overwritten by the
// compilation, the compilation should fail, to avoid accidental loss.
// See https://github.com/rust-lang/rust/pull/46814
//@ ignore-cross-compile
use run_make_support::{fs_wrapper, rustc};
fn main() {
fs_wrapper::copy("foo.rs", "foo");
rustc().input("foo").output("foo").run_fail().assert_stderr_contains(
r#"the input file "foo" would be overwritten by the generated executable"#,
);
fs_wrapper::copy("bar.rs", "bar.rlib");
rustc().input("bar.rlib").output("bar.rlib").run_fail().assert_stderr_contains(
r#"the input file "bar.rlib" would be overwritten by the generated executable"#,
);
rustc().input("foo.rs").output("foo.rs").run_fail().assert_stderr_contains(
r#"the input file "foo.rs" would be overwritten by the generated executable"#,
);
}