about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-07-04 16:02:45 -0400
committerOneirical <manchot@videotron.ca>2024-07-05 10:06:27 -0400
commit4a15fe44e3574040c469dd8ed66f26ca4d2d09c5 (patch)
tree5b7577063f6bf8df0d048f629eb45062f92de298
parentf77d5d2b351f4a86e0c6ead5db83ef0fb3d22d40 (diff)
downloadrust-4a15fe44e3574040c469dd8ed66f26ca4d2d09c5.tar.gz
rust-4a15fe44e3574040c469dd8ed66f26ca4d2d09c5.zip
rewrite emit-path-unhashed to rmake
-rw-r--r--src/tools/run-make-support/src/diff/mod.rs34
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/emit-path-unhashed/Makefile37
-rw-r--r--tests/run-make/emit-path-unhashed/rmake.rs34
4 files changed, 65 insertions, 41 deletions
diff --git a/src/tools/run-make-support/src/diff/mod.rs b/src/tools/run-make-support/src/diff/mod.rs
index 3e0bdc1c6f6..24fa88af82e 100644
--- a/src/tools/run-make-support/src/diff/mod.rs
+++ b/src/tools/run-make-support/src/diff/mod.rs
@@ -87,9 +87,7 @@ impl Diff {
         self
     }
 
