Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate libs-through-symlinks and translation run-make tests to rmake #129011

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ run-make/extern-fn-reachable/Makefile
run-make/incr-add-rust-src-component/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
run-make/jobserver-error/Makefile
run-make/libs-through-symlinks/Makefile
run-make/libtest-thread-limit/Makefile
run-make/macos-deployment-target/Makefile
run-make/reproducible-build/Makefile
run-make/split-debuginfo/Makefile
run-make/symbol-mangling-hashed/Makefile
run-make/translation/Makefile
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
12 changes: 0 additions & 12 deletions tests/run-make/libs-through-symlinks/Makefile

This file was deleted.

17 changes: 17 additions & 0 deletions tests/run-make/libs-through-symlinks/rmake.rs
Oneirical marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// The rust compiler searches by default for libraries in its current directory,
// but used to have difficulty following symlinks leading to required libraries
// if the real ones were located elsewhere. After this was fixed in #13903, this test
// checks that compilation succeeds through use of the symlink.
// See https://github.com/rust-lang/rust/issues/13890

//@ needs-symlink

use run_make_support::{cwd, path, rfs, rust_lib_name, rustc};

fn main() {
rfs::create_dir("outdir");
rustc().input("foo.rs").output(path("outdir").join(rust_lib_name("foo"))).run();
rfs::create_symlink(path("outdir").join(rust_lib_name("foo")), rust_lib_name("foo"));
// RUSTC_LOG is used for debugging and is not crucial to the test.
rustc().env("RUSTC_LOG", "rustc_metadata::loader").input("bar.rs").run();
Oneirical marked this conversation as resolved.
Show resolved Hide resolved
}
78 changes: 0 additions & 78 deletions tests/run-make/translation/Makefile

This file was deleted.

121 changes: 121 additions & 0 deletions tests/run-make/translation/rmake.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: can we please group the test cases alongside their comments, like the original Makefile? E.g.

fn test_builtin_fallback_bundle() {
    // TODO
}

Dumping them together is a bit hard to follow.

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Various tests on Fluent bundles, useful to change the compiler's language
// to the one requested by the user. Check each comment header to learn the purpose
// of each test case.
// See https://github.com/rust-lang/rust/pull/95512

//@ needs-symlink

use run_make_support::{path, rfs, rustc};

fn main() {
builtin_fallback_bundle();
custom_bundle();
interpolated_variable_missing();
desired_message_missing();
custom_locale_from_sysroot();
no_locale_in_sysroot();
locale_in_sysroot_is_invalid();
}

fn builtin_fallback_bundle() {
// Check that the test works normally, using the built-in fallback bundle.
rustc().input("test.rs").run_fail().assert_stderr_contains("struct literal body without path");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: the RUSTC_TRANSLATION_NO_DEBUG_ASSERT=1 env var might be load-bearing, see

// Always yeet out for errors on debug (unless
// `RUSTC_TRANSLATION_NO_DEBUG_ASSERT` is set in the environment - this allows
// local runs of the test suites, of builds with debug assertions, to test the
// behaviour in a normal build).
Some(Err(primary))
if cfg!(debug_assertions)
&& env::var("RUSTC_TRANSLATION_NO_DEBUG_ASSERT").is_err() =>
{
do yeet primary
}

We probably want to have a Rustc factory fn that presets that env var:

fn rustc_no_translation_assert() -> Rustc {
    rustc().env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot author

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustc() returns a temporary &mut Rustc which cannot be returned at first glance (unless there is some lifetime magic to pull it off).

I added the environment variable to the rustc calls in the test manually, though in my local tests it seemed to have no effect. Then again, this might be due to me using stage 0 compilation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, my bad. Hm.

}

fn custom_bundle() {
// Check that a primary bundle can be loaded and will be preferentially used
// where possible.
rustc()
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
.arg("-Ztranslate-additional-ftl=working.ftl")
.input("test.rs")
.run_fail()
.assert_stderr_contains("this is a test message");
}

fn interpolated_variable_missing() {
// Check that a primary bundle with a broken message (e.g. a interpolated
// variable is missing) will use the fallback bundle.
rustc()
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
.arg("-Ztranslate-additional-ftl=missing.ftl")
.input("test.rs")
.run_fail()
.assert_stderr_contains("struct literal body without path");
}

fn desired_message_missing() {
// Check that a primary bundle without the desired message will use the fallback
// bundle.
rustc()
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
.arg("-Ztranslate-additional-ftl=broken.ftl")
.input("test.rs")
.run_fail()
.assert_stderr_contains("struct literal body without path");
}

fn custom_locale_from_sysroot() {
// Check that a locale can be loaded from the sysroot given a language
// identifier by making a local copy of the sysroot and adding the custom locale
// to it.
let sysroot =
rustc().env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1").print("sysroot").run().stdout_utf8();
let sysroot = sysroot.trim();
rfs::create_dir("fakeroot");
symlink_all_entries(&sysroot, "fakeroot");
rfs::remove_file("fakeroot/lib");
rfs::create_dir("fakeroot/lib");
symlink_all_entries(path(&sysroot).join("lib"), "fakeroot/lib");
rfs::remove_file("fakeroot/lib/rustlib");
rfs::create_dir("fakeroot/lib/rustlib");
symlink_all_entries(path(&sysroot).join("lib/rustlib"), "fakeroot/lib/rustlib");
rfs::remove_file("fakeroot/lib/rustlib/src");
rfs::create_dir("fakeroot/lib/rustlib/src");
symlink_all_entries(path(&sysroot).join("lib/rustlib/src"), "fakeroot/lib/rustlib/src");
// When download-rustc is enabled, `sysroot` will have a share directory. Delete the link to it.
if path("fakeroot/share").exists() {
rfs::remove_file("fakeroot/share");
}
rfs::create_dir_all("fakeroot/share/locale/zh-CN");
rfs::create_symlink("working.ftl", "fakeroot/share/locale/zh-CN/basic-translation.ftl");
rustc()
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
.arg("-Ztranslate-lang=zh-CN")
.input("test.rs")
.sysroot("fakeroot")
.run_fail()
.assert_stderr_contains("this is a test message");
}

fn no_locale_in_sysroot() {
// Check that the compiler errors out when the sysroot requested cannot be
// found. This test might start failing if there actually exists a Klingon
// translation of rustc's error messages.
rustc()
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
.arg("-Ztranslate-lang=tlh")
// .input("test.rs")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: commented out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original test:

sysroot-missing:
	$(RUSTC) $< -Ztranslate-lang=tlh 2>&1 | $(CGREP) "missing locale directory"

Note how the ususal test.rs next to the section header sysroot-missing: is absent. I have no idea what the $< is slotting in.

.run_fail()
.assert_stderr_contains("missing locale directory");
}

fn locale_in_sysroot_is_invalid() {
// Check that the compiler errors out when the directory for the locale in the
// sysroot is actually a file.
rfs::remove_dir_all("fakeroot/share/locale/zh-CN");
rfs::create_file("fakeroot/share/locale/zh-CN");
rustc()
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
.arg("-Ztranslate-lang=zh-CN")
.input("test.rs")
.sysroot("fakeroot")
.run_fail()
.assert_stderr_contains("`$sysroot/share/locales/$locale` is not a directory");
}

fn symlink_all_entries<P: AsRef<std::path::Path>>(dir: P, fakepath: &str) {
for found_path in rfs::shallow_find_dir_entries(dir) {
rfs::create_symlink(&found_path, path(fakepath).join(found_path.file_name().unwrap()));
}
}
Loading