Skip to content

Commit 8784836

Browse files
committed
Auto merge of rust-lang#135818 - jieyouxu:migrate-translation, r=<try>
tests: Port `translation` to rmake.rs Part of rust-lang#121876. This PR partially supersedes rust-lang#129011 and is co-authored with `@Oneirical.` ## Summary This PR ports `tests/run-make/translation` to rmake.rs. Notable changes from the Makefile version include: - We now actually fail if the rustc invocations fail... The Makefile did not have `SHELL=/bin/bash -o pipefail`, so all the piped rustc invocations to grep vacuously succeeded, even if the broken ftl test case actually regressed over time and ICEs on current master. - That test case is converted to assert it ICEs with a FIXME backlinking to rust-lang#135817. - The test coverage is expanded to not ignore windows. Instead, the test now uses symlink capability detection to gate test execution. - Added some backlinks to relevant tracking issues and the initial translation infra implementation PR. ## Review advice Best reviewed commit-by-commit. r? compiler try-job: aarch64-apple
2 parents f940188 + 4e38606 commit 8784836

File tree

5 files changed

+195
-81
lines changed

5 files changed

+195
-81
lines changed

src/tools/run-make-support/src/command.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,15 @@ impl CompletedProcess {
388388
self
389389
}
390390

391+
/// Check the **exit status** of the process. On Unix, this is *not* the **wait status**.
392+
///
393+
/// See [`std::process::ExitStatus::code`]. This is not to be confused with
394+
/// [`std::process::ExitCode`].
391395
#[track_caller]
392396
pub fn assert_exit_code(&self, code: i32) -> &Self {
393-
assert!(self.output.status.code() == Some(code));
397+
// FIXME(jieyouxu): this should really be named `exit_status`, because std has an `ExitCode`
398+
// that means a different thing.
399+
assert_eq!(self.output.status.code(), Some(code));
394400
self
395401
}
396402
}

src/tools/run-make-support/src/external_deps/rustc.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ffi::{OsStr, OsString};
2-
use std::path::Path;
2+
use std::path::{Path, PathBuf};
3+
use std::str::FromStr as _;
34

