compiletest: refactor rustcflags to Vec

This commit is contained in:
Andrew Pollack 2022-10-03 19:36:27 +00:00
parent 2f172b4f0b
commit 47703d3f3d
4 changed files with 22 additions and 39 deletions

View File

@ -1386,7 +1386,7 @@ fn run(self, builder: &Builder<'_>) {
}
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
flags.push(builder.config.cmd.rustc_args().join(" "));
flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
if let Some(linker) = builder.linker(target) {
cmd.arg("--linker").arg(linker);
@ -1395,12 +1395,16 @@ fn run(self, builder: &Builder<'_>) {
let mut hostflags = flags.clone();
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
hostflags.extend(builder.lld_flags(compiler.host));
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
for flag in hostflags {
cmd.arg("--host-rustcflags").arg(flag);
}
let mut targetflags = flags;
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
targetflags.extend(builder.lld_flags(target));
cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
for flag in targetflags {
cmd.arg("--target-rustcflags").arg(flag);
}
cmd.arg("--python").arg(builder.python());

View File

@ -269,10 +269,10 @@ pub struct Config {
pub runtool: Option<String>,
/// Flags to pass to the compiler when building for the host
pub host_rustcflags: Option<String>,
pub host_rustcflags: Vec<String>,
/// Flags to pass to the compiler when building for the target
pub target_rustcflags: Option<String>,
pub target_rustcflags: Vec<String>,
/// Whether tests should be optimized by default. Individual test-suites and test files may
/// override this setting.
@ -457,12 +457,12 @@ pub enum Endian {
}
impl TargetCfg {
fn new(rustc_path: &Path, target: &str, target_rustcflags: &Option<String>) -> TargetCfg {
fn new(rustc_path: &Path, target: &str, target_rustcflags: &Vec<String>) -> TargetCfg {
let output = match Command::new(rustc_path)
.arg("--print=cfg")
.arg("--target")
.arg(target)
.args(target_rustcflags.into_iter().map(|s| s.split_whitespace()).flatten())
.args(target_rustcflags)
.output()
{
Ok(output) => output,

View File

@ -252,8 +252,8 @@ fn make_absolute(path: PathBuf) -> PathBuf {
}),
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
runtool: matches.opt_str("runtool"),
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
host_rustcflags: matches.opt_strs("host-rustcflags"),
target_rustcflags: matches.opt_strs("target-rustcflags"),
optimize_tests: matches.opt_present("optimize-tests"),
target,
host: opt_str2(matches.opt_str("host")),
@ -320,8 +320,8 @@ pub fn log_config(config: &Config) {
format!("force_pass_mode: {}", opt_str(&config.force_pass_mode.map(|m| format!("{}", m))),),
);
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
logv(c, format!("host-rustcflags: {:?}", config.host_rustcflags));
logv(c, format!("target-rustcflags: {:?}", config.target_rustcflags));
logv(c, format!("target: {}", config.target));
logv(c, format!("host: {}", config.host));
logv(c, format!("android-cross-path: {:?}", config.android_cross_path.display()));

View File

@ -558,10 +558,7 @@ fn print_source(&self, read_from: ReadFrom, pretty_type: &str) -> ProcRes {
.arg(&aux_dir)
.args(&self.props.compile_flags)
.envs(self.props.rustc_env.clone());
self.maybe_add_external_args(
&mut rustc,
self.split_maybe_args(&self.config.target_rustcflags),
);
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
let src = match read_from {
ReadFrom::Stdin(src) => Some(src),
@ -629,10 +626,7 @@ fn typecheck_source(&self, src: String) -> ProcRes {
.arg("-L")
.arg(aux_dir);
self.set_revision_flags(&mut rustc);
self.maybe_add_external_args(
&mut rustc,
self.split_maybe_args(&self.config.target_rustcflags),
);
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
rustc.args(&self.props.compile_flags);
self.compose_and_run_compiler(rustc, Some(src))
@ -1186,23 +1180,14 @@ fn cmd2procres(&self, cmd: &mut Command) -> ProcRes {
ProcRes { status, stdout: out, stderr: err, cmdline: format!("{:?}", cmd) }
}
fn cleanup_debug_info_options(&self, options: &Option<String>) -> Option<String> {
if options.is_none() {
return None;
}
fn cleanup_debug_info_options(&self, options: &Vec<String>) -> Vec<String> {
// Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
let options_to_remove = ["-O".to_owned(), "-g".to_owned(), "--debuginfo".to_owned()];
let new_options = self
.split_maybe_args(options)
.into_iter()
.filter(|x| !options_to_remove.contains(x))
.collect::<Vec<String>>();
Some(new_options.join(" "))
options.to_vec().into_iter().filter(|x| !options_to_remove.contains(x)).collect()
}
fn maybe_add_external_args(&self, cmd: &mut Command, args: Vec<String>) {
fn maybe_add_external_args(&self, cmd: &mut Command, args: &Vec<String>) {
// Filter out the arguments that should not be added by runtest here.
//
// Notable use-cases are: do not add our optimisation flag if
@ -2035,15 +2020,9 @@ fn make_compile_args(
}
if self.props.force_host {
self.maybe_add_external_args(
&mut rustc,
self.split_maybe_args(&self.config.host_rustcflags),
);
self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags);
} else {
self.maybe_add_external_args(
&mut rustc,
self.split_maybe_args(&self.config.target_rustcflags),
);
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
if !is_rustdoc {
if let Some(ref linker) = self.config.linker {
rustc.arg(format!("-Clinker={}", linker));