-    #[track_caller]
-    pub fn run(&mut self) {
-        self.drop_bomb.defuse();
+    fn run_common(&self) -> (&str, &str, String, String) {
         let expected = self.expected.as_ref().expect("expected text not set");
         let mut actual = self.actual.as_ref().expect("actual text not set").to_string();
         let expected_name = self.expected_name.as_ref().unwrap();
@@ -104,6 +102,14 @@ impl Diff {
             .header(expected_name, actual_name)
             .to_string();
 
+        (expected_name, actual_name, output, actual)
+    }
+
+    #[track_caller]
+    pub fn run(&mut self) {
+        self.drop_bomb.defuse();
+        let (expected_name, actual_name, output, actual) = self.run_common();
+
         if !output.is_empty() {
             // If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
             // environment variable set), then we write into the file and return.
@@ -120,4 +126,26 @@ impl Diff {
             )
         }
     }
+
+    #[track_caller]
+    pub fn run_fail(&mut self) {
+        self.drop_bomb.defuse();
+        let (expected_name, actual_name, output, actual) = self.run_common();
+
+        if output.is_empty() {
+            // If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
+            // environment variable set), then we write into the file and return.
+            if let Some(ref expected_file) = self.expected_file {
+                if std::env::var("RUSTC_BLESS_TEST").is_ok() {
+                    println!("Blessing `{}`", expected_file.display());
+                    fs_wrapper::write(expected_file, actual);
+                    return;
+                }
+            }
+            panic!(
+                "test failed: `{}` is not different from `{}`\n\n{}",
+                expected_name, actual_name, output
+            )
+        }
+    }
 }
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 73d6af50ea0..13fe75aac0f 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -23,7 +23,6 @@ run-make/dep-info-spaces/Makefile
 run-make/dep-info/Makefile
 run-make/dump-ice-to-disk/Makefile
 run-make/dump-mono-stats/Makefile
-run-make/emit-path-unhashed/Makefile
 run-make/emit-to-stdout/Makefile
 run-make/env-dep-info/Makefile
 run-make/export-executable-symbols/Makefile
diff --git a/tests/run-make/emit-path-unhashed/Makefile b/tests/run-make/emit-path-unhashed/Makefile
deleted file mode 100644
index 611f8578140..00000000000
--- a/tests/run-make/emit-path-unhashed/Makefile
+++ /dev/null
@@ -1,37 +0,0 @@
-include ../tools.mk
-
-OUT=$(TMPDIR)/emit
-
-# --emit KIND=PATH should not affect crate hash vs --emit KIND
-all: $(OUT)/a/libfoo.rlib $(OUT)/b/libfoo.rlib $(OUT)/c/libfoo.rlib \
-		$(TMPDIR)/libfoo.rlib
-	$(RUSTC) -Zls=root $(TMPDIR)/libfoo.rlib > $(TMPDIR)/base.txt
-	$(RUSTC) -Zls=root $(OUT)/a/libfoo.rlib > $(TMPDIR)/a.txt
-	$(RUSTC) -Zls=root $(OUT)/b/libfoo.rlib > $(TMPDIR)/b.txt
-	$(RUSTC) -Zls=root $(OUT)/c/libfoo.rlib > $(TMPDIR)/c.txt
-
-	diff $(TMPDIR)/base.txt $(TMPDIR)/a.txt
-	diff $(TMPDIR)/base.txt $(TMPDIR)/b.txt
-
-	# Different KIND parameters do affect hash.
-	# diff exits 1 on difference, 2 on trouble
-	diff $(TMPDIR)/base.txt $(TMPDIR)/c.txt ; test "$$?" -eq 1
-
-# Default output name
-$(TMPDIR)/libfoo.rlib: foo.rs
-	$(RUSTC) --emit link foo.rs
-
-# Output named with -o
-$(OUT)/a/libfoo.rlib: foo.rs
-	mkdir -p $(OUT)/a
-	$(RUSTC) --emit link -o $@ foo.rs
-
-# Output named with KIND=PATH
-$(OUT)/b/libfoo.rlib: foo.rs
-	mkdir -p $(OUT)/b
-	$(RUSTC) --emit link=$@ foo.rs
-
-# Output multiple kinds
-$(OUT)/c/libfoo.rlib: foo.rs
-	mkdir -p $(OUT)/c
-	$(RUSTC) --emit link=$@,metadata foo.rs
diff --git a/tests/run-make/emit-path-unhashed/rmake.rs b/tests/run-make/emit-path-unhashed/rmake.rs
new file mode 100644
index 00000000000..ce56c197588
--- /dev/null
+++ b/tests/run-make/emit-path-unhashed/rmake.rs
@@ -0,0 +1,34 @@
+// Specifying how rustc outputs a file can be done in different ways, such as
+// the output flag or the KIND=NAME syntax. However, some of these methods used
+// to result in different hashes on output files even though they yielded the
+// exact same result otherwise. This was fixed in #86045, and this test checks
+// that the hash is only modified when the output is made different, such as by
+// adding a new output type (in this test, metadata).
+// See https://github.com/rust-lang/rust/issues/86044
+
+use run_make_support::{diff, fs_wrapper, rustc};
+
+fn main() {
+    fs_wrapper::create_dir("emit");
+    fs_wrapper::create_dir("emit/a");
+    fs_wrapper::create_dir("emit/b");
+    fs_wrapper::create_dir("emit/c");
+    // The default output name.
+    rustc().emit("link").input("foo.rs").run();
+    // The output is named with the output flag.
+    rustc().emit("link").output("emit/a/libfoo.rlib").input("foo.rs").run();
+    // The output is named with link=NAME.
+    rustc().emit("link=emit/b/libfoo.rlib").input("foo.rs").run();
+    // The output is named with link=NAME, with an additional kind tacked on.
+    rustc().emit("link=emit/c/libfoo.rlib,metadata").input("foo.rs").run();
+
+    let base = rustc().arg("-Zls=root").input("libfoo.rlib").run().stdout_utf8();
+    let a = rustc().arg("-Zls=root").input("emit/a/libfoo.rlib").run().stdout_utf8();
+    let b = rustc().arg("-Zls=root").input("emit/b/libfoo.rlib").run().stdout_utf8();
+    let c = rustc().arg("-Zls=root").input("emit/c/libfoo.rlib").run().stdout_utf8();
+    // Both the output flag and link=NAME methods do not modify the hash of the output file.
+    diff().expected_text("base", &base).actual_text("a", a).run();
+    diff().expected_text("base", &base).actual_text("b", b).run();
+    // However, having multiple types of outputs does modify the hash.
+    diff().expected_text("base", &base).actual_text("c", c).run_fail();
+}