|
| 1 | +// Generating metadata alongside remap-path-prefix would fail to actually remap the path |
| 2 | +// in the metadata. After this was fixed in #85344, this test checks that "auxiliary" is being |
| 3 | +// successfully remapped to "/the/aux" in the rmeta files. |
| 4 | +// See https://github.com/rust-lang/rust/pull/85344 |
| 5 | + |
| 6 | +// FIXME(Oneirical): check if works without ignore-windows |
| 7 | + |
| 8 | +use run_make_support::bstr::ByteSlice; |
| 9 | +use run_make_support::{bstr, fs_wrapper, is_darwin, rustc}; |
| 10 | + |
| 11 | +fn main() { |
| 12 | + let mut out_simple = rustc(); |
| 13 | + let mut out_object = rustc(); |
| 14 | + let mut out_macro = rustc(); |
| 15 | + let mut out_diagobj = rustc(); |
| 16 | + out_simple |
| 17 | + .remap_path_prefix("auxiliary", "/the/aux") |
| 18 | + .crate_type("lib") |
| 19 | + .emit("metadata") |
| 20 | + .input("auxiliary/lib.rs"); |
| 21 | + out_object |
| 22 | + .remap_path_prefix("auxiliary", "/the/aux") |
| 23 | + .crate_type("lib") |
| 24 | + .emit("metadata") |
| 25 | + .input("auxiliary/lib.rs"); |
| 26 | + out_macro |
| 27 | + .remap_path_prefix("auxiliary", "/the/aux") |
| 28 | + .crate_type("lib") |
| 29 | + .emit("metadata") |
| 30 | + .input("auxiliary/lib.rs"); |
| 31 | + out_diagobj |
| 32 | + .remap_path_prefix("auxiliary", "/the/aux") |
| 33 | + .crate_type("lib") |
| 34 | + .emit("metadata") |
| 35 | + .input("auxiliary/lib.rs"); |
| 36 | + |
| 37 | + out_simple.run(); |
| 38 | + rmeta_contains("/the/aux/lib.rs"); |
| 39 | + rmeta_not_contains("auxiliary"); |
| 40 | + |
| 41 | + out_object.arg("-Zremap-path-scope=object"); |
| 42 | + out_macro.arg("-Zremap-path-scope=macro"); |
| 43 | + out_diagobj.arg("-Zremap-path-scope=diagnostics,object"); |
| 44 | + if is_darwin() { |
| 45 | + out_object.arg("-Csplit-debuginfo=off"); |
| 46 | + out_macro.arg("-Csplit-debuginfo=off"); |
| 47 | + out_diagobj.arg("-Csplit-debuginfo=off"); |
| 48 | + } |
| 49 | + |
| 50 | + out_object.run(); |
| 51 | + rmeta_contains("/the/aux/lib.rs"); |
| 52 | + rmeta_not_contains("auxiliary"); |
| 53 | + out_macro.run(); |
| 54 | + rmeta_contains("/the/aux/lib.rs"); |
| 55 | + rmeta_not_contains("auxiliary"); |
| 56 | + out_diagobj.run(); |
| 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 | + } |
| 89 | +} |
0 commit comments