CargoCommand can take any package

This commit is contained in:
datdenkikniet 2023-04-16 09:44:30 +02:00
parent 9dc9f49263
commit 404867cdf9
4 changed files with 29 additions and 27 deletions

View file

@ -19,15 +19,17 @@ impl fmt::Display for Package {
} }
impl Package { impl Package {
pub fn name(&self) -> &str { pub fn name(&self) -> String {
match self { let name = match self {
Package::Rtic => "rtic", Package::Rtic => "rtic",
Package::RticCommon => "rtic-common", Package::RticCommon => "rtic-common",
Package::RticMacros => "rtic-macros", Package::RticMacros => "rtic-macros",
Package::RticMonotonics => "rtic-monotonics", Package::RticMonotonics => "rtic-monotonics",
Package::RticSync => "rtic-sync", Package::RticSync => "rtic-sync",
Package::RticTime => "rtic-time", Package::RticTime => "rtic-time",
} };
name.to_string()
} }
pub fn all() -> Vec<Self> { pub fn all() -> Vec<Self> {
@ -102,33 +104,33 @@ impl TestMetadata {
); );
let features = Some(backend.to_target().and_features(&features)); let features = Some(backend.to_target().and_features(&features));
CargoCommand::Test { CargoCommand::Test {
package: Some(package), package: Some(package.name()),
features, features,
test: Some("ui".to_owned()), test: Some("ui".to_owned()),
} }
} }
Package::RticMacros => CargoCommand::Test { Package::RticMacros => CargoCommand::Test {
package: Some(package), package: Some(package.name()),
features: Some(backend.to_rtic_macros_feature().to_owned()), features: Some(backend.to_rtic_macros_feature().to_owned()),
test: None, test: None,
}, },
Package::RticSync => CargoCommand::Test { Package::RticSync => CargoCommand::Test {
package: Some(package), package: Some(package.name()),
features: Some("testing".to_owned()), features: Some("testing".to_owned()),
test: None, test: None,
}, },
Package::RticCommon => CargoCommand::Test { Package::RticCommon => CargoCommand::Test {
package: Some(package), package: Some(package.name()),
features: Some("testing".to_owned()), features: Some("testing".to_owned()),
test: None, test: None,
}, },
Package::RticMonotonics => CargoCommand::Test { Package::RticMonotonics => CargoCommand::Test {
package: Some(package), package: Some(package.name()),
features: None, features: None,
test: None, test: None,
}, },
Package::RticTime => CargoCommand::Test { Package::RticTime => CargoCommand::Test {
package: Some(package), package: Some(package.name()),
features: Some("critical-section/std".into()), features: Some("critical-section/std".into()),
test: None, test: None,
}, },

View file

@ -114,14 +114,14 @@ pub fn cargo<'c>(
let command = match operation { let command = match operation {
BuildOrCheck::Check => CargoCommand::Check { BuildOrCheck::Check => CargoCommand::Check {
cargoarg, cargoarg,
package: Some(package), package: Some(package.name()),
target, target,
features, features,
mode: BuildMode::Release, mode: BuildMode::Release,
}, },
BuildOrCheck::Build => CargoCommand::Build { BuildOrCheck::Build => CargoCommand::Build {
cargoarg, cargoarg,
package: Some(package), package: Some(package.name()),
target, target,
features, features,
mode: BuildMode::Release, mode: BuildMode::Release,
@ -224,7 +224,7 @@ pub fn cargo_clippy<'c>(
globals, globals,
CargoCommand::Clippy { CargoCommand::Clippy {
cargoarg, cargoarg,
package: Some(package), package: Some(package.name()),
target, target,
features, features,
}, },
@ -247,7 +247,7 @@ pub fn cargo_format<'c>(
globals, globals,
CargoCommand::Format { CargoCommand::Format {
cargoarg, cargoarg,
package: Some(p), package: Some(p.name()),
check_only, check_only,
}, },
false, false,

View file

@ -1,8 +1,8 @@
use log::{error, info, Level}; use log::{error, info, Level};
use crate::{ use crate::{
argument_parsing::Globals, cargo_commands::FinalRunResult, ExtraArguments, Package, RunResult, argument_parsing::Globals, cargo_commands::FinalRunResult, ExtraArguments, RunResult, Target,
Target, TestRunError, TestRunError,
}; };
use core::fmt; use core::fmt;
use std::{ use std::{
@ -70,27 +70,27 @@ pub enum CargoCommand<'a> {
}, },
Build { Build {
cargoarg: &'a Option<&'a str>, cargoarg: &'a Option<&'a str>,
package: Option<Package>, package: Option<String>,
target: Target<'a>, target: Target<'a>,
features: Option<String>, features: Option<String>,
mode: BuildMode, mode: BuildMode,
}, },
Check { Check {
cargoarg: &'a Option<&'a str>, cargoarg: &'a Option<&'a str>,
package: Option<Package>, package: Option<String>,
target: Target<'a>, target: Target<'a>,
features: Option<String>, features: Option<String>,
mode: BuildMode, mode: BuildMode,
}, },
Clippy { Clippy {
cargoarg: &'a Option<&'a str>, cargoarg: &'a Option<&'a str>,
package: Option<Package>, package: Option<String>,
target: Target<'a>, target: Target<'a>,
features: Option<String>, features: Option<String>,
}, },
Format { Format {
cargoarg: &'a Option<&'a str>, cargoarg: &'a Option<&'a str>,
package: Option<Package>, package: Option<String>,
check_only: bool, check_only: bool,
}, },
Doc { Doc {
@ -99,7 +99,7 @@ pub enum CargoCommand<'a> {
arguments: Option<ExtraArguments>, arguments: Option<ExtraArguments>,
}, },
Test { Test {
package: Option<Package>, package: Option<String>,
features: Option<String>, features: Option<String>,
test: Option<String>, test: Option<String>,
}, },
@ -127,7 +127,7 @@ pub enum CargoCommand<'a> {
impl core::fmt::Display for CargoCommand<'_> { impl core::fmt::Display for CargoCommand<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let p = |p: &Option<Package>| { let p = |p: &Option<String>| {
if let Some(package) = p { if let Some(package) = p {
format!("package {package}") format!("package {package}")
} else { } else {
@ -468,7 +468,7 @@ impl<'a> CargoCommand<'a> {
args.extend_from_slice(&[self.command(), "--target", target.triple()]); args.extend_from_slice(&[self.command(), "--target", target.triple()]);
if let Some(package) = package { if let Some(package) = package {
args.extend_from_slice(&["--package", package.name()]); args.extend_from_slice(&["--package", package]);
} }
if let Some(feature) = features { if let Some(feature) = features {
@ -493,7 +493,7 @@ impl<'a> CargoCommand<'a> {
args.extend_from_slice(&[self.command()]); args.extend_from_slice(&[self.command()]);
if let Some(package) = package { if let Some(package) = package {
args.extend_from_slice(&["--package", package.name()]); args.extend_from_slice(&["--package", package]);
} }
if let Some(feature) = features { if let Some(feature) = features {
@ -518,7 +518,7 @@ impl<'a> CargoCommand<'a> {
args.extend_from_slice(&[self.command()]); args.extend_from_slice(&[self.command()]);
if let Some(package) = package { if let Some(package) = package {
args.extend_from_slice(&["--package", package.name()]); args.extend_from_slice(&["--package", package]);
} }
if let Some(feature) = features { if let Some(feature) = features {
@ -557,7 +557,7 @@ impl<'a> CargoCommand<'a> {
args.extend_from_slice(&[self.command()]); args.extend_from_slice(&[self.command()]);
if let Some(package) = package { if let Some(package) = package {
args.extend_from_slice(&["--package", package.name()]); args.extend_from_slice(&["--package", package]);
} }
if let Some(feature) = features { if let Some(feature) = features {
@ -594,7 +594,7 @@ impl<'a> CargoCommand<'a> {
} }
if let Some(package) = package { if let Some(package) = package {
args.extend_from_slice(&["--package", package.name()]); args.extend_from_slice(&["--package", package]);
} }
if *check_only { if *check_only {
args.extend_from_slice(&["--check"]); args.extend_from_slice(&["--check"]);

View file

@ -3,7 +3,7 @@ mod build;
mod cargo_commands; mod cargo_commands;
mod command; mod command;
use argument_parsing::{ExtraArguments, Globals, Package}; use argument_parsing::{ExtraArguments, Globals};
use clap::Parser; use clap::Parser;
use command::OutputMode; use command::OutputMode;
use core::fmt; use core::fmt;