Skip to content

Commit 967a531

Browse files
committed
Implement --features for clippy and auto_actions
Also fix not passing features to one of the cargo invocations for test
1 parent dbef80a commit 967a531

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

miri-script/src/commands.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl MiriEnv {
7272
}
7373

7474
impl Command {
75-
fn auto_actions() -> Result<()> {
75+
fn auto_actions(features: Vec<String>) -> Result<()> {
7676
if env::var_os("MIRI_AUTO_OPS").is_some_and(|x| x == "no") {
7777
return Ok(());
7878
}
@@ -91,7 +91,7 @@ impl Command {
9191
Self::fmt(vec![])?;
9292
}
9393
if auto_clippy {
94-
Self::clippy(vec![])?;
94+
Self::clippy(features, vec![])?;
9595
}
9696

9797
Ok(())
@@ -160,14 +160,14 @@ impl Command {
160160
pub fn exec(self) -> Result<()> {
161161
// First, and crucially only once, run the auto-actions -- but not for all commands.
162162
match &self {
163-
Command::Install { .. }
164-
| Command::Build { .. }
165-
| Command::Check { .. }
166-
| Command::Test { .. }
167-
| Command::Run { .. }
168-
| Command::Fmt { .. }
169-
| Command::Doc { .. }
170-
| Command::Clippy { .. } => Self::auto_actions()?,
163+
Command::Install { features, .. }
164+
| Command::Build { features, .. }
165+
| Command::Check { features, .. }
166+
| Command::Test { features, .. }
167+
| Command::Run { features, .. }
168+
| Command::Doc { features, .. }
169+
| Command::Clippy { features, .. } => Self::auto_actions(features.clone())?,
170+
| Command::Fmt { .. } => Self::auto_actions(vec![])?,
171171
| Command::Toolchain { .. }
172172
| Command::Bench { .. }
173173
| Command::RustcPull { .. }
@@ -179,13 +179,13 @@ impl Command {
179179
Command::Install { features, flags } => Self::install(features, flags),
180180
Command::Build { features, flags } => Self::build(features, flags),
181181
Command::Check { features, flags } => Self::check(features, flags),
182-
Command::Test { bless, flags, target, coverage, features } =>
183-
Self::test(bless, flags, target, coverage, features),
182+
Command::Test { bless, target, coverage, features, flags } =>
183+
Self::test(bless, target, coverage, features, flags),
184184
Command::Run { dep, verbose, target, edition, features, flags } =>
185185
Self::run(dep, verbose, target, edition, features, flags),
186186
Command::Doc { features, flags } => Self::doc(features, flags),
187187
Command::Fmt { flags } => Self::fmt(flags),
188-
Command::Clippy { flags } => Self::clippy(flags),
188+
Command::Clippy { features, flags } => Self::clippy(features, flags),
189189
Command::Bench { target, no_install, save_baseline, load_baseline, benches } =>
190190
Self::bench(target, no_install, save_baseline, load_baseline, benches),
191191
Command::Toolchain { flags } => Self::toolchain(flags),
@@ -630,20 +630,20 @@ impl Command {
630630
Ok(())
631631
}
632632

633-
fn clippy(flags: Vec<String>) -> Result<()> {
633+
fn clippy(features: Vec<String>, flags: Vec<String>) -> Result<()> {
634634
let e = MiriEnv::new()?;
635-
e.clippy(".", &flags)?;
636-
e.clippy("cargo-miri", &flags)?;
637-
e.clippy("miri-script", &flags)?;
635+
e.clippy(".", &features, &flags)?;
636+
e.clippy("cargo-miri", &[], &flags)?;
637+
e.clippy("miri-script", &[], &flags)?;
638638
Ok(())
639639
}
640640

641641
fn test(
642642
bless: bool,
643-
mut flags: Vec<String>,
644643
target: Option<String>,
645644
coverage: bool,
646645
features: Vec<String>,
646+
mut flags: Vec<String>,
647647
) -> Result<()> {
648648
let mut e = MiriEnv::new()?;
649649

@@ -674,7 +674,7 @@ impl Command {
674674

675675
// Then test, and let caller control flags.
676676
// Only in root project as `cargo-miri` has no tests.
677-
e.test(".", &flags)?;
677+
e.test(".", &features, &flags)?;
678678

679679
if let Some(coverage) = &coverage {
680680
coverage.show_coverage_report(&e, &features)?;

miri-script/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ pub enum Command {
4444
},
4545
/// Check Miri with Clippy.
4646
Clippy {
47+
/// Pass features to cargo invocations on the "miri" crate in the root. This option does
48+
/// **not** apply to other crates, so e.g. these features won't be used on "cargo-miri".
49+
#[arg(long, value_delimiter = ',', action = clap::ArgAction::Append)]
50+
features: Vec<String>,
4751
/// Flags that are passed through to `cargo clippy`.
4852
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
4953
flags: Vec<String>,
@@ -174,7 +178,7 @@ impl Command {
174178
| Self::Doc { flags, .. }
175179
| Self::Fmt { flags }
176180
| Self::Toolchain { flags }
177-
| Self::Clippy { flags }
181+
| Self::Clippy { flags, .. }
178182
| Self::Run { flags, .. }
179183
| Self::Test { flags, .. } => {
180184
flags.extend(remainder);

miri-script/src/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ impl MiriEnv {
226226
Ok(())
227227
}
228228

229-
pub fn clippy(&self, crate_dir: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
230-
self.cargo_cmd(crate_dir, "clippy", &[]).arg("--all-targets").args(args).run()?;
229+
pub fn clippy(&self, crate_dir: impl AsRef<OsStr>, features: &[String], args: &[String]) -> Result<()> {
230+
self.cargo_cmd(crate_dir, "clippy", features).arg("--all-targets").args(args).run()?;
231231
Ok(())
232232
}
233233

234-
pub fn test(&self, crate_dir: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
235-
self.cargo_cmd(crate_dir, "test", &[]).args(args).run()?;
234+
pub fn test(&self, crate_dir: impl AsRef<OsStr>, features: &[String], args: &[String]) -> Result<()> {
235+
self.cargo_cmd(crate_dir, "test", features).args(args).run()?;
236236
Ok(())
237237
}
238238

0 commit comments

Comments
 (0)