Skip to content

Commit 04dee08

Browse files
committed
return Command from make_compile_args
1 parent 90a87be commit 04dee08

File tree

1 file changed

+45
-68
lines changed

1 file changed

+45
-68
lines changed

src/tools/compiletest/src/runtest.rs

+45-68
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,9 @@ actual:\n\
11161116
}
11171117
_ => {}
11181118
}
1119-
let ProcArgs { prog, args } = self.make_compile_args(
1119+
1120+
let rustc = self.make_compile_args(
11201121
extra_args, &self.testpaths.file, TargetLocation::ThisFile(self.make_exe_name()));
1121-
let mut rustc = Command::new(prog);
1122-
rustc.args(args);
11231122
self.compose_and_run_compiler(rustc, None)
11241123
}
11251124

@@ -1280,11 +1279,9 @@ actual:\n\
12801279
testpaths: &aux_testpaths,
12811280
revision: self.revision
12821281
};
1283-
let ProcArgs { prog, args } =
1282+
let aux_rustc =
12841283
aux_cx.make_compile_args(crate_type, &aux_testpaths.file, aux_output);
1285-
let mut rustc = Command::new(prog);
1286-
rustc.args(&args);
1287-
let auxres = aux_cx.compose_and_run(rustc,
1284+
let auxres = aux_cx.compose_and_run(aux_rustc,
12881285
aux_cx.config.compile_lib_path.to_str().unwrap(),
12891286
Some(aux_dir.to_str().unwrap()),
12901287
None);
@@ -1341,48 +1338,38 @@ actual:\n\
13411338
}
13421339

13431340
fn make_compile_args(&self,
1344-
extras: Vec<String> ,
1341+
extra_args: Vec<String>,
13451342
input_file: &Path,
13461343
output_file: TargetLocation)
1347-
-> ProcArgs
1344+
-> Command
13481345
{
1349-
let target = if self.props.force_host {
1350-
&*self.config.host
1351-
} else {
1352-
&*self.config.target
1353-
};
1354-
1355-
// FIXME (#9639): This needs to handle non-utf8 paths
1356-
let mut args = vec![input_file.to_str().unwrap().to_owned(),
1357-
"-L".to_owned(),
1358-
self.config.build_base.to_str().unwrap().to_owned()];
1346+
let mut rustc = Command::new(&self.config.rustc_path);
1347+
rustc.arg(input_file)
1348+
.arg("-L").arg(&self.config.build_base);
13591349

13601350
// Optionally prevent default --target if specified in test compile-flags.
13611351
let custom_target = self.props.compile_flags
13621352
.iter()
13631353
.fold(false, |acc, x| acc || x.starts_with("--target"));
13641354

13651355
if !custom_target {
1366-
args.extend(vec![
1367-
format!("--target={}", target),
1368-
]);
1356+
let target = if self.props.force_host {
1357+
&*self.config.host
1358+
} else {
1359+
&*self.config.target
1360+
};
1361+
1362+
rustc.arg(&format!("--target={}", target));
13691363
}
13701364

13711365
if let Some(revision) = self.revision {
1372-
args.extend(vec![
1373-
"--cfg".to_string(),
1374-
revision.to_string(),
1375-
]);
1366+
rustc.args(&["--cfg", revision]);
13761367
}
13771368

13781369
if let Some(ref incremental_dir) = self.props.incremental_dir {
1379-
args.extend(vec![
1380-
"-Z".to_string(),
1381-
format!("incremental={}", incremental_dir.display()),
1382-
]);
1370+
rustc.args(&["-Z", &format!("incremental={}", incremental_dir.display())]);
13831371
}
13841372

1385-
13861373
match self.config.mode {
13871374
CompileFail |
13881375
ParseFail |
@@ -1391,27 +1378,22 @@ actual:\n\
13911378
// fashion, then you want JSON mode. Old-skool error
13921379
// patterns still match the raw compiler output.
13931380
if self.props.error_patterns.is_empty() {
1394-
args.extend(["--error-format",
1395-
"json"]
1396-
.iter()
1397-
.map(|s| s.to_string()));
1381+
rustc.args(&["--error-format", "json"]);
13981382
}
13991383
}
14001384
MirOpt => {
1401-
args.extend(["-Zdump-mir=all",
1402-
"-Zmir-opt-level=3",
1403-
"-Zdump-mir-exclude-pass-number"]
1404-
.iter()
1405-
.map(|s| s.to_string()));
1406-
1385+
rustc.args(&[
1386+
"-Zdump-mir=all",
1387+
"-Zmir-opt-level=3",
1388+
"-Zdump-mir-exclude-pass-number"]);
14071389

14081390
let mir_dump_dir = self.get_mir_dump_dir();
14091391
create_dir_all(mir_dump_dir.as_path()).unwrap();
14101392
let mut dir_opt = "-Zdump-mir-dir=".to_string();
14111393
dir_opt.push_str(mir_dump_dir.to_str().unwrap());
14121394
debug!("dir_opt: {:?}", dir_opt);
14131395

1414-
args.push(dir_opt);
1396+
rustc.arg(dir_opt);
14151397
}
14161398
RunPass |
14171399
RunFail |
@@ -1428,32 +1410,30 @@ actual:\n\
14281410
}
14291411
}
14301412

