From deeb3877f061fb71389ec7730c6c21e81e9e3050 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 22:40:25 +0200 Subject: [PATCH] Improve locality of error messages & ExampleBuild + Qemu commands, and indicate failure earlier --- xtask/src/cargo_commands.rs | 50 +++++++++++++++++++++---------------- xtask/src/command.rs | 34 +++++++++++-------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/xtask/src/cargo_commands.rs b/xtask/src/cargo_commands.rs index 42895d810b..2e3099749b 100644 --- a/xtask/src/cargo_commands.rs +++ b/xtask/src/cargo_commands.rs @@ -312,30 +312,36 @@ pub fn qemu_run_examples<'c>( let target = backend.to_target(); let features = Some(target.and_features(backend.to_rtic_feature())); - let build = examples_iter(examples).map(|example| { - let cmd_build = CargoCommand::ExampleBuild { - // We need to be in the correct - cargoarg: &None, - example, - target, - features: features.clone(), - mode: BuildMode::Release, - }; - (globals, cmd_build, overwrite) - }); + examples_iter(examples) + .flat_map(|example| { + let cmd_build = CargoCommand::ExampleBuild { + cargoarg: &None, + example, + target, + features: features.clone(), + mode: BuildMode::Release, + }; - let run = examples_iter(examples).map(|example| { - let cmd_qemu = CargoCommand::Qemu { - cargoarg, - example, - target, - features: features.clone(), - mode: BuildMode::Release, - }; - (globals, cmd_qemu, overwrite) - }); + let cmd_qemu = CargoCommand::Qemu { + cargoarg, + example, + target, + features: features.clone(), + mode: BuildMode::Release, + }; - build.chain(run).run_and_coalesce() + #[cfg(not(feature = "rayon"))] + { + [cmd_build, cmd_qemu].into_iter() + } + + #[cfg(feature = "rayon")] + { + [cmd_build, cmd_qemu].into_par_iter() + } + }) + .map(|cmd| (globals, cmd, overwrite)) + .run_and_coalesce() } /// Check the binary sizes of examples diff --git a/xtask/src/command.rs b/xtask/src/command.rs index 187a3ddccd..3596897e30 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -765,6 +765,10 @@ pub fn run_command(command: &CargoCommand, stderr_mode: OutputMode) -> anyhow::R log::info!("\n{}", stdout); } + if !exit_status.success() { + log::error!("❌ Command failed. Run to completion for the summary."); + } + Ok(RunResult { exit_status, stdout, @@ -825,32 +829,19 @@ pub fn handle_results(globals: &Globals, results: Vec) -> Result }); let log_stdout_stderr = |level: Level| { - move |(command, stdout, stderr): (&CargoCommand, &String, &String)| { + move |(cmd, stdout, stderr): (&CargoCommand, &String, &String)| { + let cmd = cmd.as_cmd_string(); if !stdout.is_empty() && !stderr.is_empty() { - log::log!( - level, - "Output for \"{command}\"\nStdout:\n{stdout}\nStderr:\n{stderr}" - ); + log::log!(level, "\n{cmd}\nStdout:\n{stdout}\nStderr:\n{stderr}"); } else if !stdout.is_empty() { - log::log!( - level, - "Output for \"{command}\":\nStdout:\n{}", - stdout.trim_end() - ); + log::log!(level, "\n{cmd}\nStdout:\n{}", stdout.trim_end()); } else if !stderr.is_empty() { - log::log!( - level, - "Output for \"{command}\"\nStderr:\n{}", - stderr.trim_end() - ); + log::log!(level, "\n{cmd}\nStderr:\n{}", stderr.trim_end()); } } }; - successes.clone().for_each(log_stdout_stderr(Level::Debug)); - errors.clone().for_each(log_stdout_stderr(Level::Error)); - - successes.for_each(|(cmd, _, _)| { + successes.for_each(|(cmd, stdout, stderr)| { let path = if let Some(dir) = cmd.chdir() { let path = dir.as_os_str().to_str().unwrap_or("Not displayable"); format!(" (in {path}") @@ -863,15 +854,18 @@ pub fn handle_results(globals: &Globals, results: Vec) -> Result } else { info!("✅ Success: {cmd}{path}"); } + + log_stdout_stderr(Level::Debug)((cmd, stdout, stderr)); }); - errors.clone().for_each(|(cmd, _, _)| { + errors.clone().for_each(|(cmd, stdout, stderr)| { if let Some(dir) = cmd.chdir() { let path = dir.as_os_str().to_str().unwrap_or("Not displayable"); error!("❌ Failed: {cmd} (in {path}) \n {}", cmd.as_cmd_string()); } else { error!("❌ Failed: {cmd}\n {}", cmd.as_cmd_string()); } + log_stdout_stderr(Level::Error)((cmd, stdout, stderr)); }); command_errors