From 63b7024cb98717dd785ae888f419002b9835c6b1 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Fri, 14 Apr 2023 23:59:23 +0200 Subject: xtask: build usage examples and general improvements --- xtask/src/main.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 2bfe851..2b45f23 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -23,10 +23,7 @@ use log::{error, info, log_enabled, trace, Level}; use crate::{ argument_parsing::{Backends, BuildOrCheck, Cli, Commands}, build::init_build_dir, - cargo_commands::{ - build_and_check_size, cargo, cargo_book, cargo_clippy, cargo_doc, cargo_example, - cargo_format, cargo_test, run_test, - }, + cargo_commands::*, command::{handle_results, run_command, run_successful, CargoCommand}, }; @@ -152,6 +149,12 @@ fn main() -> anyhow::Result<()> { trace!("default logging level: {0}", globals.verbose); + log::debug!( + "Stderr of child processes is inherited: {}", + globals.stderr_inherited + ); + log::debug!("Partial features: {}", globals.partial); + let backend = if let Some(backend) = globals.backend { backend } else { @@ -285,6 +288,14 @@ fn main() -> anyhow::Result<()> { info!("Running mdbook"); cargo_book(globals, &args.arguments) } + Commands::UsageExamplesCheck(examples) => { + info!("Checking usage examples"); + cargo_usage_example(globals, BuildOrCheck::Check, examples.examples()?) + } + Commands::UsageExampleBuild(examples) => { + info!("Building usage examples"); + cargo_usage_example(globals, BuildOrCheck::Build, examples.examples()?) + } }; handle_results(globals, final_run_results) @@ -347,7 +358,9 @@ fn command_parser( | CargoCommand::Doc { .. } | CargoCommand::Test { .. } | CargoCommand::Book { .. } - | CargoCommand::ExampleSize { .. } => { + | CargoCommand::ExampleSize { .. } + | CargoCommand::BuildInDir { .. } + | CargoCommand::CheckInDir { .. } => { let cargo_result = run_command(command, output_mode)?; Ok(cargo_result) } -- cgit v1.2.3 From fa8af4cbcffbedec1504ed464bd02b6ee6e3fb4b Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 20:19:37 +0200 Subject: Add the most important message --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 2b45f23..1cc0185 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -298,7 +298,7 @@ fn main() -> anyhow::Result<()> { } }; - handle_results(globals, final_run_results) + handle_results(globals, final_run_results).map_err(|_| anyhow::anyhow!("Commands failed")) } // run example binary `example` -- cgit v1.2.3 From 6517a4bec2e909b40eb9974e063f95e44e4d9a31 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 20:44:06 +0200 Subject: Also check for CommandErrors in error checking --- xtask/src/main.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 1cc0185..4cf6db8 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -324,9 +324,7 @@ fn command_parser( .map_err(TestRunError::PathConversionError)?; // cargo run <..> - info!("Running example: {example}"); let cargo_run_result = run_command(command, output_mode)?; - info!("{}", cargo_run_result.stdout); // Create a file for the expected output if it does not exist or mismatches if overwrite { -- cgit v1.2.3 From 859cd418f063590a9928b3e43caeea0b53dc0823 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 20:57:27 +0200 Subject: Rename some things --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4cf6db8..10499c0 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -288,7 +288,7 @@ fn main() -> anyhow::Result<()> { info!("Running mdbook"); cargo_book(globals, &args.arguments) } - Commands::UsageExamplesCheck(examples) => { + Commands::UsageExampleCheck(examples) => { info!("Checking usage examples"); cargo_usage_example(globals, BuildOrCheck::Check, examples.examples()?) } -- cgit v1.2.3 From d838286de679a1ac35ea79999816418cd02b7259 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 21:16:45 +0200 Subject: Fix config pickup behaviour so that both examples and usage-examples build correctly --- xtask/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 10499c0..7077d55 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -100,8 +100,8 @@ impl fmt::Display for TestRunError { TestRunError::CommandError(e) => { write!( f, - "Command failed with exit status {}: {}", - e.exit_status, e.stdout + "Command failed with exit status {}: {} {}", + e.exit_status, e.stdout, e.stderr ) } TestRunError::PathConversionError(p) => { -- cgit v1.2.3 From 1c84ccf6e4169b4b45f0e22e709e4265a10324a5 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 22:19:13 +0200 Subject: Fix running of tests --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7077d55..853dbe7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -268,7 +268,7 @@ fn main() -> anyhow::Result<()> { Commands::Qemu(args) | Commands::Run(args) => { // x86_64 target not valid info!("Testing for backend: {backend:?}"); - run_test( + qemu_run_examples( globals, &cargologlevel, backend, -- cgit v1.2.3 From 404867cdf92990cb0aba415dfbee97c7fef78b60 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sun, 16 Apr 2023 09:44:30 +0200 Subject: CargoCommand can take any package --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 853dbe7..0043474 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -3,7 +3,7 @@ mod build; mod cargo_commands; mod command; -use argument_parsing::{ExtraArguments, Globals, Package}; +use argument_parsing::{ExtraArguments, Globals}; use clap::Parser; use command::OutputMode; use core::fmt; -- cgit v1.2.3 From b59bf686c1e10bb8068d89e43779d7777f553c48 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sun, 16 Apr 2023 11:00:39 +0200 Subject: Redo command building so that we don't repeat as much, and to make it easier to add new ones --- xtask/src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 0043474..2f35079 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -356,9 +356,7 @@ fn command_parser( | CargoCommand::Doc { .. } | CargoCommand::Test { .. } | CargoCommand::Book { .. } - | CargoCommand::ExampleSize { .. } - | CargoCommand::BuildInDir { .. } - | CargoCommand::CheckInDir { .. } => { + | CargoCommand::ExampleSize { .. } => { let cargo_result = run_command(command, output_mode)?; Ok(cargo_result) } -- cgit v1.2.3 From 66a3d02b4585a76615d750c33a37edd5e8fd30e6 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sun, 16 Apr 2023 11:02:49 +0200 Subject: Rename cargo_commands -> run Rename command -> cargo_command --- xtask/src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 2f35079..09bf8c7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,11 +1,11 @@ mod argument_parsing; mod build; -mod cargo_commands; -mod command; +mod xtasks; +mod cargo_command; use argument_parsing::{ExtraArguments, Globals}; use clap::Parser; -use command::OutputMode; +use cargo_command::OutputMode; use core::fmt; use diffy::{create_patch, PatchFormatter}; use std::{ @@ -23,8 +23,8 @@ use log::{error, info, log_enabled, trace, Level}; use crate::{ argument_parsing::{Backends, BuildOrCheck, Cli, Commands}, build::init_build_dir, - cargo_commands::*, - command::{handle_results, run_command, run_successful, CargoCommand}, + xtasks::*, + cargo_command::{handle_results, run_command, run_successful, CargoCommand}, }; #[derive(Debug, Clone, Copy)] -- cgit v1.2.3 From c6b43800d2a368d7948639899b8dca50cc97712f Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sun, 16 Apr 2023 11:05:41 +0200 Subject: Move all run-related stuff into `run` --- xtask/src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 09bf8c7..1712d71 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,11 +1,10 @@ mod argument_parsing; mod build; -mod xtasks; mod cargo_command; +mod run; use argument_parsing::{ExtraArguments, Globals}; use clap::Parser; -use cargo_command::OutputMode; use core::fmt; use diffy::{create_patch, PatchFormatter}; use std::{ @@ -23,8 +22,8 @@ use log::{error, info, log_enabled, trace, Level}; use crate::{ argument_parsing::{Backends, BuildOrCheck, Cli, Commands}, build::init_build_dir, - xtasks::*, - cargo_command::{handle_results, run_command, run_successful, CargoCommand}, + cargo_command::CargoCommand, + run::*, }; #[derive(Debug, Clone, Copy)] -- cgit v1.2.3 From 65f1f4c1b7f8de50c6f9462a39c98dcd3a73b4cc Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sun, 16 Apr 2023 11:26:23 +0200 Subject: Also separate all results and data --- xtask/src/main.rs | 126 +----------------------------------------------------- 1 file changed, 2 insertions(+), 124 deletions(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 1712d71..30c3da0 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -3,26 +3,16 @@ mod build; mod cargo_command; mod run; -use argument_parsing::{ExtraArguments, Globals}; +use argument_parsing::ExtraArguments; use clap::Parser; use core::fmt; -use diffy::{create_patch, PatchFormatter}; -use std::{ - error::Error, - ffi::OsString, - fs::File, - io::prelude::*, - path::{Path, PathBuf}, - process::ExitStatus, - str, -}; +use std::{path::Path, str}; use log::{error, info, log_enabled, trace, Level}; use crate::{ argument_parsing::{Backends, BuildOrCheck, Cli, Commands}, build::init_build_dir, - cargo_command::CargoCommand, run::*, }; @@ -65,56 +55,6 @@ 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 { - exit_status: ExitStatus, - stdout: String, - stderr: String, -} - -#[derive(Debug)] -pub enum TestRunError { - FileCmpError { expected: String, got: String }, - FileError { file: String }, - PathConversionError(OsString), - CommandError(RunResult), - IncompatibleCommand, -} -impl fmt::Display for TestRunError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - TestRunError::FileCmpError { expected, got } => { - let patch = create_patch(expected, got); - writeln!(f, "Differing output in files.\n")?; - let pf = PatchFormatter::new().with_color(); - writeln!(f, "{}", pf.fmt_patch(&patch))?; - write!( - f, - "See flag --overwrite-expected to create/update expected output." - ) - } - TestRunError::FileError { file } => { - write!(f, "File error on: {file}\nSee flag --overwrite-expected to create/update expected output.") - } - TestRunError::CommandError(e) => { - write!( - f, - "Command failed with exit status {}: {} {}", - e.exit_status, e.stdout, e.stderr - ) - } - TestRunError::PathConversionError(p) => { - write!(f, "Can't convert path from `OsString` to `String`: {p:?}") - } - TestRunError::IncompatibleCommand => { - write!(f, "Can't run that command in this context") - } - } - } -} - -impl Error for TestRunError {} - fn main() -> anyhow::Result<()> { // if there's an `xtask` folder, we're *probably* at the root of this repo (we can't just // check the name of `env::current_dir()` because people might clone it into a different name) @@ -299,65 +239,3 @@ fn main() -> anyhow::Result<()> { handle_results(globals, final_run_results).map_err(|_| anyhow::anyhow!("Commands failed")) } - -// run example binary `example` -fn command_parser( - glob: &Globals, - command: &CargoCommand, - overwrite: bool, -) -> anyhow::Result { - let output_mode = if glob.stderr_inherited { - OutputMode::Inherited - } else { - OutputMode::PipedAndCollected - }; - - match *command { - CargoCommand::Qemu { example, .. } | CargoCommand::Run { example, .. } => { - let run_file = format!("{example}.run"); - let expected_output_file = ["rtic", "ci", "expected", &run_file] - .iter() - .collect::() - .into_os_string() - .into_string() - .map_err(TestRunError::PathConversionError)?; - - // cargo run <..> - let cargo_run_result = run_command(command, output_mode)?; - - // Create a file for the expected output if it does not exist or mismatches - if overwrite { - let result = run_successful(&cargo_run_result, &expected_output_file); - if let Err(e) = result { - // FileError means the file did not exist or was unreadable - error!("Error: {e}"); - let mut file_handle = File::create(&expected_output_file).map_err(|_| { - TestRunError::FileError { - file: expected_output_file.clone(), - } - })?; - info!("Flag --overwrite-expected enabled"); - info!("Creating/updating file: {expected_output_file}"); - file_handle.write_all(cargo_run_result.stdout.as_bytes())?; - }; - } else { - run_successful(&cargo_run_result, &expected_output_file)?; - }; - - Ok(cargo_run_result) - } - CargoCommand::Format { .. } - | CargoCommand::ExampleCheck { .. } - | CargoCommand::ExampleBuild { .. } - | CargoCommand::Check { .. } - | CargoCommand::Build { .. } - | CargoCommand::Clippy { .. } - | CargoCommand::Doc { .. } - | CargoCommand::Test { .. } - | CargoCommand::Book { .. } - | CargoCommand::ExampleSize { .. } => { - let cargo_result = run_command(command, output_mode)?; - Ok(cargo_result) - } - } -} -- cgit v1.2.3