2023-03-01 00:25:05 +01:00
|
|
|
use crate::{
|
2023-04-15 00:26:16 +02:00
|
|
|
argument_parsing::{
|
|
|
|
Backends, BuildOrCheck, ExtraArguments, Globals, Package, PackageOpt, TestMetadata,
|
|
|
|
},
|
2023-03-01 00:25:05 +01:00
|
|
|
command::{BuildMode, CargoCommand},
|
2023-04-15 00:50:46 +02:00
|
|
|
command_parser, package_feature_extractor,
|
2023-03-01 00:25:05 +01:00
|
|
|
};
|
|
|
|
use log::error;
|
|
|
|
use rayon::prelude::*;
|
|
|
|
|
|
|
|
/// Cargo command to either build or check
|
|
|
|
pub fn cargo(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals: &Globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
operation: BuildOrCheck,
|
|
|
|
cargoarg: &Option<&str>,
|
|
|
|
package: &PackageOpt,
|
|
|
|
backend: Backends,
|
|
|
|
) -> anyhow::Result<()> {
|
2023-04-15 00:50:46 +02:00
|
|
|
let target = backend.to_target();
|
|
|
|
let features = package_feature_extractor(target, package, backend);
|
2023-03-01 00:25:05 +01:00
|
|
|
|
|
|
|
let command = match operation {
|
|
|
|
BuildOrCheck::Check => CargoCommand::Check {
|
|
|
|
cargoarg,
|
|
|
|
package: package.package,
|
2023-04-15 00:50:46 +02:00
|
|
|
target,
|
2023-03-01 00:25:05 +01:00
|
|
|
features,
|
|
|
|
mode: BuildMode::Release,
|
|
|
|
},
|
|
|
|
BuildOrCheck::Build => CargoCommand::Build {
|
|
|
|
cargoarg,
|
|
|
|
package: package.package,
|
2023-04-15 00:50:46 +02:00
|
|
|
target,
|
2023-03-01 00:25:05 +01:00
|
|
|
features,
|
|
|
|
mode: BuildMode::Release,
|
|
|
|
},
|
|
|
|
};
|
2023-04-15 00:26:16 +02:00
|
|
|
command_parser(globals, &command, false)?;
|
2023-03-01 00:25:05 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Cargo command to either build or check all examples
|
|
|
|
///
|
|
|
|
/// The examples are in rtic/examples
|
|
|
|
pub fn cargo_example(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals: &Globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
operation: BuildOrCheck,
|
|
|
|
cargoarg: &Option<&str>,
|
|
|
|
backend: Backends,
|
|
|
|
examples: &[String],
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
examples.into_par_iter().for_each(|example| {
|
2023-04-15 00:50:46 +02:00
|
|
|
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
2023-03-01 00:25:05 +01:00
|
|
|
|
|
|
|
let command = match operation {
|
|
|
|
BuildOrCheck::Check => CargoCommand::ExampleCheck {
|
|
|
|
cargoarg,
|
|
|
|
example,
|
|
|
|
target: backend.to_target(),
|
|
|
|
features,
|
|
|
|
mode: BuildMode::Release,
|
|
|
|
},
|
|
|
|
BuildOrCheck::Build => CargoCommand::ExampleBuild {
|
|
|
|
cargoarg,
|
|
|
|
example,
|
|
|
|
target: backend.to_target(),
|
|
|
|
features,
|
|
|
|
mode: BuildMode::Release,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-04-15 00:26:16 +02:00
|
|
|
if let Err(err) = command_parser(globals, &command, false) {
|
2023-03-01 00:25:05 +01:00
|
|
|
error!("{err}");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Run cargo clippy on selected package
|
|
|
|
pub fn cargo_clippy(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals: &Globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
cargoarg: &Option<&str>,
|
|
|
|
package: &PackageOpt,
|
|
|
|
backend: Backends,
|
|
|
|
) -> anyhow::Result<()> {
|
2023-04-15 00:50:46 +02:00
|
|
|
let target = backend.to_target();
|
|
|
|
let features = package_feature_extractor(target, package, backend);
|
2023-03-01 00:25:05 +01:00
|
|
|
command_parser(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
&CargoCommand::Clippy {
|
|
|
|
cargoarg,
|
|
|
|
package: package.package,
|
2023-04-15 00:50:46 +02:00
|
|
|
target,
|
2023-03-01 00:25:05 +01:00
|
|
|
features,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Run cargo fmt on selected package
|
|
|
|
pub fn cargo_format(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals: &Globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
cargoarg: &Option<&str>,
|
|
|
|
package: &PackageOpt,
|
|
|
|
check_only: bool,
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
command_parser(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
&CargoCommand::Format {
|
|
|
|
cargoarg,
|
|
|
|
package: package.package,
|
|
|
|
check_only,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Run cargo doc
|
2023-03-02 22:02:19 +01:00
|
|
|
pub fn cargo_doc(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals: &Globals,
|
2023-03-02 22:02:19 +01:00
|
|
|
cargoarg: &Option<&str>,
|
|
|
|
backend: Backends,
|
|
|
|
arguments: &Option<ExtraArguments>,
|
|
|
|
) -> anyhow::Result<()> {
|
2023-04-15 00:50:46 +02:00
|
|
|
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
2023-03-01 00:25:05 +01:00
|
|
|
|
2023-03-02 22:02:19 +01:00
|
|
|
command_parser(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals,
|
2023-03-02 22:02:19 +01:00
|
|
|
&CargoCommand::Doc {
|
|
|
|
cargoarg,
|
|
|
|
features,
|
|
|
|
arguments: arguments.clone(),
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
)?;
|
2023-03-01 00:25:05 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:50:46 +02:00
|
|
|
/// Run cargo test on the selected package or all packages
|
2023-03-01 00:25:05 +01:00
|
|
|
///
|
|
|
|
/// If no package is specified, loop through all packages
|
2023-04-15 00:26:16 +02:00
|
|
|
pub fn cargo_test(
|
|
|
|
globals: &Globals,
|
|
|
|
package: &PackageOpt,
|
|
|
|
backend: Backends,
|
|
|
|
) -> anyhow::Result<()> {
|
2023-03-01 00:25:05 +01:00
|
|
|
if let Some(package) = package.package {
|
2023-03-02 19:40:50 +01:00
|
|
|
let cmd = TestMetadata::match_package(package, backend);
|
2023-04-15 00:26:16 +02:00
|
|
|
command_parser(globals, &cmd, false)?;
|
2023-03-01 00:25:05 +01:00
|
|
|
} else {
|
|
|
|
// Iterate over all workspace packages
|
|
|
|
for package in [
|
|
|
|
Package::Rtic,
|
|
|
|
Package::RticCommon,
|
|
|
|
Package::RticMacros,
|
|
|
|
Package::RticMonotonics,
|
2023-03-02 19:40:50 +01:00
|
|
|
Package::RticSync,
|
2023-03-01 00:25:05 +01:00
|
|
|
Package::RticTime,
|
|
|
|
] {
|
|
|
|
let mut error_messages = vec![];
|
|
|
|
let cmd = &TestMetadata::match_package(package, backend);
|
2023-04-15 00:26:16 +02:00
|
|
|
if let Err(err) = command_parser(globals, cmd, false) {
|
2023-03-01 00:25:05 +01:00
|
|
|
error_messages.push(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if !error_messages.is_empty() {
|
|
|
|
for err in error_messages {
|
|
|
|
error!("{err}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Use mdbook to build the book
|
2023-04-15 00:26:16 +02:00
|
|
|
pub fn cargo_book(globals: &Globals, arguments: &Option<ExtraArguments>) -> anyhow::Result<()> {
|
2023-03-01 00:25:05 +01:00
|
|
|
command_parser(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
&CargoCommand::Book {
|
2023-03-02 22:02:19 +01:00
|
|
|
arguments: arguments.clone(),
|
2023-03-01 00:25:05 +01:00
|
|
|
},
|
|
|
|
false,
|
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Run examples
|
|
|
|
///
|
|
|
|
/// Supports updating the expected output via the overwrite argument
|
|
|
|
pub fn run_test(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals: &Globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
cargoarg: &Option<&str>,
|
|
|
|
backend: Backends,
|
|
|
|
examples: &[String],
|
|
|
|
overwrite: bool,
|
|
|
|
) -> anyhow::Result<()> {
|
2023-04-15 00:50:46 +02:00
|
|
|
let target = backend.to_target();
|
|
|
|
let features = Some(target.and_features(backend.to_rtic_feature()));
|
|
|
|
|
2023-03-01 00:25:05 +01:00
|
|
|
examples.into_par_iter().for_each(|example| {
|
|
|
|
let cmd = CargoCommand::ExampleBuild {
|
|
|
|
cargoarg: &Some("--quiet"),
|
|
|
|
example,
|
2023-04-15 00:50:46 +02:00
|
|
|
target,
|
|
|
|
features: features.clone(),
|
2023-03-01 00:25:05 +01:00
|
|
|
mode: BuildMode::Release,
|
|
|
|
};
|
2023-04-15 00:26:16 +02:00
|
|
|
if let Err(err) = command_parser(globals, &cmd, false) {
|
2023-03-01 00:25:05 +01:00
|
|
|
error!("{err}");
|
|
|
|
}
|
|
|
|
|
|
|
|
let cmd = CargoCommand::Qemu {
|
|
|
|
cargoarg,
|
|
|
|
example,
|
2023-04-15 00:50:46 +02:00
|
|
|
target,
|
|
|
|
features: features.clone(),
|
2023-03-01 00:25:05 +01:00
|
|
|
mode: BuildMode::Release,
|
|
|
|
};
|
|
|
|
|
2023-04-15 00:26:16 +02:00
|
|
|
if let Err(err) = command_parser(globals, &cmd, overwrite) {
|
2023-03-01 00:25:05 +01:00
|
|
|
error!("{err}");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check the binary sizes of examples
|
|
|
|
pub fn build_and_check_size(
|
2023-04-15 00:26:16 +02:00
|
|
|
globals: &Globals,
|
2023-03-01 00:25:05 +01:00
|
|
|
cargoarg: &Option<&str>,
|
|
|
|
backend: Backends,
|
|
|
|
examples: &[String],
|
2023-03-02 22:02:19 +01:00
|
|
|
arguments: &Option<ExtraArguments>,
|
2023-03-01 00:25:05 +01:00
|
|
|
) -> anyhow::Result<()> {
|
2023-04-15 00:50:46 +02:00
|
|
|
let target = backend.to_target();
|
|
|
|
let features = Some(target.and_features(backend.to_rtic_feature()));
|
|
|
|
|
2023-03-01 00:25:05 +01:00
|
|
|
examples.into_par_iter().for_each(|example| {
|
|
|
|
// Make sure the requested example(s) are built
|
|
|
|
let cmd = CargoCommand::ExampleBuild {
|
|
|
|
cargoarg: &Some("--quiet"),
|
|
|
|
example,
|
2023-04-15 00:50:46 +02:00
|
|
|
target,
|
|
|
|
features: features.clone(),
|
2023-03-01 00:25:05 +01:00
|
|
|
mode: BuildMode::Release,
|
|
|
|
};
|
2023-04-15 00:26:16 +02:00
|
|
|
if let Err(err) = command_parser(globals, &cmd, false) {
|
2023-03-01 00:25:05 +01:00
|
|
|
error!("{err}");
|
|
|
|
}
|
|
|
|
|
|
|
|
let cmd = CargoCommand::ExampleSize {
|
|
|
|
cargoarg,
|
|
|
|
example,
|
|
|
|
target: backend.to_target(),
|
2023-04-15 00:50:46 +02:00
|
|
|
features: features.clone(),
|
2023-03-01 00:25:05 +01:00
|
|
|
mode: BuildMode::Release,
|
2023-03-02 22:02:19 +01:00
|
|
|
arguments: arguments.clone(),
|
2023-03-01 00:25:05 +01:00
|
|
|
};
|
2023-04-15 00:26:16 +02:00
|
|
|
if let Err(err) = command_parser(globals, &cmd, false) {
|
2023-03-01 00:25:05 +01:00
|
|
|
error!("{err}");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|