Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1795082

Browse files
committedJun 28, 2024
rmeta_contains functions for remap-path-prefix
1 parent 133b47a commit 1795082

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
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-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
// successfully remapped to "/the/aux" in the rmeta files.
44
// See https://github.com/rust-lang/rust/pull/85344
55

6-
// FIXME(Oneirical): check if works without ignore-windows
7-
8-
use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, is_darwin, rustc};
6+
use run_make_support::bstr::ByteSlice;
7+
use run_make_support::{bstr, fs_wrapper, is_darwin, rustc};
98

109
fn main() {
1110
let mut out_simple = rustc();
@@ -34,8 +33,8 @@ fn main() {
3433
.input("auxiliary/lib.rs");
3534

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

4039
out_object.arg("-Zremap-path-scope=object");
4140
out_macro.arg("-Zremap-path-scope=macro");
@@ -47,12 +46,42 @@ fn main() {
4746
}
4847

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

0 commit comments

Comments
 (0)
Failed to load comments.