From 17950828420fa2068214b906e9fea98a771e64e8 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 27 Jun 2024 14:38:30 -0400 Subject: [PATCH] rmeta_contains functions for remap-path-prefix --- Cargo.lock | 1 + src/tools/run-make-support/Cargo.toml | 1 + src/tools/run-make-support/src/lib.rs | 1 + tests/run-make/remap-path-prefix/rmake.rs | 51 ++++++++++++++++++----- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0182eca05058d..f6293f9626e13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3401,6 +3401,7 @@ name = "run_make_support" version = "0.2.0" dependencies = [ "ar", + "bstr", "gimli 0.28.1", "object 0.34.0", "regex", diff --git a/src/tools/run-make-support/Cargo.toml b/src/tools/run-make-support/Cargo.toml index e3837a2f8cc4e..ec3b8a96ef3b6 100644 --- a/src/tools/run-make-support/Cargo.toml +++ b/src/tools/run-make-support/Cargo.toml @@ -4,6 +4,7 @@ version = "0.2.0" edition = "2021" [dependencies] +bstr = "1.6.0" object = "0.34.0" similar = "2.5.0" wasmparser = "0.118.2" diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 771cda630af6a..31b913810b665 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -21,6 +21,7 @@ use std::io; use std::panic; use std::path::{Path, PathBuf}; +pub use bstr; pub use gimli; pub use object; pub use regex; diff --git a/tests/run-make/remap-path-prefix/rmake.rs b/tests/run-make/remap-path-prefix/rmake.rs index 4d98dcf6131cd..62c0368e4b3a4 100644 --- a/tests/run-make/remap-path-prefix/rmake.rs +++ b/tests/run-make/remap-path-prefix/rmake.rs @@ -3,9 +3,8 @@ // 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}; +use run_make_support::bstr::ByteSlice; +use run_make_support::{bstr, fs_wrapper, is_darwin, rustc}; fn main() { let mut out_simple = rustc(); @@ -34,8 +33,8 @@ fn main() { .input("auxiliary/lib.rs"); out_simple.run(); - invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); - invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + rmeta_contains("/the/aux/lib.rs"); + rmeta_not_contains("auxiliary"); out_object.arg("-Zremap-path-scope=object"); out_macro.arg("-Zremap-path-scope=macro"); @@ -47,12 +46,42 @@ fn main() { } out_object.run(); - invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); - invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + rmeta_contains("/the/aux/lib.rs"); + rmeta_not_contains("auxiliary"); out_macro.run(); - invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); - invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + rmeta_contains("/the/aux/lib.rs"); + rmeta_not_contains("auxiliary"); out_diagobj.run(); - invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); - invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + rmeta_contains("/the/aux/lib.rs"); + rmeta_not_contains("auxiliary"); +} + +//FIXME(Oneirical): These could be generalized into run_make_support +// helper functions. +fn rmeta_contains(expected: &str) { + // Normalize to account for path differences in Windows. + if !bstr::BString::from(fs_wrapper::read("liblib.rmeta")) + .replace(b"\\", b"/") + .contains_str(expected) + { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta"))); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was not found in file"); + } +} + +fn rmeta_not_contains(expected: &str) { + // Normalize to account for path differences in Windows. + if bstr::BString::from(fs_wrapper::read("liblib.rmeta")) + .replace(b"\\", b"/") + .contains_str(expected) + { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta"))); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was not found in file"); + } }