about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-06-20 11:21:56 -0400
committerOneirical <manchot@videotron.ca>2024-06-28 11:18:46 -0400
commitacb6078d9183c41e39495ff075cd01b3d68fe967 (patch)
tree97e3a678623e6adcd77e72d4856cf6501f0453cc
parent99f77a2eda555b50b518f74823ab636a20efb87f (diff)
downloadrust-acb6078d9183c41e39495ff075cd01b3d68fe967.tar.gz
rust-acb6078d9183c41e39495ff075cd01b3d68fe967.zip
rewrite remap-path-prefix to rmake
-rw-r--r--src/tools/run-make-support/src/rustc.rs11
-rw-r--r--tests/run-make/remap-path-prefix/Makefile30
-rw-r--r--tests/run-make/remap-path-prefix/rmake.rs58
3 files changed, 69 insertions, 30 deletions
diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs
index 28ece1dff12..df843d74fc9 100644
--- a/src/tools/run-make-support/src/rustc.rs
+++ b/src/tools/run-make-support/src/rustc.rs
@@ -106,6 +106,17 @@ impl Rustc {
         self
     }
 
+    /// Remap source path prefixes in all output.
+    pub fn remap_path_prefix<P: AsRef<Path>>(&mut self, from: P, to: P) -> &mut Self {
+        let from = from.as_ref().to_string_lossy();
+        let to = to.as_ref().to_string_lossy();
+
+        self.cmd.arg("--remap-path-prefix");
+        self.cmd.arg(format!("{from}={to}"));
+
+        self
+    }
+
     /// Specify path to the input file.
     pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
         self.cmd.arg(path.as_ref());
diff --git a/tests/run-make/remap-path-prefix/Makefile b/tests/run-make/remap-path-prefix/Makefile
deleted file mode 100644
index 02423dea7d2..00000000000
--- a/tests/run-make/remap-path-prefix/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-include ../tools.mk
-
-# ignore-windows
-
-ifeq ($(UNAME),Darwin)
-  DEBUGINFOOPTS := -Csplit-debuginfo=off
-else
-  DEBUGINFOOPTS :=
-endif
-
-all: remap remap-with-scope
-
-# Checks if remapping works if the remap-from string contains path to the working directory plus more
-remap:
-	$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs
-	grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
-	! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
-
-remap-with-scope:
-	$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
-	grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
-	! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
-
-	$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=macro $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
-	grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
-	! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
-
-	$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=diagnostics,object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
-	grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
-	! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
diff --git a/tests/run-make/remap-path-prefix/rmake.rs b/tests/run-make/remap-path-prefix/rmake.rs
new file mode 100644
index 00000000000..4d98dcf6131
--- /dev/null
+++ b/tests/run-make/remap-path-prefix/rmake.rs
@@ -0,0 +1,58 @@
+// Generating metadata alongside remap-path-prefix would fail to actually remap the path
+// in the metadata. After this was fixed in #85344, this test checks that "auxiliary" is being
+// successfully remapped to "/the/aux" in the rmeta files.
+// See https://github.com/rust-lang/rust/pull/85344
+
+// FIXME(Oneirical): check if works without ignore-windows
+
+use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, is_darwin, rustc};
+
+fn main() {
+    let mut out_simple = rustc();
+    let mut out_object = rustc();
+    let mut out_macro = rustc();
+    let mut out_diagobj = rustc();
+    out_simple
+        .remap_path_prefix("auxiliary", "/the/aux")
+        .crate_type("lib")
+        .emit("metadata")
+        .input("auxiliary/lib.rs");
+    out_object
+        .remap_path_prefix("auxiliary", "/the/aux")
+        .crate_type("lib")
+        .emit("metadata")
+        .input("auxiliary/lib.rs");
+    out_macro
+        .remap_path_prefix("auxiliary", "/the/aux")
+        .crate_type("lib")
+        .emit("metadata")
+        .input("auxiliary/lib.rs");
+    out_diagobj
+        .remap_path_prefix("auxiliary", "/the/aux")
+        .crate_type("lib")
+        .emit("metadata")
+        .input("auxiliary/lib.rs");
+
+    out_simple.run();
+    invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
+    invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
+
+    out_object.arg("-Zremap-path-scope=object");
+    out_macro.arg("-Zremap-path-scope=macro");
+    out_diagobj.arg("-Zremap-path-scope=diagnostics,object");
+    if is_darwin() {
+        out_object.arg("-Csplit-debuginfo=off");
+        out_macro.arg("-Csplit-debuginfo=off");
+        out_diagobj.arg("-Csplit-debuginfo=off");
+    }
+
+    out_object.run();
+    invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
+    invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
+    out_macro.run();
+    invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
+    invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
+    out_diagobj.run();
+    invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
+    invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
+}