rewrite remap-path-prefix-dwarf to rmake · rust-lang/rust@fe52572 (original) (raw)
``
1
`+
// This test makes sure that --remap-path-prefix has the expected effects on paths in debuginfo.
`
``
2
`+
// We explicitly switch to a directory that is a prefix of the directory our
`
``
3
`+
// source code is contained in.
`
``
4
`+
// It tests several cases, each of them has a detailed description attached to it.
`
``
5
`+
// See https://github.com/rust-lang/rust/pull/96867
`
``
6
+
``
7
`+
//@ ignore-windows
`
``
8
`+
// Reason: the remap path prefix is not printed in the dwarf dump.
`
``
9
+
``
10
`+
use run_make_support::{cwd, is_darwin, llvm_dwarfdump, rust_lib_name, rustc};
`
``
11
+
``
12
`+
fn main() {
`
``
13
`+
// The compiler is called with an ABSOLUTE PATH as input, and that absolute path is within
`
``
14
`` +
// the working directory of the compiler. We are remapping the path that contains src
.
``
``
15
`+
check_dwarf(DwarfTest {
`
``
16
`+
lib_name: "abs_input_inside_working_dir",
`
``
17
`+
input_path: PathType::Absolute,
`
``
18
`+
scope: None,
`
``
19
`+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
`
``
20
`+
dwarf_test: DwarfDump::ContainsSrcPath,
`
``
21
`+
});
`
``
22
`+
check_dwarf(DwarfTest {
`
``
23
`+
lib_name: "abs_input_inside_working_dir_scope",
`
``
24
`+
input_path: PathType::Absolute,
`
``
25
`+
scope: Some(ScopeType::Object),
`
``
26
`+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
`
``
27
`+
dwarf_test: DwarfDump::ContainsSrcPath,
`
``
28
`+
});
`
``
29
`+
// The compiler is called with an ABSOLUTE PATH as input, and that absolute path is not
`
``
30
`+
// within the working directory of the compiler. We are remapping both the path that contains
`
``
31
`` +
// src
and the working directory to the same thing. This setup corresponds to a workaround
``
``
32
`+
// that is needed when trying to remap everything to something that looks like a local
`
``
33
`+
// path. Relative paths are interpreted as relative to the compiler's working directory (e.g.
`
``
34
`+
// in debuginfo). If we also remap the working directory, the compiler strip it from other
`
``
35
`+
// paths so that the final outcome is the desired one again.
`
``
36
`+
check_dwarf(DwarfTest {
`
``
37
`+
lib_name: "abs_input_outside_working_dir",
`
``
38
`+
input_path: PathType::Absolute,
`
``
39
`+
scope: None,
`
``
40
`+
remap_path_prefix: PrefixType::Dual((
`
``
41
`+
format!("{}=REMAPPED", cwd().display()),
`
``
42
`+
"rmake_out=REMAPPED".to_owned(),
`
``
43
`+
)),
`
``
44
`+
dwarf_test: DwarfDump::ContainsSrcPath,
`
``
45
`+
});
`
``
46
`+
// The compiler is called with a RELATIVE PATH as input. We are remapping the working
`
``
47
`+
// directory of the compiler, which naturally is an implicit prefix of our relative input path.
`
``
48
`+
// Debuginfo will expand the relative path to an absolute path and we expect the working
`
``
49
`+
// directory to be remapped in that expansion.
`
``
50
`+
check_dwarf(DwarfTest {
`
``
51
`+
lib_name: "rel_input_remap_working_dir",
`
``
52
`+
input_path: PathType::Relative,
`
``
53
`+
scope: None,
`
``
54
`+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
`
``
55
`+
dwarf_test: DwarfDump::ContainsSrcPath,
`
``
56
`+
});
`
``
57
`+
check_dwarf(DwarfTest {
`
``
58
`+
lib_name: "rel_input_remap_working_dir_scope",
`
``
59
`+
input_path: PathType::Relative,
`
``
60
`+
scope: Some(ScopeType::Object),
`
``
61
`+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
`
``
62
`+
dwarf_test: DwarfDump::ContainsSrcPath,
`
``
63
`+
});
`
``
64
`+
check_dwarf(DwarfTest {
`
``
65
`+
lib_name: "rel_input_remap_working_dir_scope",
`
``
66
`+
input_path: PathType::Relative,
`
``
67
`+
scope: Some(ScopeType::Diagnostics),
`
``
68
`+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
`
``
69
`+
dwarf_test: DwarfDump::AvoidSrcPath,
`
``
70
`+
});
`
``
71
`+
// The compiler is called with a RELATIVE PATH as input. We are remapping a SUB-DIRECTORY
`
``
72
`+
// of the compiler's working directory. This test makes sure that that directory is remapped
`
``
73
`+
// even though it won't actually show up in this form in the compiler's SourceMap and instead
`
``
74
`+
// is only constructed on demand during debuginfo generation.
`
``
75
`+
check_dwarf(DwarfTest {
`
``
76
`+
lib_name: "rel_input_remap_working_dir_child",
`
``
77
`+
input_path: PathType::Relative,
`
``
78
`+
scope: None,
`
``
79
`+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().join("src").display())),
`
``
80
`+
dwarf_test: DwarfDump::ChildTest,
`
``
81
`+
});
`
``
82
`+
// The compiler is called with a RELATIVE PATH as input. We are remapping a
`
``
83
`+
// PARENT DIRECTORY of the compiler's working directory.
`
``
84
`+
check_dwarf(DwarfTest {
`
``
85
`+
lib_name: "rel_input_remap_working_dir_parent",
`
``
86
`+
input_path: PathType::Relative,
`
``
87
`+
scope: None,
`
``
88
`+
remap_path_prefix: PrefixType::Regular(format!(
`
``
89
`+
"{}=REMAPPED",
`
``
90
`+
cwd().parent().unwrap().display()
`
``
91
`+
)),
`
``
92
`+
dwarf_test: DwarfDump::ParentTest,
`
``
93
`+
});
`
``
94
`+
}
`
``
95
+
``
96
`+
#[track_caller]
`
``
97
`+
fn check_dwarf(test: DwarfTest) {
`
``
98
`+
let mut rustc = rustc();
`
``
99
`+
match test.input_path {
`
``
100
`+
PathType::Absolute => rustc.input(cwd().join("src/quux.rs")),
`
``
101
`+
PathType::Relative => rustc.input("src/quux.rs"),
`
``
102
`+
};
`
``
103
`+
rustc.output(rust_lib_name(test.lib_name));
`
``
104
`+
rustc.arg("-Cdebuginfo=2");
`
``
105
`+
if let Some(scope) = test.scope {
`
``
106
`+
match scope {
`
``
107
`+
ScopeType::Object => rustc.arg("-Zremap-path-scope=object"),
`
``
108
`+
ScopeType::Diagnostics => rustc.arg("-Zremap-path-scope=diagnostics"),
`
``
109
`+
};
`
``
110
`+
if is_darwin() {
`
``
111
`+
rustc.arg("-Csplit-debuginfo=off");
`
``
112
`+
}
`
``
113
`+
}
`
``
114
`+
match test.remap_path_prefix {
`
``
115
`+
PrefixType::Regular(prefix) => {
`
``
116
`+
// We explicitly switch to a directory that is a prefix of the directory our
`
``
117
`+
// source code is contained in.
`
``
118
`+
rustc.arg("--remap-path-prefix");
`
``
119
`+
rustc.arg(prefix);
`
``
120
`+
}
`
``
121
`+
PrefixType::Dual((prefix1, prefix2)) => {
`
``
122
`+
// We explicitly switch to a directory that is not a prefix of the directory our
`
``
123
`+
// source code is contained in.
`
``
124
`+
rustc.arg("--remap-path-prefix");
`
``
125
`+
rustc.arg(prefix1);
`
``
126
`+
rustc.arg("--remap-path-prefix");
`
``
127
`+
rustc.arg(prefix2);
`
``
128
`+
}
`
``
129
`+
}
`
``
130
`+
rustc.run();
`
``
131
`+
match test.dwarf_test {
`
``
132
`+
DwarfDump::ContainsSrcPath => {
`
``
133
`+
llvm_dwarfdump()
`
``
134
`+
.input(rust_lib_name(test.lib_name))
`
``
135
`+
.run()
`
``
136
`+
// We expect the path to the main source file to be remapped.
`
``
137
`+
.assert_stdout_contains("REMAPPED/src/quux.rs")
`
``
138
`+
// No weird duplication of remapped components (see #78479)
`
``
139
`+
.assert_stdout_not_contains("REMAPPED/REMAPPED");
`
``
140
`+
}
`
``
141
`+
DwarfDump::AvoidSrcPath => {
`
``
142
`+
llvm_dwarfdump()
`
``
143
`+
.input(rust_lib_name(test.lib_name))
`
``
144
`+
.run()
`
``
145
`+
.assert_stdout_not_contains("REMAPPED/src/quux.rs")
`
``
146
`+
.assert_stdout_not_contains("REMAPPED/REMAPPED");
`
``
147
`+
}
`
``
148
`+
DwarfDump::ChildTest => {
`
``
149
`+
llvm_dwarfdump()
`
``
150
`+
.input(rust_lib_name(test.lib_name))
`
``
151
`+
.run()
`
``
152
`` +
// We expect src/quux.rs
to have been remapped to REMAPPED/quux.rs
.
``
``
153
`+
.assert_stdout_contains("REMAPPED/quux.rs")
`
``
154
`+
// We don't want to find the path that we just remapped anywhere in the DWARF
`
``
155
`+
.assert_stdout_not_contains(cwd().join("src").to_str().unwrap())
`
``
156
`+
// No weird duplication of remapped components (see #78479)
`
``
157
`+
.assert_stdout_not_contains("REMAPPED/REMAPPED");
`
``
158
`+
}
`
``
159
`+
DwarfDump::ParentTest => {
`
``
160
`+
llvm_dwarfdump()
`
``
161
`+
.input(rust_lib_name(test.lib_name))
`
``
162
`+
.run()
`
``
163
`` +
// We expect src/quux.rs
to have been remapped to
``
``
164
`` +
// REMAPPED/remap-path-prefix-dwarf/src/quux.rs
.
``
``
165
`+
.assert_stdout_contains("REMAPPED/rmake_out/src/quux.rs")
`
``
166
`+
// We don't want to find the path that we just remapped anywhere in the DWARF
`
``
167
`+
.assert_stdout_not_contains(cwd().parent().unwrap().to_str().unwrap())
`
``
168
`+
// No weird duplication of remapped components (see #78479)
`
``
169
`+
.assert_stdout_not_contains("REMAPPED/REMAPPED");
`
``
170
`+
}
`
``
171
`+
};
`
``
172
`+
}
`
``
173
+
``
174
`+
struct DwarfTest {
`
``
175
`+
lib_name: &'static str,
`
``
176
`+
input_path: PathType,
`
``
177
`+
scope: Option,
`
``
178
`+
remap_path_prefix: PrefixType,
`
``
179
`+
dwarf_test: DwarfDump,
`
``
180
`+
}
`
``
181
+
``
182
`+
enum PathType {
`
``
183
`+
Absolute,
`
``
184
`+
Relative,
`
``
185
`+
}
`
``
186
+
``
187
`+
enum ScopeType {
`
``
188
`+
Object,
`
``
189
`+
Diagnostics,
`
``
190
`+
}
`
``
191
+
``
192
`+
enum DwarfDump {
`
``
193
`+
ContainsSrcPath,
`
``
194
`+
AvoidSrcPath,
`
``
195
`+
ChildTest,
`
``
196
`+
ParentTest,
`
``
197
`+
}
`
``
198
+
``
199
`+
enum PrefixType {
`
``
200
`+
Regular(String),
`
``
201
`+
Dual((String, String)),
`
``
202
`+
}
`