diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 92405bdb876be..b44a8a77b2a9e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -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 diff --git a/tests/run-make/libs-through-symlinks/Makefile b/tests/run-make/libs-through-symlinks/Makefile deleted file mode 100644 index 592eae663a49a..0000000000000 --- a/tests/run-make/libs-through-symlinks/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# ignore-windows - -NAME := $(shell $(RUSTC) --print file-names foo.rs) - -all: - mkdir -p $(TMPDIR)/outdir - $(RUSTC) foo.rs -o $(TMPDIR)/outdir/$(NAME) - ln -nsf outdir/$(NAME) $(TMPDIR) - RUSTC_LOG=rustc_metadata::loader $(RUSTC) bar.rs diff --git a/tests/run-make/libs-through-symlinks/rmake.rs b/tests/run-make/libs-through-symlinks/rmake.rs new file mode 100644 index 0000000000000..e31220c655740 --- /dev/null +++ b/tests/run-make/libs-through-symlinks/rmake.rs @@ -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(); +} diff --git a/tests/run-make/translation/Makefile b/tests/run-make/translation/Makefile deleted file mode 100644 index 07e0547cfa090..0000000000000 --- a/tests/run-make/translation/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -include ../tools.mk - -# This test uses `ln -s` rather than copying to save testing time, but its -# usage doesn't work on Windows. -# ignore-windows - -SYSROOT:=$(shell $(RUSTC) --print sysroot) -FAKEROOT=$(TMPDIR)/fakeroot -RUSTC_LOG:=rustc_error_messages -export RUSTC_TRANSLATION_NO_DEBUG_ASSERT:=1 - -all: normal custom missing broken sysroot sysroot-invalid sysroot-missing - -# Check that the test works normally, using the built-in fallback bundle. -normal: test.rs - $(RUSTC) $< 2>&1 | $(CGREP) "struct literal body without path" - -# Check that a primary bundle can be loaded and will be preferentially used -# where possible. -custom: test.rs working.ftl - $(RUSTC) $< -Ztranslate-additional-ftl=$(CURDIR)/working.ftl 2>&1 | $(CGREP) "this is a test message" - -# Check that a primary bundle with a broken message (e.g. a interpolated -# variable is missing) will use the fallback bundle. -missing: test.rs missing.ftl - $(RUSTC) $< -Ztranslate-additional-ftl=$(CURDIR)/missing.ftl 2>&1 | $(CGREP) "struct literal body without path" - -# Check that a primary bundle without the desired message will use the fallback -# bundle. -broken: test.rs broken.ftl - $(RUSTC) $< -Ztranslate-additional-ftl=$(CURDIR)/broken.ftl 2>&1 | $(CGREP) "struct literal body without path" - -# 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. -sysroot: test.rs working.ftl - rm -rf $(FAKEROOT) - mkdir $(FAKEROOT) - ln -s $(SYSROOT)/* $(FAKEROOT) - rm -f $(FAKEROOT)/lib - mkdir $(FAKEROOT)/lib - ln -s $(SYSROOT)/lib/* $(FAKEROOT)/lib - rm -f $(FAKEROOT)/lib/rustlib - mkdir $(FAKEROOT)/lib/rustlib - ln -s $(SYSROOT)/lib/rustlib/* $(FAKEROOT)/lib/rustlib - rm -f $(FAKEROOT)/lib/rustlib/src - mkdir $(FAKEROOT)/lib/rustlib/src - ln -s $(SYSROOT)/lib/rustlib/src/* $(FAKEROOT)/lib/rustlib/src - # When download-rustc is enabled, `$(SYSROOT)` will have a share directory. Delete the link to it. - rm -f $(FAKEROOT)/share - mkdir -p $(FAKEROOT)/share/locale/zh-CN/ - ln -s $(CURDIR)/working.ftl $(FAKEROOT)/share/locale/zh-CN/basic-translation.ftl - $(RUSTC) $< --sysroot $(FAKEROOT) -Ztranslate-lang=zh-CN 2>&1 | $(CGREP) "this is a test message" - -# 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. -sysroot-missing: - $(RUSTC) $< -Ztranslate-lang=tlh 2>&1 | $(CGREP) "missing locale directory" - -# Check that the compiler errors out when the directory for the locale in the -# sysroot is actually a file. -sysroot-invalid: test.rs working.ftl - rm -rf $(FAKEROOT) - mkdir $(FAKEROOT) - ln -s $(SYSROOT)/* $(FAKEROOT) - rm -f $(FAKEROOT)/lib - mkdir $(FAKEROOT)/lib - ln -s $(SYSROOT)/lib/* $(FAKEROOT)/lib - rm -f $(FAKEROOT)/lib/rustlib - mkdir $(FAKEROOT)/lib/rustlib - ln -s $(SYSROOT)/lib/rustlib/* $(FAKEROOT)/lib/rustlib - rm -f $(FAKEROOT)/lib/rustlib/src - mkdir $(FAKEROOT)/lib/rustlib/src - ln -s $(SYSROOT)/lib/rustlib/src/* $(FAKEROOT)/lib/rustlib/src - mkdir -p $(FAKEROOT)/share/locale - touch $(FAKEROOT)/share/locale/zh-CN - $(RUSTC) $< --sysroot $(FAKEROOT) -Ztranslate-lang=zh-CN 2>&1 | $(CGREP) "`\$sysroot/share/locales/\$locale` is not a directory" diff --git a/tests/run-make/translation/rmake.rs b/tests/run-make/translation/rmake.rs new file mode 100644 index 0000000000000..006ab105ee56e --- /dev/null +++ b/tests/run-make/translation/rmake.rs @@ -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"); +} + +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") + .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>(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())); + } +}