From d838286de679a1ac35ea79999816418cd02b7259 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 21:16:45 +0200 Subject: [PATCH] Fix config pickup behaviour so that both examples and usage-examples build correctly --- .cargo/config.toml | 12 ++---------- rtic/.cargo/config.toml | 10 ++++++++++ xtask/src/command.rs | 28 +++++++++++++++++++++++++--- xtask/src/main.rs | 4 ++-- 4 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 rtic/.cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml index 0a62466ad2..ea1655c19d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,13 +2,5 @@ xtask = "run --package xtask --" pxtask = "run --package xtask --features rayon --" -[target.thumbv6m-none-eabi] -runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" - -[target.thumbv7m-none-eabi] -runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" - -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -rustflags = [ - "-C", "link-arg=-Tlink.x", -] +# Don't define the RUSTFLAGS link.x thing here: it messes +# up compilation of the usage examples. diff --git a/rtic/.cargo/config.toml b/rtic/.cargo/config.toml new file mode 100644 index 0000000000..ddec65047b --- /dev/null +++ b/rtic/.cargo/config.toml @@ -0,0 +1,10 @@ +[target.thumbv6m-none-eabi] +runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" + +[target.thumbv7m-none-eabi] +runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" + +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +rustflags = [ + "-C", "link-arg=-Tlink.x", +] diff --git a/xtask/src/command.rs b/xtask/src/command.rs index a1c4d2533b..a45cb8ac8b 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -383,6 +383,7 @@ impl<'a> CargoCommand<'a> { if let Some(cargoarg) = cargoarg { args.extend_from_slice(&[cargoarg]); } + args.extend_from_slice(&[ self.command(), "--example", @@ -407,9 +408,15 @@ impl<'a> CargoCommand<'a> { mode, } => { let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { args.extend_from_slice(&[cargoarg]); } + + // We need to be in the `rtic` directory to pick up + // the correct .cargo/config.toml file + args.extend_from_slice(&["-Z", "unstable-options", "-C", "rtic"]); + args.extend_from_slice(&[ self.command(), "--example", @@ -641,6 +648,11 @@ impl<'a> CargoCommand<'a> { if let Some(cargoarg) = cargoarg { args.extend_from_slice(&[cargoarg]); } + + // We need to be in the `rtic` directory to pick up + // the correct .cargo/config.toml file + args.extend_from_slice(&["-Z", "unstable-options", "-C", "rtic"]); + args.extend_from_slice(&[ self.command(), "--example", @@ -694,6 +706,13 @@ impl<'a> CargoCommand<'a> { _ => None, } } + + pub fn print_stdout_intermediate(&self) -> bool { + match self { + Self::ExampleSize { .. } => true, + _ => false, + } + } } impl BuildMode { @@ -737,6 +756,10 @@ pub fn run_command(command: &CargoCommand, stderr_mode: OutputMode) -> anyhow::R let stderr = String::from_utf8(result.stderr).unwrap_or("Not displayable".into()); let stdout = String::from_utf8(result.stdout).unwrap_or("Not displayable".into()); + if command.print_stdout_intermediate() && exit_status.success() { + log::info!("\n{}", stdout); + } + Ok(RunResult { exit_status, stdout, @@ -850,9 +873,8 @@ pub fn handle_results(globals: &Globals, results: Vec) -> Result .clone() .for_each(|(cmd, error)| error!("❌ Failed: {cmd}\n {}\n{error}", cmd.as_cmd_string())); - let ecount = errors.count(); - let cecount = command_errors.count(); - if ecount != 0 || cecount != 0 { + let ecount = errors.count() + command_errors.count(); + if ecount != 0 { log::error!("{ecount} commands failed."); Err(()) } else { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 10499c022c..7077d552bd 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) => {