Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiletest: Refactor test rustcflags #102634

Merged
merged 2 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
}
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);
andrewpollack marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -1395,12 +1395,16 @@ note: if you're sure you want to do this, please open an issue as to why. In the
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());

Expand Down
8 changes: 4 additions & 4 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
}),
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")),
Expand Down Expand Up @@ -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()));
Expand Down
35 changes: 7 additions & 28 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,7 @@ impl<'test> TestCx<'test> {
.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),
Expand Down Expand Up @@ -629,10 +626,7 @@ impl<'test> TestCx<'test> {
.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))
Expand Down Expand Up @@ -1186,23 +1180,14 @@ impl<'test> TestCx<'test> {
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.iter().filter(|x| !options_to_remove.contains(x)).map(|x| x.clone()).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
Expand Down Expand Up @@ -2035,15 +2020,9 @@ impl<'test> TestCx<'test> {
}

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));
Expand Down