Skip to content

Commit 289deb9

Browse files
committed
Auto merge of #127335 - Oneirical:put-on-a-petestal, r=jieyouxu
Migrate `emit-shared-files` and `emit-path-unhashed` `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). try-job: x86_64-msvc try-job: aarch64-apple try-job: armhf-gnu try-job: test-various
2 parents 6ba80a9 + 4a15fe4 commit 289deb9

File tree

6 files changed

+167
-88
lines changed

6 files changed

+167
-88
lines changed

src/tools/run-make-support/src/diff/mod.rs

+31-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ impl Diff {
8787
self
8888
}
8989

90-
#[track_caller]
91-
pub fn run(&mut self) {
92-
self.drop_bomb.defuse();
90+
fn run_common(&self) -> (&str, &str, String, String) {
9391
let expected = self.expected.as_ref().expect("expected text not set");
9492
let mut actual = self.actual.as_ref().expect("actual text not set").to_string();
9593
let expected_name = self.expected_name.as_ref().unwrap();
@@ -104,6 +102,14 @@ impl Diff {
104102
.header(expected_name, actual_name)
105103
.to_string();
106104

105+
(expected_name, actual_name, output, actual)
106+
}
107+
108+
#[track_caller]
109+
pub fn run(&mut self) {
110+
self.drop_bomb.defuse();
111+
let (expected_name, actual_name, output, actual) = self.run_common();
112+
107113
if !output.is_empty() {
108114
// If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
109115
// environment variable set), then we write into the file and return.
@@ -120,4 +126,26 @@ impl Diff {
120126
)
121127
}
122128
}
129+
130+
#[track_caller]
131+
pub fn run_fail(&mut self) {
132+
self.drop_bomb.defuse();
133+
let (expected_name, actual_name, output, actual) = self.run_common();
134+
135+
if output.is_empty() {
136+
// If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
137+
// environment variable set), then we write into the file and return.
138+
if let Some(ref expected_file) = self.expected_file {
139+
if std::env::var("RUSTC_BLESS_TEST").is_ok() {
140+
println!("Blessing `{}`", expected_file.display());
141+
fs_wrapper::write(expected_file, actual);
142+
return;
143+
}
144+
}
145+
panic!(
146+
"test failed: `{}` is not different from `{}`\n\n{}",
147+
expected_name, actual_name, output
148+
)
149+
}
150+
}
123151
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ run-make/dep-info-spaces/Makefile
2323
run-make/dep-info/Makefile
2424
run-make/dump-ice-to-disk/Makefile
2525
run-make/dump-mono-stats/Makefile
26-
run-make/emit-path-unhashed/Makefile
27-
run-make/emit-shared-files/Makefile
2826
run-make/emit-to-stdout/Makefile
2927
run-make/env-dep-info/Makefile
3028
run-make/export-executable-symbols/Makefile

tests/run-make/emit-path-unhashed/Makefile

-37
This file was deleted.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Specifying how rustc outputs a file can be done in different ways, such as
2+
// the output flag or the KIND=NAME syntax. However, some of these methods used
3+
// to result in different hashes on output files even though they yielded the
4+
// exact same result otherwise. This was fixed in #86045, and this test checks
5+
// that the hash is only modified when the output is made different, such as by
6+
// adding a new output type (in this test, metadata).
7+
// See https://github.com/rust-lang/rust/issues/86044
8+
9+
use run_make_support::{diff, fs_wrapper, rustc};
10+
11+
fn main() {
12+
fs_wrapper::create_dir("emit");
13+
fs_wrapper::create_dir("emit/a");
14+
fs_wrapper::create_dir("emit/b");
15+
fs_wrapper::create_dir("emit/c");
16+
// The default output name.
17+
rustc().emit("link").input("foo.rs").run();
18+
// The output is named with the output flag.
19+
rustc().emit("link").output("emit/a/libfoo.rlib").input("foo.rs").run();
20+
// The output is named with link=NAME.
21+
rustc().emit("link=emit/b/libfoo.rlib").input("foo.rs").run();
22+
// The output is named with link=NAME, with an additional kind tacked on.
23+
rustc().emit("link=emit/c/libfoo.rlib,metadata").input("foo.rs").run();
24+
25+
let base = rustc().arg("-Zls=root").input("libfoo.rlib").run().stdout_utf8();
26+
let a = rustc().arg("-Zls=root").input("emit/a/libfoo.rlib").run().stdout_utf8();
27+
let b = rustc().arg("-Zls=root").input("emit/b/libfoo.rlib").run().stdout_utf8();
28+
let c = rustc().arg("-Zls=root").input("emit/c/libfoo.rlib").run().stdout_utf8();
29+
// Both the output flag and link=NAME methods do not modify the hash of the output file.
30+
diff().expected_text("base", &base).actual_text("a", a).run();
31+
diff().expected_text("base", &base).actual_text("b", b).run();
32+
// However, having multiple types of outputs does modify the hash.
33+
diff().expected_text("base", &base).actual_text("c", c).run_fail();
34+
}

tests/run-make/emit-shared-files/Makefile

-46
This file was deleted.
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// This test checks the functionality of one of rustdoc's unstable options,
2+
// the ability to specify emit restrictions with `--emit`.
3+
// `invocation-only` should only emit crate-specific files.
4+
// `toolchain-only` should only emit toolchain-specific files.
5+
// `all-shared` should only emit files that can be shared between crates.
6+
// See https://github.com/rust-lang/rust/pull/83478
7+
8+
use run_make_support::{has_extension, has_prefix, rustdoc, shallow_find_files};
9+
use std::path::Path;
10+
11+
fn main() {
12+
rustdoc()
13+
.arg("-Zunstable-options")
14+
.arg("--emit=invocation-specific")
15+
.output("invocation-only")
16+
.arg("--resource-suffix=-xxx")
17+
.args(&["--theme", "y.css"])
18+
.args(&["--extend-css", "z.css"])
19+
.input("x.rs")
20+
.run();
21+
assert!(Path::new("invocation-only/search-index-xxx.js").exists());
22+
assert!(Path::new("invocation-only/settings.html").exists());
23+
assert!(Path::new("invocation-only/x/all.html").exists());
24+
assert!(Path::new("invocation-only/x/index.html").exists());
25+
assert!(Path::new("invocation-only/theme-xxx.css").exists()); // generated from z.css
26+
assert!(!Path::new("invocation-only/storage-xxx.js").exists());
27+
assert!(!Path::new("invocation-only/SourceSerif4-It.ttf.woff2").exists());
28+
// FIXME: this probably shouldn't have a suffix
29+
assert!(Path::new("invocation-only/y-xxx.css").exists());
30+
// FIXME: this is technically incorrect (see `write_shared`)
31+
assert!(!Path::new("invocation-only/main-xxx.js").exists());
32+
33+
rustdoc()
34+
.arg("-Zunstable-options")
35+
.arg("--emit=toolchain-shared-resources")
36+
.output("toolchain-only")
37+
.arg("--resource-suffix=-xxx")
38+
.args(&["--extend-css", "z.css"])
39+
.input("x.rs")
40+
.run();
41+
assert_eq!(
42+
shallow_find_files("toolchain-only/static.files", |path| {
43+
has_prefix(path, "storage-") && has_extension(path, "js")
44+
})
45+
.len(),
46+
1
47+
);
48+
assert_eq!(
49+
shallow_find_files("toolchain-only/static.files", |path| {
50+
has_prefix(path, "SourceSerif4-It-") && has_extension(path, "woff2")
51+
})
52+
.len(),
53+
1
54+
);
55+
assert_eq!(
56+
shallow_find_files("toolchain-only/static.files", |path| {
57+
has_prefix(path, "main-") && has_extension(path, "js")
58+
})
59+
.len(),
60+
1
61+
);
62+
assert!(!Path::new("toolchain-only/search-index-xxx.js").exists());
63+
assert!(!Path::new("toolchain-only/x/index.html").exists());
64+
assert!(!Path::new("toolchain-only/theme.css").exists());
65+
assert!(!Path::new("toolchain-only/y-xxx.css").exists());
66+
67+
rustdoc()
68+
.arg("-Zunstable-options")
69+
.arg("--emit=toolchain-shared-resources,unversioned-shared-resources")
70+
.output("all-shared")
71+
.arg("--resource-suffix=-xxx")
72+
.args(&["--extend-css", "z.css"])
73+
.input("x.rs")
74+
.run();
75+
assert_eq!(
76+
shallow_find_files("all-shared/static.files", |path| {
77+
has_prefix(path, "storage-") && has_extension(path, "js")
78+
})
79+
.len(),
80+
1
81+
);
82+
assert_eq!(
83+
shallow_find_files("all-shared/static.files", |path| {
84+
has_prefix(path, "SourceSerif4-It-") && has_extension(path, "woff2")
85+
})
86+
.len(),
87+
1
88+
);
89+
assert!(!Path::new("all-shared/search-index-xxx.js").exists());
90+
assert!(!Path::new("all-shared/settings.html").exists());
91+
assert!(!Path::new("all-shared/x").exists());
92+
assert!(!Path::new("all-shared/src").exists());
93+
assert!(!Path::new("all-shared/theme.css").exists());
94+
assert_eq!(
95+
shallow_find_files("all-shared/static.files", |path| {
96+
has_prefix(path, "main-") && has_extension(path, "js")
97+
})
98+
.len(),
99+
1
100+
);
101+
assert!(!Path::new("all-shared/y-xxx.css").exists());
102+
}

0 commit comments

Comments
 (0)