45
use crate::command::Command;
56
use crate::env::env_var;
@@ -390,3 +391,10 @@ impl Rustc {
390391
self
391392
}
392393
}
394+
395+
/// Query the sysroot path corresponding `rustc --print=sysroot`.
396+
#[track_caller]
397+
pub fn sysroot() -> PathBuf {
398+
let path = rustc().print("sysroot").run().stdout_utf8();
399+
PathBuf::from_str(path.trim()).unwrap()
400+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
run-make/split-debuginfo/Makefile
22
run-make/symbol-mangling-hashed/Makefile
3-
run-make/translation/Makefile

tests/run-make/translation/Makefile

-78
This file was deleted.

tests/run-make/translation/rmake.rs

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
//! Smoke test for the rustc diagnostics translation infrastructure.
2+
//!
3+
//! # References
4+
//!
5+
//! - Current tracking issue: <https://github.com/rust-lang/rust/issues/132181>.
6+
//! - Old tracking issue: <https://github.com/rust-lang/rust/issues/100717>
7+
//! - Initial translation infra implementation: <https://github.com/rust-lang/rust/pull/95512>.
8+
9+
// This test uses symbolic links to stub out a fake sysroot to save testing time.
10+
//@ needs-symlink
11+
//@ needs-subprocess
12+
13+
#![deny(warnings)]
14+
15+
use std::path::{Path, PathBuf};
16+
17+
use run_make_support::rustc::sysroot;
18+
use run_make_support::{cwd, rfs, run_in_tmpdir, rustc};
19+
20+
fn main() {
21+
builtin_fallback_bundle();
22+
additional_primary_bundle();
23+
missing_slug_prefers_fallback_bundle();
24+
broken_primary_bundle_prefers_fallback_bundle();
25+
locale_sysroot();
26+
missing_sysroot();
27+
file_sysroot();
28+
}
29+
30+
/// Check that the test works normally, using the built-in fallback bundle.
31+
fn builtin_fallback_bundle() {
32+
rustc().input("test.rs").run_fail().assert_stderr_contains("struct literal body without path");
33+
}
34+
35+
/// Check that a primary bundle can be loaded and will be preferentially used where possible.
36+
fn additional_primary_bundle() {
37+
rustc()
38+
.input("test.rs")
39+
.arg("-Ztranslate-additional-ftl=working.ftl")
40+
.run_fail()
41+
.assert_stderr_contains("this is a test message");
42+
}
43+
44+
/// Check that a primary bundle without the desired message will use the fallback bundle.
45+
fn missing_slug_prefers_fallback_bundle() {
46+
rustc()
47+
.input("test.rs")
48+
.arg("-Ztranslate-additional-ftl=missing.ftl")
49+
.run_fail()
50+
.assert_stderr_contains("struct literal body without path");
51+
}
52+
53+
/// Check that a primary bundle with a broken message (e.g. an interpolated variable is not
54+
/// provided) will use the fallback bundle.
55+
fn broken_primary_bundle_prefers_fallback_bundle() {
56+
// FIXME(#135817): as of the rmake.rs port, the compiler actually ICEs on the additional
57+
// `broken.ftl`, even though the original intention seems to be that it should gracefully
58+
// failover to the fallback bundle.
59+
60+
let outcome = rustc()
61+
.env("RUSTC_ICE", "0") // disable ICE dump file, not needed
62+
.input("test.rs")
63+
.arg("-Ztranslate-additional-ftl=broken.ftl")
64+
.run_unchecked();
65+
66+
// XXX: do not merge, testing in CI
67+
eprintln!("stdout: {:#?}", outcome.stdout_utf8());
68+
eprintln!("stderr: {:#?}", outcome.stderr_utf8());
69+
70+
outcome.assert_exit_code(101);
71+
}
72+
73+
#[track_caller]
74+
fn shallow_symlink_dir_entries(src_dir: &Path, dst_dir: &Path) {
75+
for entry in rfs::read_dir(src_dir) {
76+
let entry = entry.unwrap();
77+
let src_entry_path = entry.path();
78+
let src_filename = src_entry_path.file_name().unwrap();
79+
let meta = rfs::symlink_metadata(&src_entry_path);
80+
81+
if meta.is_symlink() || meta.is_file() {
82+
rfs::symlink_file(&src_entry_path, dst_dir.join(src_filename));
83+
} else if meta.is_dir() {
84+
rfs::symlink_dir(&src_entry_path, dst_dir.join(src_filename));
85+
} else {
86+
unreachable!()
87+
}
88+
}
89+
}
90+
91+
#[track_caller]
92+
fn shallow_symlink_dir_entries_materialize_single_dir(
93+
src_dir: &Path,
94+
dst_dir: &Path,
95+
dir_filename: &str,
96+
) {
97+
shallow_symlink_dir_entries(src_dir, dst_dir);
98+
rfs::remove_file(dst_dir.join(dir_filename));
99+
rfs::create_dir_all(dst_dir.join(dir_filename));
100+
}
101+
102+
#[track_caller]
103+
fn setup_fakeroot_parents() -> PathBuf {
104+
let sysroot = sysroot();
105+
let fakeroot = cwd().join("fakeroot");
106+
rfs::create_dir_all(&fakeroot);
107+
shallow_symlink_dir_entries_materialize_single_dir(&sysroot, &fakeroot, "lib");
108+
shallow_symlink_dir_entries_materialize_single_dir(
109+
&sysroot.join("lib"),
110+
&fakeroot.join("lib"),
111+
"rustlib",
112+
);
113+
shallow_symlink_dir_entries_materialize_single_dir(
114+
&sysroot.join("lib").join("rustlib"),
115+
&fakeroot.join("lib").join("rustlib"),
116+
"src",
117+
);
118+
shallow_symlink_dir_entries(
119+
&sysroot.join("lib").join("rustlib").join("src"),
120+
&fakeroot.join("lib").join("rustlib").join("src"),
121+
);
122+
fakeroot
123+
}
124+
125+
/// Check that a locale can be loaded from the sysroot given a language identifier by making a local
126+
/// copy of the sysroot and adding the custom locale to it.
127+
fn locale_sysroot() {
128+
run_in_tmpdir(|| {
129+
let fakeroot = setup_fakeroot_parents();
130+
131+
// When download-rustc is enabled, real sysroot will have a share directory. Delete the link
132+
// to it.
133+
let _ = std::fs::remove_file(fakeroot.join("share"));
134+
135+
let fake_locale_path = fakeroot.join("share").join("locale").join("zh-CN");
136+
rfs::create_dir_all(&fake_locale_path);
137+
rfs::symlink_file(
138+
cwd().join("working.ftl"),
139+
fake_locale_path.join("basic-translation.ftl"),
140+
);
141+
142+
rustc()
143+
.env("RUSTC_ICE", "0")
144+
.input("test.rs")
145+
.sysroot(&fakeroot)
146+
.arg("-Ztranslate-lang=zh-CN")
147+
.run_fail()
148+
.assert_stderr_contains("this is a test message");
149+
});
150+
}
151+
152+
/// Check that the compiler errors out when the sysroot requested cannot be found. This test might
153+
/// start failing if there actually exists a Klingon translation of rustc's error messages.
154+
fn missing_sysroot() {
155+
run_in_tmpdir(|| {
156+
rustc()
157+
.input("test.rs")
158+
.arg("-Ztranslate-lang=tlh")
159+
.run_fail()
160+
.assert_stderr_contains("missing locale directory");
161+
});
162+
}
163+
164+
/// Check that the compiler errors out when the directory for the locale in the sysroot is actually
165+
/// a file.
166+
fn file_sysroot() {
167+
run_in_tmpdir(|| {
168+
let fakeroot = setup_fakeroot_parents();
169+
rfs::create_dir_all(fakeroot.join("share").join("locale"));
170+
rfs::write(fakeroot.join("share").join("locale").join("zh-CN"), b"not a dir");
171+
172+
rustc()
173+
.input("test.rs")
174+
.sysroot(&fakeroot)
175+
.arg("-Ztranslate-lang=zh-CN")
176+
.run_fail()
177+
.assert_stderr_contains("is not a directory");
178+
});
179+
}

0 commit comments

Comments
 (0)