1431-
args.extend_from_slice(&extras);
1413+
rustc.args(&extra_args);
1414+
14321415
if !self.props.no_prefer_dynamic {
1433-
args.push("-C".to_owned());
1434-
args.push("prefer-dynamic".to_owned());
1416+
rustc.args(&["-C", "prefer-dynamic"]);
14351417
}
1436-
let path = match output_file {
1418+
1419+
match output_file {
14371420
TargetLocation::ThisFile(path) => {
1438-
args.push("-o".to_owned());
1439-
path
1421+
rustc.arg("-o").arg(path);
14401422
}
14411423
TargetLocation::ThisDirectory(path) => {
1442-
args.push("--out-dir".to_owned());
1443-
path
1424+
rustc.arg("--out-dir").arg(path);
14441425
}
1445-
};
1446-
args.push(path.to_str().unwrap().to_owned());
1426+
}
1427+
14471428
if self.props.force_host {
1448-
args.extend(self.split_maybe_args(&self.config.host_rustcflags));
1429+
rustc.args(self.split_maybe_args(&self.config.host_rustcflags));
14491430
} else {
1450-
args.extend(self.split_maybe_args(&self.config.target_rustcflags));
1451-
}
1452-
args.extend(self.props.compile_flags.iter().cloned());
1453-
ProcArgs {
1454-
prog: self.config.rustc_path.to_str().unwrap().to_owned(),
1455-
args,
1431+
rustc.args(self.split_maybe_args(&self.config.target_rustcflags));
14561432
}
1433+
1434+
rustc.args(&self.props.compile_flags);
1435+
1436+
rustc
14571437
}
14581438

14591439
fn make_lib_name(&self, auxfile: &Path) -> PathBuf {
@@ -1660,15 +1640,12 @@ actual:\n\
16601640
aux_dir.to_str().unwrap().to_owned()];
16611641
let llvm_args = vec!["--emit=llvm-ir".to_owned(),];
16621642
link_args.extend(llvm_args);
1663-
let args = self.make_compile_args(link_args,
1664-
&self.testpaths.file,
1665-
TargetLocation::ThisDirectory(
1666-
self.output_base_name().parent()
1667-
.unwrap()
1668-
.to_path_buf()));
1669-
let ProcArgs { prog, args } = args;
1670-
let mut rustc = Command::new(prog);
1671-
rustc.args(args);
1643+
let rustc = self.make_compile_args(link_args,
1644+
&self.testpaths.file,
1645+
TargetLocation::ThisDirectory(
1646+
self.output_base_name().parent()
1647+
.unwrap()
1648+
.to_path_buf()));
16721649
self.compose_and_run_compiler(rustc, None)
16731650
}
16741651

0 commit comments

Comments
 (0)