Skip to content

Commit 92123eb

Browse files
committed
Make build_command a method
1 parent d747924 commit 92123eb

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

src/lib.rs

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn test_command(mut config: Config, path: &Path) -> Result<Command> {
164164
comments: &comments,
165165
path,
166166
};
167-
let mut result = build_command(&config).unwrap();
167+
let mut result = config.build_command().unwrap();
168168
result.args(extra_args);
169169

170170
Ok(result)
@@ -431,52 +431,6 @@ fn parse_and_test_file(
431431
.collect())
432432
}
433433

434-
fn build_command(config: &TestConfig) -> Result<Command, Errored> {
435-
let TestConfig {
436-
config,
437-
revision,
438-
comments,
439-
path,
440-
} = config;
441-
let mut cmd = config.program.build(&config.out_dir);
442-
cmd.arg(path);
443-
if !revision.is_empty() {
444-
cmd.arg(format!("--cfg={revision}"));
445-
}
446-
for arg in comments
447-
.for_revision(revision)
448-
.flat_map(|r| r.compile_flags.iter())
449-
{
450-
cmd.arg(arg);
451-
}
452-
let edition = comments.edition(revision)?;
453-
454-
if let Some(edition) = edition {
455-
cmd.arg("--edition").arg(&*edition);
456-
}
457-
458-
if let Some(target) = &config.target {
459-
// Adding a `--target` arg to calls to Cargo will cause target folders
460-
// to create a target-specific sub-folder. We can avoid that by just
461-
// not passing a `--target` arg if its the same as the host.
462-
if !config.host_matches(target) {
463-
cmd.arg("--target").arg(target);
464-
}
465-
}
466-
467-
// False positive in miri, our `map` uses a ref pattern to get the references to the tuple fields instead
468-
// of a reference to a tuple
469-
#[allow(clippy::map_identity)]
470-
cmd.envs(
471-
comments
472-
.for_revision(revision)
473-
.flat_map(|r| r.env_vars.iter())
474-
.map(|(k, v)| (k, v)),
475-
);
476-
477-
Ok(cmd)
478-
}
479-
480434
fn build_aux(
481435
aux_file: &Path,
482436
config: &Config,
@@ -534,7 +488,7 @@ fn build_aux(
534488

535489
config.patch_out_dir();
536490

537-
let mut aux_cmd = build_command(&config)?;
491+
let mut aux_cmd = config.build_command()?;
538492

539493
let mut extra_args = build_aux_files(
540494
aux_file.parent().unwrap(),
@@ -594,7 +548,7 @@ fn run_test(build_manager: &BuildManager<'_>, mut config: TestConfig<'_>) -> Tes
594548

595549
config.patch_out_dir();
596550

597-
let mut cmd = build_command(&config)?;
551+
let mut cmd = config.build_command()?;
598552
cmd.args(&extra_args);
599553
let stdin = config.path.with_extension(config.extension("stdin"));
600554
if stdin.exists() {
@@ -871,7 +825,7 @@ fn run_rustfix(
871825
return Ok(());
872826
}
873827

874-
let mut cmd = build_command(&config)?;
828+
let mut cmd = config.build_command()?;
875829
cmd.args(extra_args);
876830
cmd.arg("--crate-name").arg(crate_name);
877831
let output = cmd.output().unwrap();

src/per_test_config.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! some boolean settings have no way to disable them.
55
66
use std::path::Path;
7+
use std::process::Command;
78

89
use spanned::Spanned;
910

@@ -62,4 +63,50 @@ impl TestConfig<'_> {
6263
.flat_map(f)
6364
.collect()
6465
}
66+
67+
pub fn build_command(&self) -> Result<Command, Errored> {
68+
let TestConfig {
69+
config,
70+
revision,
71+
comments,
72+
path,
73+
} = self;
74+
let mut cmd = config.program.build(&config.out_dir);
75+
cmd.arg(path);
76+
if !revision.is_empty() {
77+
cmd.arg(format!("--cfg={revision}"));
78+
}
79+
for arg in comments
80+
.for_revision(revision)
81+
.flat_map(|r| r.compile_flags.iter())
82+
{
83+
cmd.arg(arg);
84+
}
85+
let edition = comments.edition(revision)?;
86+
87+
if let Some(edition) = edition {
88+
cmd.arg("--edition").arg(&*edition);
89+
}
90+
91+
if let Some(target) = &config.target {
92+
// Adding a `--target` arg to calls to Cargo will cause target folders
93+
// to create a target-specific sub-folder. We can avoid that by just
94+
// not passing a `--target` arg if its the same as the host.
95+
if !config.host_matches(target) {
96+
cmd.arg("--target").arg(target);
97+
}
98+
}
99+
100+
// False positive in miri, our `map` uses a ref pattern to get the references to the tuple fields instead
101+
// of a reference to a tuple
102+
#[allow(clippy::map_identity)]
103+
cmd.envs(
104+
comments
105+
.for_revision(revision)
106+
.flat_map(|r| r.env_vars.iter())
107+
.map(|(k, v)| (k, v)),
108+
);
109+
110+
Ok(cmd)
111+
}
65112
}

0 commit comments

Comments
 (0)