Skip to content

Commit 47703d3

Browse files
committed
compiletest: refactor rustcflags to Vec
1 parent 2f172b4 commit 47703d3

File tree

4 files changed

+22
-39
lines changed

4 files changed

+22
-39
lines changed

Diff for: src/bootstrap/test.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
13861386
}
13871387
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
13881388
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1389-
flags.push(builder.config.cmd.rustc_args().join(" "));
1389+
flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
13901390

13911391
if let Some(linker) = builder.linker(target) {
13921392
cmd.arg("--linker").arg(linker);
@@ -1395,12 +1395,16 @@ note: if you're sure you want to do this, please open an issue as to why. In the
13951395
let mut hostflags = flags.clone();
13961396
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
13971397
hostflags.extend(builder.lld_flags(compiler.host));
1398-
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1398+
for flag in hostflags {
1399+
cmd.arg("--host-rustcflags").arg(flag);
1400+
}
13991401

14001402
let mut targetflags = flags;
14011403
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
14021404
targetflags.extend(builder.lld_flags(target));
1403-
cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1405+
for flag in targetflags {
1406+
cmd.arg("--target-rustcflags").arg(flag);
1407+
}
14041408

14051409
cmd.arg("--python").arg(builder.python());
14061410

Diff for: src/tools/compiletest/src/common.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ pub struct Config {
269269
pub runtool: Option<String>,
270270

271271
/// Flags to pass to the compiler when building for the host
272-
pub host_rustcflags: Option<String>,
272+
pub host_rustcflags: Vec<String>,
273273

274274
/// Flags to pass to the compiler when building for the target
275-
pub target_rustcflags: Option<String>,
275+
pub target_rustcflags: Vec<String>,
276276

277277
/// Whether tests should be optimized by default. Individual test-suites and test files may
278278
/// override this setting.
@@ -457,12 +457,12 @@ pub enum Endian {
457457
}
458458

459459
impl TargetCfg {
460-
fn new(rustc_path: &Path, target: &str, target_rustcflags: &Option<String>) -> TargetCfg {
460+
fn new(rustc_path: &Path, target: &str, target_rustcflags: &Vec<String>) -> TargetCfg {
461461
let output = match Command::new(rustc_path)
462462
.arg("--print=cfg")
463463
.arg("--target")
464464
.arg(target)
465-
.args(target_rustcflags.into_iter().map(|s| s.split_whitespace()).flatten())
465+
.args(target_rustcflags)
466466
.output()
467467
{
468468
Ok(output) => output,

Diff for: src/tools/compiletest/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
252252
}),
253253
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
254254
runtool: matches.opt_str("runtool"),
255-
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
256-
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
255+
host_rustcflags: matches.opt_strs("host-rustcflags"),
256+
target_rustcflags: matches.opt_strs("target-rustcflags"),
257257
optimize_tests: matches.opt_present("optimize-tests"),
258258
target,
259259
host: opt_str2(matches.opt_str("host")),
@@ -320,8 +320,8 @@ pub fn log_config(config: &Config) {
320320
format!("force_pass_mode: {}", opt_str(&config.force_pass_mode.map(|m| format!("{}", m))),),
321321
);
322322
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
323-
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
324-
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
323+
logv(c, format!("host-rustcflags: {:?}", config.host_rustcflags));
324+
logv(c, format!("target-rustcflags: {:?}", config.target_rustcflags));
325325
logv(c, format!("target: {}", config.target));
326326
logv(c, format!("host: {}", config.host));
327327
logv(c, format!("android-cross-path: {:?}", config.android_cross_path.display()));

Diff for: src/tools/compiletest/src/runtest.rs

+7-28
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,7 @@ impl<'test> TestCx<'test> {
558558
.arg(&aux_dir)
559559
.args(&self.props.compile_flags)
560560
.envs(self.props.rustc_env.clone());
561-
self.maybe_add_external_args(
562-
&mut rustc,
563-
self.split_maybe_args(&self.config.target_rustcflags),
564-
);
561+
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
565562

566563
let src = match read_from {
567564
ReadFrom::Stdin(src) => Some(src),
@@ -629,10 +626,7 @@ impl<'test> TestCx<'test> {
629626
.arg("-L")
630627
.arg(aux_dir);
631628
self.set_revision_flags(&mut rustc);
632-
self.maybe_add_external_args(
633-
&mut rustc,
634-
self.split_maybe_args(&self.config.target_rustcflags),
635-
);
629+
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
636630
rustc.args(&self.props.compile_flags);
637631

638632
self.compose_and_run_compiler(rustc, Some(src))
@@ -1186,23 +1180,14 @@ impl<'test> TestCx<'test> {
11861180
ProcRes { status, stdout: out, stderr: err, cmdline: format!("{:?}", cmd) }
11871181
}
11881182

1189-
fn cleanup_debug_info_options(&self, options: &Option<String>) -> Option<String> {
1190-
if options.is_none() {
1191-
return None;
1192-
}
1193-
1183+
fn cleanup_debug_info_options(&self, options: &Vec<String>) -> Vec<String> {
11941184
// Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
11951185
let options_to_remove = ["-O".to_owned(), "-g".to_owned(), "--debuginfo".to_owned()];
1196-
let new_options = self
1197-
.split_maybe_args(options)
1198-
.into_iter()
1199-
.filter(|x| !options_to_remove.contains(x))
1200-
.collect::<Vec<String>>();
12011186

1202-
Some(new_options.join(" "))
1187+
options.to_vec().into_iter().filter(|x| !options_to_remove.contains(x)).collect()
12031188
}
12041189

1205-
fn maybe_add_external_args(&self, cmd: &mut Command, args: Vec<String>) {
1190+
fn maybe_add_external_args(&self, cmd: &mut Command, args: &Vec<String>) {
12061191
// Filter out the arguments that should not be added by runtest here.
12071192
//
12081193
// Notable use-cases are: do not add our optimisation flag if
@@ -2035,15 +2020,9 @@ impl<'test> TestCx<'test> {
20352020
}
20362021

20372022
if self.props.force_host {
2038-
self.maybe_add_external_args(
2039-
&mut rustc,
2040-
self.split_maybe_args(&self.config.host_rustcflags),
2041-
);
2023+
self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags);
20422024
} else {
2043-
self.maybe_add_external_args(
2044-
&mut rustc,
2045-
self.split_maybe_args(&self.config.target_rustcflags),
2046-
);
2025+
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
20472026
if !is_rustdoc {
20482027
if let Some(ref linker) = self.config.linker {
20492028
rustc.arg(format!("-Clinker={}", linker));

0 commit comments

Comments
 (0)