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