Skip to content

Commit 73e7c3a

Browse files
Rollup merge of #102634 - andrewpollack:refactor-test-rustcflags, r=Mark-Simulacrum
compiletest: Refactor test rustcflags Refactoring `host-rustcflags` and `target-rustcflags` from `Option<String>` to `Vec<String>` Ref: #102438 r? `@Mark-Simulacrum`
2 parents 33b530e + f01608c commit 73e7c3a

File tree

4 files changed

+22
-39
lines changed

4 files changed

+22
-39
lines changed

src/bootstrap/test.rs

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

14231423
if let Some(linker) = builder.linker(target) {
14241424
cmd.arg("--linker").arg(linker);
@@ -1427,12 +1427,16 @@ note: if you're sure you want to do this, please open an issue as to why. In the
14271427
let mut hostflags = flags.clone();
14281428
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
14291429
hostflags.extend(builder.lld_flags(compiler.host));
1430-
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1430+
for flag in hostflags {
1431+
cmd.arg("--host-rustcflags").arg(flag);
1432+
}
14311433

14321434
let mut targetflags = flags;
14331435
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
14341436
targetflags.extend(builder.lld_flags(target));
1435-
cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1437+
for flag in targetflags {
1438+
cmd.arg("--target-rustcflags").arg(flag);
1439+
}
14361440

14371441
cmd.arg("--python").arg(builder.python());
14381442

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,

src/tools/compiletest/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
254254
}),
255255
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
256256
runtool: matches.opt_str("runtool"),
257-
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
258-
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
257+
host_rustcflags: matches.opt_strs("host-rustcflags"),
258+
target_rustcflags: matches.opt_strs("target-rustcflags"),
259259
optimize_tests: matches.opt_present("optimize-tests"),
260260
target,
261261
host: opt_str2(matches.opt_str("host")),
@@ -322,8 +322,8 @@ pub fn log_config(config: &Config) {
322322
format!("force_pass_mode: {}", opt_str(&config.force_pass_mode.map(|m| format!("{}", m))),),
323323
);
324324
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
325-
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
326-
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
325+
logv(c, format!("host-rustcflags: {:?}", config.host_rustcflags));
326+
logv(c, format!("target-rustcflags: {:?}", config.target_rustcflags));
327327
logv(c, format!("target: {}", config.target));
328328
logv(c, format!("host: {}", config.host));
329329
logv(c, format!("android-cross-path: {:?}", config.android_cross_path.display()));

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.iter().filter(|x| !options_to_remove.contains(x)).map(|x| x.clone()).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)