Skip to content

Commit 2e1fd8f

Browse files
committed
rmeta_contains functions for remap-path-prefix
1 parent 133b47a commit 2e1fd8f

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3401,6 +3401,7 @@ name = "run_make_support"
34013401
version = "0.2.0"
34023402
dependencies = [
34033403
"ar",
3404+
"bstr",
34043405
"gimli 0.28.1",
34053406
"object 0.34.0",
34063407
"regex",

src/tools/run-make-support/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.2.0"
44
edition = "2021"
55

66
[dependencies]
7+
bstr = "1.6.0"
78
object = "0.34.0"
89
similar = "2.5.0"
910
wasmparser = "0.118.2"

src/tools/run-make-support/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::io;
2121
use std::panic;
2222
use std::path::{Path, PathBuf};
2323

24+
pub use bstr;
2425
pub use gimli;
2526
pub use object;
2627
pub use regex;

tests/run-make/remap-path-prefix/rmake.rs

+40-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
// FIXME(Oneirical): check if works without ignore-windows
77

8-
use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, is_darwin, rustc};
8+
use run_make_support::bstr::ByteSlice;
9+
use run_make_support::{bstr, fs_wrapper, is_darwin, rustc};
910

1011
fn main() {
1112
let mut out_simple = rustc();
@@ -34,8 +35,8 @@ fn main() {
3435
.input("auxiliary/lib.rs");
3536

3637
out_simple.run();
37-
invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
38-
invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
38+
rmeta_contains("/the/aux/lib.rs");
39+
rmeta_not_contains("auxiliary");
3940

4041
out_object.arg("-Zremap-path-scope=object");
4142
out_macro.arg("-Zremap-path-scope=macro");
@@ -47,12 +48,42 @@ fn main() {
4748
}
4849

4950
out_object.run();
50-
invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
51-
invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
51+
rmeta_contains("/the/aux/lib.rs");
52+
rmeta_not_contains("auxiliary");
5253
out_macro.run();
53-
invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
54-
invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
54+
rmeta_contains("/the/aux/lib.rs");
55+
rmeta_not_contains("auxiliary");
5556
out_diagobj.run();
56-
invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs");
57-
invalid_utf8_not_contains("liblib.rmeta", "auxiliary");
57+
rmeta_contains("/the/aux/lib.rs");
58+
rmeta_not_contains("auxiliary");
59+
}
60+
61+
//FIXME(Oneirical): These could be generalized into run_make_support
62+
// helper functions.
63+
fn rmeta_contains(expected: &str) {
64+
// Normalize to account for path differences in Windows.
65+
if !bstr::BString::from(fs_wrapper::read("liblib.rmeta"))
66+
.replace(b"\\", b"/")
67+
.contains_str(expected)
68+
{
69+
eprintln!("=== FILE CONTENTS (LOSSY) ===");
70+
eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta")));
71+
eprintln!("=== SPECIFIED TEXT ===");
72+
eprintln!("{}", expected);
73+
panic!("specified text was not found in file");
74+
}
75+
}
76+
77+
fn rmeta_not_contains(expected: &str) {
78+
// Normalize to account for path differences in Windows.
79+
if bstr::BString::from(fs_wrapper::read("liblib.rmeta"))
80+
.replace(b"\\", b"/")
81+
.contains_str(expected)
82+
{
83+
eprintln!("=== FILE CONTENTS (LOSSY) ===");
84+
eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta")));
85+
eprintln!("=== SPECIFIED TEXT ===");
86+
eprintln!("{}", expected);
87+
panic!("specified text was not found in file");
88+
}
5889
}

0 commit comments

Comments
 (0)