1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
pub use self::Mode::*;
use std::env;
use std::fmt;
use std::fs::{read_dir, remove_file};
use std::str::FromStr;
use std::path::PathBuf;
#[cfg(not(feature = "norustc"))]
use rustc;
use test::ColorConfig;
use runtest::dylib_env_var;
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Mode {
CompileFail,
ParseFail,
RunFail,
RunPass,
RunPassValgrind,
Pretty,
DebugInfoGdb,
DebugInfoLldb,
Codegen,
Rustdoc,
CodegenUnits,
Incremental,
RunMake,
Ui,
MirOpt,
}
impl Mode {
pub fn disambiguator(self) -> &'static str {
match self {
Pretty => ".pretty",
DebugInfoGdb => ".gdb",
DebugInfoLldb => ".lldb",
_ => "",
}
}
}
impl FromStr for Mode {
type Err = ();
fn from_str(s: &str) -> Result<Mode, ()> {
match s {
"compile-fail" => Ok(CompileFail),
"parse-fail" => Ok(ParseFail),
"run-fail" => Ok(RunFail),
"run-pass" => Ok(RunPass),
"run-pass-valgrind" => Ok(RunPassValgrind),
"pretty" => Ok(Pretty),
"debuginfo-lldb" => Ok(DebugInfoLldb),
"debuginfo-gdb" => Ok(DebugInfoGdb),
"codegen" => Ok(Codegen),
"rustdoc" => Ok(Rustdoc),
"codegen-units" => Ok(CodegenUnits),
"incremental" => Ok(Incremental),
"run-make" => Ok(RunMake),
"ui" => Ok(Ui),
"mir-opt" => Ok(MirOpt),
_ => Err(()),
}
}
}
impl fmt::Display for Mode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(match *self {
CompileFail => "compile-fail",
ParseFail => "parse-fail",
RunFail => "run-fail",
RunPass => "run-pass",
RunPassValgrind => "run-pass-valgrind",
Pretty => "pretty",
DebugInfoGdb => "debuginfo-gdb",
DebugInfoLldb => "debuginfo-lldb",
Codegen => "codegen",
Rustdoc => "rustdoc",
CodegenUnits => "codegen-units",
Incremental => "incremental",
RunMake => "run-make",
Ui => "ui",
MirOpt => "mir-opt",
},
f)
}
}
#[derive(Clone)]
pub struct Config {
pub compile_lib_path: PathBuf,
pub run_lib_path: PathBuf,
pub rustc_path: PathBuf,
pub rustdoc_path: Option<PathBuf>,
pub lldb_python: String,
pub docck_python: String,
pub llvm_filecheck: Option<PathBuf>,
pub valgrind_path: Option<String>,
pub force_valgrind: bool,
pub src_base: PathBuf,
pub build_base: PathBuf,
pub stage_id: String,
pub mode: Mode,
pub run_ignored: bool,
pub filter: Option<String>,
pub filter_exact: bool,
pub logfile: Option<PathBuf>,
pub runtool: Option<String>,
pub host_rustcflags: Option<String>,
pub target_rustcflags: Option<String>,
pub target: String,
pub host: String,
pub gdb: Option<String>,
pub gdb_version: Option<u32>,
pub gdb_native_rust: bool,
pub lldb_version: Option<String>,
pub llvm_version: Option<String>,
pub system_llvm: bool,
pub android_cross_path: PathBuf,
pub adb_path: String,
pub adb_test_dir: String,
pub adb_device_status: bool,
pub lldb_python_dir: Option<String>,
pub verbose: bool,
pub quiet: bool,
pub color: ColorConfig,
pub remote_test_client: Option<PathBuf>,
pub cc: String,
pub cxx: String,
pub cflags: String,
pub ar: String,
pub linker: Option<String>,
pub llvm_components: String,
pub llvm_cxxflags: String,
pub nodejs: Option<String>,
}
#[derive(Clone)]
pub struct TestPaths {
pub file: PathBuf,
pub base: PathBuf,
pub relative_dir: PathBuf,
}
impl Config {
pub fn link_deps(&mut self) {
let varname = dylib_env_var();
let lib_paths = env::var(varname).unwrap_or_else(|e| {
panic!("Cannot link to dependencies. Problem with env var '{}': {:?}", varname, e)
});
let mut flags = self.target_rustcflags.take().unwrap_or_else(String::new);
for p in env::split_paths(&lib_paths) {
flags += " -L ";
flags += p.to_str().unwrap();
}
self.target_rustcflags = Some(flags);
}
pub fn clean_rmeta(&self) {
if self.target_rustcflags.is_some() {
for directory in self.target_rustcflags
.as_ref()
.unwrap()
.split_whitespace()
.filter(|s| s.ends_with("/deps"))
{
if let Ok(mut entries) = read_dir(directory) {
while let Some(Ok(entry)) = entries.next() {
if entry.file_name().to_string_lossy().ends_with(".rmeta") {
let _ = remove_file(entry.path());
}
}
}
}
}
}
#[cfg(feature = "tmp")]
pub fn tempdir(mut self) -> config_tempdir::ConfigWithTemp {
use tempfile;
let tmp = tempfile::Builder::new().prefix("compiletest").tempdir()
.expect("failed to create temporary directory");
self.build_base = tmp.path().to_owned();
config_tempdir::ConfigWithTemp {
config: self,
tempdir: tmp,
}
}
}
#[cfg(feature = "tmp")]
mod config_tempdir {
use tempfile;
use std::ops;
pub struct ConfigWithTemp {
pub config: super::Config,
pub tempdir: tempfile::TempDir,
}
impl ops::Deref for ConfigWithTemp {
type Target = super::Config;
fn deref(&self) -> &Self::Target {
&self.config
}
}
impl ops::DerefMut for ConfigWithTemp {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.config
}
}
}
impl Default for Config {
fn default() -> Config {
#[cfg(not(feature = "norustc"))]
let platform = rustc::session::config::host_triple().to_string();
Config {
compile_lib_path: PathBuf::from(""),
run_lib_path: PathBuf::from(""),
rustc_path: PathBuf::from("rustc"),
rustdoc_path: None,
lldb_python: "python".to_owned(),
docck_python: "docck-python".to_owned(),
valgrind_path: None,
force_valgrind: false,
llvm_filecheck: None,
src_base: PathBuf::from("tests/run-pass"),
build_base: env::temp_dir(),
stage_id: "stage-id".to_owned(),
mode: Mode::RunPass,
run_ignored: false,
filter: None,
filter_exact: false,
logfile: None,
runtool: None,
host_rustcflags: None,
target_rustcflags: None,
#[cfg(not(feature = "norustc"))]
target: platform.clone(),
#[cfg(feature = "norustc")]
target: env!("TARGET").to_string(),
#[cfg(not(feature = "norustc"))]
host: platform.clone(),
#[cfg(feature = "norustc")]
host: env!("HOST").to_string(),
gdb: None,
gdb_version: None,
gdb_native_rust: false,
lldb_version: None,
llvm_version: None,
system_llvm: false,
android_cross_path: PathBuf::from("android-cross-path"),
adb_path: "adb-path".to_owned(),
adb_test_dir: "adb-test-dir/target".to_owned(),
adb_device_status: false,
lldb_python_dir: None,
verbose: false,
quiet: false,
color: ColorConfig::AutoColor,
remote_test_client: None,
cc: "cc".to_string(),
cxx: "cxx".to_string(),
cflags: "cflags".to_string(),
ar: "ar".to_string(),
linker: None,
llvm_components: "llvm-components".to_string(),
llvm_cxxflags: "llvm-cxxflags".to_string(),
nodejs: None,
}
}
}