mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
xtask: don't add default arguments if building for a no_std target
This commit is contained in:
parent
18522122f1
commit
4adae80f2d
4 changed files with 118 additions and 75 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::{command::CargoCommand, ARMV6M, ARMV7M, ARMV8MBASE, ARMV8MMAIN, DEFAULT_FEATURES};
|
||||
use crate::{command::CargoCommand, Target, ARMV6M, ARMV7M, ARMV8MBASE, ARMV8MMAIN};
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use core::fmt;
|
||||
|
||||
|
@ -37,12 +37,12 @@ impl TestMetadata {
|
|||
pub fn match_package(package: Package, backend: Backends) -> CargoCommand<'static> {
|
||||
match package {
|
||||
Package::Rtic => {
|
||||
let features = Some(format!(
|
||||
"{},{},{}",
|
||||
DEFAULT_FEATURES,
|
||||
let features = format!(
|
||||
"{},{}",
|
||||
backend.to_rtic_feature(),
|
||||
backend.to_rtic_uitest_feature(),
|
||||
));
|
||||
backend.to_rtic_uitest_feature()
|
||||
);
|
||||
let features = Some(backend.to_target().and_features(&features));
|
||||
CargoCommand::Test {
|
||||
package: Some(package),
|
||||
features,
|
||||
|
@ -89,7 +89,7 @@ pub enum Backends {
|
|||
|
||||
impl Backends {
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn to_target(&self) -> &str {
|
||||
pub fn to_target(&self) -> Target {
|
||||
match self {
|
||||
Backends::Thumbv6 => ARMV6M,
|
||||
Backends::Thumbv7 => ARMV7M,
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
|||
Backends, BuildOrCheck, ExtraArguments, Globals, Package, PackageOpt, TestMetadata,
|
||||
},
|
||||
command::{BuildMode, CargoCommand},
|
||||
command_parser, package_feature_extractor, DEFAULT_FEATURES,
|
||||
command_parser, package_feature_extractor,
|
||||
};
|
||||
use log::error;
|
||||
use rayon::prelude::*;
|
||||
|
@ -16,20 +16,21 @@ pub fn cargo(
|
|||
package: &PackageOpt,
|
||||
backend: Backends,
|
||||
) -> anyhow::Result<()> {
|
||||
let features = package_feature_extractor(package, backend);
|
||||
let target = backend.to_target();
|
||||
let features = package_feature_extractor(target, package, backend);
|
||||
|
||||
let command = match operation {
|
||||
BuildOrCheck::Check => CargoCommand::Check {
|
||||
cargoarg,
|
||||
package: package.package,
|
||||
target: backend.to_target(),
|
||||
target,
|
||||
features,
|
||||
mode: BuildMode::Release,
|
||||
},
|
||||
BuildOrCheck::Build => CargoCommand::Build {
|
||||
cargoarg,
|
||||
package: package.package,
|
||||
target: backend.to_target(),
|
||||
target,
|
||||
features,
|
||||
mode: BuildMode::Release,
|
||||
},
|
||||
|
@ -49,11 +50,7 @@ pub fn cargo_example(
|
|||
examples: &[String],
|
||||
) -> anyhow::Result<()> {
|
||||
examples.into_par_iter().for_each(|example| {
|
||||
let features = Some(format!(
|
||||
"{},{}",
|
||||
DEFAULT_FEATURES,
|
||||
backend.to_rtic_feature()
|
||||
));
|
||||
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
||||
|
||||
let command = match operation {
|
||||
BuildOrCheck::Check => CargoCommand::ExampleCheck {
|
||||
|
@ -87,13 +84,14 @@ pub fn cargo_clippy(
|
|||
package: &PackageOpt,
|
||||
backend: Backends,
|
||||
) -> anyhow::Result<()> {
|
||||
let features = package_feature_extractor(package, backend);
|
||||
let target = backend.to_target();
|
||||
let features = package_feature_extractor(target, package, backend);
|
||||
command_parser(
|
||||
globals,
|
||||
&CargoCommand::Clippy {
|
||||
cargoarg,
|
||||
package: package.package,
|
||||
target: backend.to_target(),
|
||||
target,
|
||||
features,
|
||||
},
|
||||
false,
|
||||
|
@ -127,11 +125,7 @@ pub fn cargo_doc(
|
|||
backend: Backends,
|
||||
arguments: &Option<ExtraArguments>,
|
||||
) -> anyhow::Result<()> {
|
||||
let features = Some(format!(
|
||||
"{},{}",
|
||||
DEFAULT_FEATURES,
|
||||
backend.to_rtic_feature()
|
||||
));
|
||||
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
||||
|
||||
command_parser(
|
||||
globals,
|
||||
|
@ -145,7 +139,7 @@ pub fn cargo_doc(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Run cargo test on the selcted package or all packages
|
||||
/// Run cargo test on the selected package or all packages
|
||||
///
|
||||
/// If no package is specified, loop through all packages
|
||||
pub fn cargo_test(
|
||||
|
@ -204,16 +198,15 @@ pub fn run_test(
|
|||
examples: &[String],
|
||||
overwrite: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let target = backend.to_target();
|
||||
let features = Some(target.and_features(backend.to_rtic_feature()));
|
||||
|
||||
examples.into_par_iter().for_each(|example| {
|
||||
let cmd = CargoCommand::ExampleBuild {
|
||||
cargoarg: &Some("--quiet"),
|
||||
example,
|
||||
target: backend.to_target(),
|
||||
features: Some(format!(
|
||||
"{},{}",
|
||||
DEFAULT_FEATURES,
|
||||
backend.to_rtic_feature()
|
||||
)),
|
||||
target,
|
||||
features: features.clone(),
|
||||
mode: BuildMode::Release,
|
||||
};
|
||||
if let Err(err) = command_parser(globals, &cmd, false) {
|
||||
|
@ -223,12 +216,8 @@ pub fn run_test(
|
|||
let cmd = CargoCommand::Qemu {
|
||||
cargoarg,
|
||||
example,
|
||||
target: backend.to_target(),
|
||||
features: Some(format!(
|
||||
"{},{}",
|
||||
DEFAULT_FEATURES,
|
||||
backend.to_rtic_feature()
|
||||
)),
|
||||
target,
|
||||
features: features.clone(),
|
||||
mode: BuildMode::Release,
|
||||
};
|
||||
|
||||
|
@ -248,17 +237,16 @@ pub fn build_and_check_size(
|
|||
examples: &[String],
|
||||
arguments: &Option<ExtraArguments>,
|
||||
) -> anyhow::Result<()> {
|
||||
let target = backend.to_target();
|
||||
let features = Some(target.and_features(backend.to_rtic_feature()));
|
||||
|
||||
examples.into_par_iter().for_each(|example| {
|
||||
// Make sure the requested example(s) are built
|
||||
let cmd = CargoCommand::ExampleBuild {
|
||||
cargoarg: &Some("--quiet"),
|
||||
example,
|
||||
target: backend.to_target(),
|
||||
features: Some(format!(
|
||||
"{},{}",
|
||||
DEFAULT_FEATURES,
|
||||
backend.to_rtic_feature()
|
||||
)),
|
||||
target,
|
||||
features: features.clone(),
|
||||
mode: BuildMode::Release,
|
||||
};
|
||||
if let Err(err) = command_parser(globals, &cmd, false) {
|
||||
|
@ -269,11 +257,7 @@ pub fn build_and_check_size(
|
|||
cargoarg,
|
||||
example,
|
||||
target: backend.to_target(),
|
||||
features: Some(format!(
|
||||
"{},{}",
|
||||
DEFAULT_FEATURES,
|
||||
backend.to_rtic_feature()
|
||||
)),
|
||||
features: features.clone(),
|
||||
mode: BuildMode::Release,
|
||||
arguments: arguments.clone(),
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{debug, ExtraArguments, Package, RunResult, TestRunError};
|
||||
use crate::{debug, ExtraArguments, Package, RunResult, Target, TestRunError};
|
||||
use core::fmt;
|
||||
use std::{
|
||||
fs::File,
|
||||
|
@ -35,49 +35,49 @@ pub enum CargoCommand<'a> {
|
|||
Run {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
example: &'a str,
|
||||
target: &'a str,
|
||||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
},
|
||||
Qemu {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
example: &'a str,
|
||||
target: &'a str,
|
||||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
},
|
||||
ExampleBuild {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
example: &'a str,
|
||||
target: &'a str,
|
||||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
},
|
||||
ExampleCheck {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
example: &'a str,
|
||||
target: &'a str,
|
||||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
},
|
||||
Build {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
package: Option<Package>,
|
||||
target: &'a str,
|
||||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
},
|
||||
Check {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
package: Option<Package>,
|
||||
target: &'a str,
|
||||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
},
|
||||
Clippy {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
package: Option<Package>,
|
||||
target: &'a str,
|
||||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
},
|
||||
Format {
|
||||
|
@ -101,7 +101,7 @@ pub enum CargoCommand<'a> {
|
|||
ExampleSize {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
example: &'a str,
|
||||
target: &'a str,
|
||||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
arguments: Option<ExtraArguments>,
|
||||
|
@ -153,7 +153,13 @@ impl<'a> CargoCommand<'a> {
|
|||
if let Some(cargoarg) = cargoarg {
|
||||
args.extend_from_slice(&[cargoarg]);
|
||||
}
|
||||
args.extend_from_slice(&[self.command(), "--example", example, "--target", target]);
|
||||
args.extend_from_slice(&[
|
||||
self.command(),
|
||||
"--example",
|
||||
example,
|
||||
"--target",
|
||||
target.triple(),
|
||||
]);
|
||||
|
||||
if let Some(feature) = features {
|
||||
args.extend_from_slice(&["--features", feature]);
|
||||
|
@ -174,7 +180,13 @@ impl<'a> CargoCommand<'a> {
|
|||
if let Some(cargoarg) = cargoarg {
|
||||
args.extend_from_slice(&[cargoarg]);
|
||||
}
|
||||
args.extend_from_slice(&[self.command(), "--example", example, "--target", target]);
|
||||
args.extend_from_slice(&[
|
||||
self.command(),
|
||||
"--example",
|
||||
example,
|
||||
"--target",
|
||||
target.triple(),
|
||||
]);
|
||||
|
||||
if let Some(feature) = features {
|
||||
args.extend_from_slice(&["--features", feature]);
|
||||
|
@ -196,7 +208,7 @@ impl<'a> CargoCommand<'a> {
|
|||
args.extend_from_slice(&[cargoarg]);
|
||||
}
|
||||
|
||||
args.extend_from_slice(&[self.command(), "--target", target]);
|
||||
args.extend_from_slice(&[self.command(), "--target", target.triple()]);
|
||||
|
||||
if let Some(package) = package {
|
||||
args.extend_from_slice(&["--package", package.name()]);
|
||||
|
@ -344,7 +356,13 @@ impl<'a> CargoCommand<'a> {
|
|||
if let Some(cargoarg) = cargoarg {
|
||||
args.extend_from_slice(&[cargoarg]);
|
||||
}
|
||||
args.extend_from_slice(&[self.command(), "--example", example, "--target", target]);
|
||||
args.extend_from_slice(&[
|
||||
self.command(),
|
||||
"--example",
|
||||
example,
|
||||
"--target",
|
||||
target.triple(),
|
||||
]);
|
||||
|
||||
if let Some(feature) = features {
|
||||
args.extend_from_slice(&["--features", feature]);
|
||||
|
@ -365,7 +383,13 @@ impl<'a> CargoCommand<'a> {
|
|||
if let Some(cargoarg) = cargoarg {
|
||||
args.extend_from_slice(&[cargoarg]);
|
||||
}
|
||||
args.extend_from_slice(&[self.command(), "--example", example, "--target", target]);
|
||||
args.extend_from_slice(&[
|
||||
self.command(),
|
||||
"--example",
|
||||
example,
|
||||
"--target",
|
||||
target.triple(),
|
||||
]);
|
||||
|
||||
if let Some(feature) = features {
|
||||
args.extend_from_slice(&["--features", feature]);
|
||||
|
@ -387,7 +411,13 @@ impl<'a> CargoCommand<'a> {
|
|||
if let Some(cargoarg) = cargoarg {
|
||||
args.extend_from_slice(&[cargoarg]);
|
||||
}
|
||||
args.extend_from_slice(&[self.command(), "--example", example, "--target", target]);
|
||||
args.extend_from_slice(&[
|
||||
self.command(),
|
||||
"--example",
|
||||
example,
|
||||
"--target",
|
||||
target.triple(),
|
||||
]);
|
||||
|
||||
if let Some(feature_name) = features {
|
||||
args.extend_from_slice(&["--features", feature_name]);
|
||||
|
|
|
@ -33,14 +33,42 @@ use crate::{
|
|||
command::{run_command, run_successful, CargoCommand},
|
||||
};
|
||||
|
||||
// x86_64-unknown-linux-gnu
|
||||
const _X86_64: &str = "x86_64-unknown-linux-gnu";
|
||||
const ARMV6M: &str = "thumbv6m-none-eabi";
|
||||
const ARMV7M: &str = "thumbv7m-none-eabi";
|
||||
const ARMV8MBASE: &str = "thumbv8m.base-none-eabi";
|
||||
const ARMV8MMAIN: &str = "thumbv8m.main-none-eabi";
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Target<'a> {
|
||||
triple: &'a str,
|
||||
has_std: bool,
|
||||
}
|
||||
|
||||
const DEFAULT_FEATURES: &str = "test-critical-section";
|
||||
impl<'a> Target<'a> {
|
||||
const STD_FEATURES: &str = "test-critical-section";
|
||||
|
||||
pub const fn new(triple: &'a str, has_std: bool) -> Self {
|
||||
Self { triple, has_std }
|
||||
}
|
||||
|
||||
pub fn triple(&self) -> &str {
|
||||
self.triple
|
||||
}
|
||||
|
||||
pub fn has_std(&self) -> bool {
|
||||
self.has_std
|
||||
}
|
||||
|
||||
pub fn and_features(&self, features: &str) -> String {
|
||||
if self.has_std {
|
||||
format!("{},{}", Self::STD_FEATURES, features)
|
||||
} else {
|
||||
features.to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// x86_64-unknown-linux-gnu
|
||||
const _X86_64: Target = Target::new("x86_64-unknown-linux-gnu", true);
|
||||
const ARMV6M: Target = Target::new("thumbv6m-none-eabi", false);
|
||||
const ARMV7M: Target = Target::new("thumbv7m-none-eabi", false);
|
||||
const ARMV8MBASE: Target = Target::new("thumbv8m.base-none-eabi", false);
|
||||
const ARMV8MMAIN: Target = Target::new("thumbv8m.main-none-eabi", false);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RunResult {
|
||||
|
@ -276,12 +304,13 @@ fn main() -> anyhow::Result<()> {
|
|||
/// Without package specified the features for RTIC are required
|
||||
/// With only a single package which is not RTIC, no special
|
||||
/// features are needed
|
||||
fn package_feature_extractor(package: &PackageOpt, backend: Backends) -> Option<String> {
|
||||
let default_features = Some(format!(
|
||||
"{},{}",
|
||||
DEFAULT_FEATURES,
|
||||
backend.to_rtic_feature()
|
||||
));
|
||||
fn package_feature_extractor(
|
||||
target: Target,
|
||||
package: &PackageOpt,
|
||||
backend: Backends,
|
||||
) -> Option<String> {
|
||||
let default_features = Some(target.and_features(backend.to_rtic_feature()));
|
||||
|
||||
if let Some(package) = package.package {
|
||||
debug!("\nTesting package: {package}");
|
||||
match package {
|
||||
|
|
Loading…
Reference in a new issue