Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 28b636a

Browse files
committedJul 4, 2024
rewrite emit-path-unhashed to rmake
1 parent 0e53f9c commit 28b636a

File tree

4 files changed

+68
-38
lines changed

4 files changed

+68
-38
lines changed
 

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

+34
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,38 @@ impl Diff {
120120
)
121121
}
122122
}
123+
124+
#[track_caller]
125+
pub fn run_fail(&mut self) {
126+
self.drop_bomb.defuse();
127+
let expected = self.expected.as_ref().expect("expected text not set");
128+
let mut actual = self.actual.as_ref().expect("actual text not set").to_string();
129+
let expected_name = self.expected_name.as_ref().unwrap();
130+
let actual_name = self.actual_name.as_ref().unwrap();
131+
for (regex, replacement) in &self.normalizers {
132+
let re = Regex::new(regex).expect("bad regex in custom normalization rule");
133+
actual = re.replace_all(&actual, replacement).into_owned();
134+
}
135+
136+
let output = TextDiff::from_lines(expected, &actual)
137+
.unified_diff()
138+
.header(expected_name, actual_name)
139+
.to_string();
140+
141+
if output.is_empty() {
142+
// If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
143+
// environment variable set), then we write into the file and return.
144+
if let Some(ref expected_file) = self.expected_file {
145+
if std::env::var("RUSTC_BLESS_TEST").is_ok() {
146+
println!("Blessing `{}`", expected_file.display());
147+
fs_wrapper::write(expected_file, actual);
148+
return;
149+
}
150+
}
151+
panic!(
152+
"test failed: `{}` is not different from `{}`\n\n{}",
153+
expected_name, actual_name, output
154+
)
155+
}
156+
}
123157
}

‎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)
Failed to load comments.