Skip to content

Commit c049f28

Browse files
committed
rewrite emit-path-unhashed to rmake
1 parent 0e53f9c commit c049f28

File tree

4 files changed

+65
-41
lines changed

4 files changed

+65
-41
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

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +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
2726
run-make/emit-to-stdout/Makefile
2827
run-make/env-dep-info/Makefile
2928
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+
}

0 commit comments

Comments
 (0)