Skip to content

Commit

Permalink
rmeta_contains functions for remap-path-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 28, 2024
1 parent 133b47a commit 1795082
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3401,6 +3401,7 @@ name = "run_make_support"
version = "0.2.0"
dependencies = [
"ar",
"bstr",
"gimli 0.28.1",
"object 0.34.0",
"regex",
Expand Down
1 change: 1 addition & 0 deletions src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 40 additions & 11 deletions tests/run-make/remap-path-prefix/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -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");
}
}

0 comments on commit 1795082

Please sign in to comment.