Skip to content

Commit e385bc5

Browse files
committed
let compose_and_run take a Command
1 parent 6601ffc commit e385bc5

File tree

1 file changed

+55
-68
lines changed

1 file changed

+55
-68
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 55 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -325,39 +325,26 @@ impl<'test> TestCx<'test> {
325325
}
326326
}
327327

328-
fn print_source(&self,
329-
src: String,
330-
pretty_type: &str)
331-
-> ProcRes {
328+
fn print_source(&self, src: String, pretty_type: &str) -> ProcRes {
332329
let aux_dir = self.aux_output_dir_name();
333-
self.compose_and_run(self.make_pp_args(pretty_type.to_owned()),
330+
331+
let mut rustc = Command::new(&self.config.rustc_path);
332+
rustc.arg("-")
333+
.arg("-Zunstable-options")
334+
.args(&["--unpretty", &pretty_type])
335+
.args(&["--target", &self.config.target])
336+
.arg("-L").arg(&aux_dir)
337+
.args(self.split_maybe_args(&self.config.target_rustcflags))
338+
.args(&self.props.compile_flags);
339+
340+
self.compose_and_run(rustc,
334341
self.props.exec_env.clone(),
335342
self.config.compile_lib_path.to_str().unwrap(),
336343
Some(aux_dir.to_str().unwrap()),
337344
Some(src),
338345
None)
339346
}
340347

341-
fn make_pp_args(&self,
342-
pretty_type: String)
343-
-> ProcArgs {
344-
let aux_dir = self.aux_output_dir_name();
345-
// FIXME (#9639): This needs to handle non-utf8 paths
346-
let mut args = vec!["-".to_owned(),
347-
"-Zunstable-options".to_owned(),
348-
"--unpretty".to_owned(),
349-
pretty_type,
350-
format!("--target={}", self.config.target),
351-
"-L".to_owned(),
352-
aux_dir.to_str().unwrap().to_owned()];
353-
args.extend(self.split_maybe_args(&self.config.target_rustcflags));
354-
args.extend(self.props.compile_flags.iter().cloned());
355-
ProcArgs {
356-
prog: self.config.rustc_path.to_str().unwrap().to_owned(),
357-
args,
358-
}
359-
}
360-
361348
fn compare_source(&self,
362349
expected: &str,
363350
actual: &str) {
@@ -562,9 +549,9 @@ actual:\n\
562549
.output()
563550
.expect(&format!("failed to exec `{:?}`", gdb_path));
564551
let cmdline = {
565-
let cmdline = self.make_cmdline("",
566-
&format!("{}-gdb", self.config.target),
567-
&debugger_opts);
552+
let mut gdb = Command::new(&format!("{}-gdb", self.config.target));
553+
gdb.args(&debugger_opts);
554+
let cmdline = self.make_cmdline(&gdb, "");
568555
logv(self.config, format!("executing {}", cmdline));
569556
cmdline
570557
};
@@ -654,15 +641,13 @@ actual:\n\
654641
"-nx".to_owned(),
655642
format!("-command={}", debugger_script.to_str().unwrap())];
656643

657-
let proc_args = ProcArgs {
658-
prog: self.config.gdb.as_ref().unwrap().to_owned(),
659-
args: debugger_opts,
660-
};
644+
let mut gdb = Command::new(self.config.gdb.as_ref().unwrap());
645+
gdb.args(&debugger_opts);
661646

662647
let environment = vec![("PYTHONPATH".to_owned(), rust_pp_module_abs_path)];
663648

664649
debugger_run_result =
665-
self.compose_and_run(proc_args,
650+
self.compose_and_run(gdb,
666651
environment,
667652
self.config.run_lib_path.to_str().unwrap(),
668653
None,
@@ -1205,23 +1190,22 @@ actual:\n\
12051190
// the process) and then report back the same result.
12061191
_ if self.config.remote_test_client.is_some() => {
12071192
let aux_dir = self.aux_output_dir_name();
1208-
let mut args = self.make_run_args();
1209-
let mut program = args.prog.clone();
1193+
let ProcArgs { mut prog, args } = self.make_run_args();
12101194
if let Ok(entries) = aux_dir.read_dir() {
12111195
for entry in entries {
12121196
let entry = entry.unwrap();
12131197
if !entry.path().is_file() {
12141198
continue
12151199
}
1216-
program.push_str(":");
1217-
program.push_str(entry.path().to_str().unwrap());
1200+
prog.push_str(":");
1201+
prog.push_str(entry.path().to_str().unwrap());
12181202
}
12191203
}
1220-
args.args.insert(0, program);
1221-
args.args.insert(0, "run".to_string());
1222-
args.prog = self.config.remote_test_client.clone().unwrap()
1223-
.into_os_string().into_string().unwrap();
1224-
self.compose_and_run(args,
1204+
let mut test_client = Command::new(
1205+
self.config.remote_test_client.as_ref().unwrap());
1206+
test_client.args(&["run", &prog]);
1207+
test_client.args(args);
1208+
self.compose_and_run(test_client,
12251209
env,
12261210
self.config.run_lib_path.to_str().unwrap(),
12271211
Some(aux_dir.to_str().unwrap()),
@@ -1234,7 +1218,10 @@ actual:\n\
12341218
Some(self.output_base_name()
12351219
.parent().unwrap()
12361220
.to_str().unwrap().to_owned());
1237-
self.compose_and_run(self.make_run_args(),
1221+
let ProcArgs { prog, args } = self.make_run_args();
1222+
let mut program = Command::new(&prog);
1223+
program.args(args);
1224+
self.compose_and_run(program,
12381225
env,
12391226
self.config.run_lib_path.to_str().unwrap(),
12401227
Some(aux_dir.to_str().unwrap()),
@@ -1312,8 +1299,11 @@ actual:\n\
13121299
testpaths: &aux_testpaths,
13131300
revision: self.revision
13141301
};
1315-
let aux_args = aux_cx.make_compile_args(crate_type, &aux_testpaths.file, aux_output);
1316-
let auxres = aux_cx.compose_and_run(aux_args,
1302+
let ProcArgs { prog, args } =
1303+
aux_cx.make_compile_args(crate_type, &aux_testpaths.file, aux_output);
1304+
let mut rustc = Command::new(prog);
1305+
rustc.args(&args);
1306+
let auxres = aux_cx.compose_and_run(rustc,
13171307
Vec::new(),
13181308
aux_cx.config.compile_lib_path.to_str().unwrap(),
13191309
Some(aux_dir.to_str().unwrap()),
@@ -1327,7 +1317,11 @@ actual:\n\
13271317
}
13281318
}
13291319

1330-
self.compose_and_run(args,
1320+
let ProcArgs { prog, args } = args;
1321+
let mut rustc = Command::new(prog);
1322+
rustc.args(args);
1323+
1324+
self.compose_and_run(rustc,
13311325
self.props.rustc_env.clone(),
13321326
self.config.compile_lib_path.to_str().unwrap(),
13331327
Some(aux_dir.to_str().unwrap()),
@@ -1336,37 +1330,33 @@ actual:\n\
13361330
}
13371331

13381332
fn compose_and_run(&self,
1339-
ProcArgs{ args, prog }: ProcArgs,
1333+
mut command: Command,
13401334
procenv: Vec<(String, String)> ,
13411335
lib_path: &str,
13421336
aux_path: Option<&str>,
13431337
input: Option<String>,
13441338
working_dir: Option<String>) -> ProcRes {
13451339
let cmdline =
13461340
{
1347-
let cmdline = self.make_cmdline(lib_path,
1348-
&prog,
1349-
&args);
1341+
let cmdline = self.make_cmdline(&command, lib_path);
13501342
logv(self.config, format!("executing {}", cmdline));
13511343
cmdline
13521344
};
13531345

1354-
let mut process = Command::new(&prog);
1355-
process
1356-
.args(&args)
1346+
command
13571347
.stdout(Stdio::piped())
13581348
.stderr(Stdio::piped())
13591349
.stdin(Stdio::piped());
13601350

1361-
procsrv::add_target_env(&mut process, lib_path, aux_path);
1351+
procsrv::add_target_env(&mut command, lib_path, aux_path);
13621352
for (key, val) in procenv {
1363-
process.env(&key, &val);
1353+
command.env(&key, &val);
13641354
}
13651355
if let Some(cwd) = working_dir {
1366-
process.current_dir(cwd);
1356+
command.current_dir(cwd);
13671357
}
13681358

1369-
let mut child = process.spawn().expect(&format!("failed to exec `{}`", prog));
1359+
let mut child = command.spawn().expect(&format!("failed to exec `{:?}`", &command));
13701360
if let Some(input) = input {
13711361
child.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
13721362
}
@@ -1568,20 +1558,20 @@ actual:\n\
15681558
}
15691559
}
15701560

1571-
fn make_cmdline(&self, libpath: &str, prog: &str, args: &[String]) -> String {
1561+
fn make_cmdline(&self, command: &Command, libpath: &str) -> String {
15721562
use util;
15731563

15741564
// Linux and mac don't require adjusting the library search path
15751565
if cfg!(unix) {
1576-
format!("{} {}", prog, args.join(" "))
1566+
format!("{:?}", command)
15771567
} else {
15781568
// Build the LD_LIBRARY_PATH variable as it would be seen on the command line
15791569
// for diagnostic purposes
15801570
fn lib_path_cmd_prefix(path: &str) -> String {
15811571
format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path))
15821572
}
15831573

1584-
format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.join(" "))
1574+
format!("{} {:?}", lib_path_cmd_prefix(libpath), command)
15851575
}
15861576
}
15871577

@@ -1715,14 +1705,11 @@ actual:\n\
17151705

17161706
fn check_ir_with_filecheck(&self) -> ProcRes {
17171707
let irfile = self.output_base_name().with_extension("ll");
1718-
let prog = self.config.llvm_filecheck.as_ref().unwrap();
1719-
let proc_args = ProcArgs {
1720-
// FIXME (#9639): This needs to handle non-utf8 paths
1721-
prog: prog.to_str().unwrap().to_owned(),
1722-
args: vec![format!("-input-file={}", irfile.to_str().unwrap()),
1723-
self.testpaths.file.to_str().unwrap().to_owned()]
1724-
};
1725-
self.compose_and_run(proc_args, Vec::new(), "", None, None, None)
1708+
let mut filecheck = Command::new(self.config.llvm_filecheck.as_ref().unwrap());
1709+
// FIXME (#9639): This needs to handle non-utf8 paths
1710+
filecheck.arg(&format!("-input-file={}", irfile.to_str().unwrap()));
1711+
filecheck.arg(&self.testpaths.file);
1712+
self.compose_and_run(filecheck, Vec::new(), "", None, None, None)
17261713
}
17271714

17281715
fn run_codegen_test(&self) {

0 commit comments

Comments
 (0)