aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/main.rs
diff options
context:
space:
mode:
authordatdenkikniet <jcdra1@gmail.com>2023-04-15 12:21:11 +0200
committerdatdenkikniet <jcdra1@gmail.com>2023-04-15 12:33:46 +0200
commit525703358bf52b74a01d9b0c04680d33621d60cd (patch)
tree366346833e91ebfc1704525233cfb68abe3ef600 /xtask/src/main.rs
parent1ccca03a70b5d11dc03c046041138f73267af22a (diff)
Rework command execution structure and make rayon optional (since it's not necessarily faster
due to workspace wide lockfile contention)
Diffstat (limited to 'xtask/src/main.rs')
-rw-r--r--xtask/src/main.rs47
1 files changed, 14 insertions, 33 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 89ca0fe..a50657d 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -3,7 +3,6 @@ mod build;
mod cargo_commands;
mod command;
-use anyhow::bail;
use argument_parsing::{ExtraArguments, Globals, Package};
use clap::Parser;
use command::OutputMode;
@@ -15,7 +14,6 @@ use std::{
fs::File,
io::prelude::*,
path::{Path, PathBuf},
- process,
process::ExitStatus,
str,
};
@@ -72,7 +70,6 @@ const ARMV8MMAIN: Target = Target::new("thumbv8m.main-none-eabi", false);
#[derive(Debug, Clone)]
pub struct RunResult {
exit_status: ExitStatus,
- full_command: String,
stdout: String,
stderr: String,
}
@@ -125,7 +122,9 @@ fn main() -> anyhow::Result<()> {
// check the name of `env::current_dir()` because people might clone it into a different name)
let probably_running_from_repo_root = Path::new("./xtask").exists();
if !probably_running_from_repo_root {
- bail!("xtasks can only be executed from the root of the `rtic` repository");
+ return Err(anyhow::anyhow!(
+ "xtasks can only be executed from the root of the `rtic` repository"
+ ));
}
let examples: Vec<_> = std::fs::read_dir("./rtic/examples")?
@@ -195,10 +194,10 @@ fn main() -> anyhow::Result<()> {
\n{examples:#?}\n\
By default if example flag is emitted, all examples are tested.",
);
- process::exit(exitcode::USAGE);
+ return Err(anyhow::anyhow!("Incorrect usage"));
} else {
+ examples_to_run
}
- examples_to_run
};
init_build_dir()?;
@@ -299,7 +298,11 @@ fn main() -> anyhow::Result<()> {
}
// run example binary `example`
-fn command_parser(glob: &Globals, command: &CargoCommand, overwrite: bool) -> anyhow::Result<()> {
+fn command_parser(
+ glob: &Globals,
+ command: &CargoCommand,
+ overwrite: bool,
+) -> anyhow::Result<RunResult> {
let output_mode = if glob.stderr_inherited {
OutputMode::Inherited
} else {
@@ -338,8 +341,9 @@ fn command_parser(glob: &Globals, command: &CargoCommand, overwrite: bool) -> an
};
} else {
run_successful(&cargo_run_result, &expected_output_file)?;
- }
- Ok(())
+ };
+
+ Ok(cargo_run_result)
}
CargoCommand::Format { .. }
| CargoCommand::ExampleCheck { .. }
@@ -352,30 +356,7 @@ fn command_parser(glob: &Globals, command: &CargoCommand, overwrite: bool) -> an
| CargoCommand::Book { .. }
| CargoCommand::ExampleSize { .. } => {
let cargo_result = run_command(command, output_mode)?;
- let command = cargo_result.full_command;
- if let Some(exit_code) = cargo_result.exit_status.code() {
- if exit_code != exitcode::OK {
- error!("Command {command} failed.");
- error!("Exit code: {exit_code}");
-
- if !cargo_result.stdout.is_empty() {
- info!("{}", cargo_result.stdout);
- }
- if !cargo_result.stderr.is_empty() {
- error!("{}", cargo_result.stderr);
- }
- process::exit(exit_code);
- } else {
- if !cargo_result.stdout.is_empty() {
- info!("{}", cargo_result.stdout);
- }
- if !cargo_result.stderr.is_empty() {
- info!("{}", cargo_result.stderr);
- }
- }
- }
-
- Ok(())
+ Ok(cargo_result)
}
}
}