mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
Use chdir() instead of unstable option, also confirm whenver a command succeeds because
why not
This commit is contained in:
parent
deeb3877f0
commit
9dc9f49263
3 changed files with 63 additions and 35 deletions
|
@ -326,7 +326,7 @@ impl UsageExamplesOpt {
|
|||
let usage_examples: Vec<_> = std::fs::read_dir("./examples")?
|
||||
.filter_map(Result::ok)
|
||||
.filter(|p| p.metadata().ok().map(|p| p.is_dir()).unwrap_or(false))
|
||||
.filter_map(|p| p.file_name().as_os_str().to_str().map(ToString::to_string))
|
||||
.filter_map(|p| p.file_name().to_str().map(ToString::to_string))
|
||||
.collect();
|
||||
|
||||
let selected_examples: Option<Vec<String>> = self
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::{
|
||||
argument_parsing::{Backends, BuildOrCheck, ExtraArguments, Globals, PackageOpt, TestMetadata},
|
||||
command::{BuildMode, CargoCommand},
|
||||
|
@ -186,6 +188,7 @@ pub fn cargo_example<'c>(
|
|||
target: backend.to_target(),
|
||||
features,
|
||||
mode: BuildMode::Release,
|
||||
dir: Some(PathBuf::from("./rtic")),
|
||||
},
|
||||
};
|
||||
(globals, command, false)
|
||||
|
@ -320,6 +323,7 @@ pub fn qemu_run_examples<'c>(
|
|||
target,
|
||||
features: features.clone(),
|
||||
mode: BuildMode::Release,
|
||||
dir: Some(PathBuf::from("./rtic")),
|
||||
};
|
||||
|
||||
let cmd_qemu = CargoCommand::Qemu {
|
||||
|
@ -328,6 +332,7 @@ pub fn qemu_run_examples<'c>(
|
|||
target,
|
||||
features: features.clone(),
|
||||
mode: BuildMode::Release,
|
||||
dir: Some(PathBuf::from("./rtic")),
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "rayon"))]
|
||||
|
@ -363,6 +368,7 @@ pub fn build_and_check_size<'c>(
|
|||
target,
|
||||
features: features.clone(),
|
||||
mode: BuildMode::Release,
|
||||
dir: Some(PathBuf::from("./rtic")),
|
||||
};
|
||||
if let Err(err) = command_parser(globals, &cmd, false) {
|
||||
error!("{err}");
|
||||
|
@ -375,6 +381,7 @@ pub fn build_and_check_size<'c>(
|
|||
features: features.clone(),
|
||||
mode: BuildMode::Release,
|
||||
arguments: arguments.clone(),
|
||||
dir: Some(PathBuf::from("./rtic")),
|
||||
};
|
||||
(globals, cmd, false)
|
||||
});
|
||||
|
|
|
@ -51,6 +51,7 @@ pub enum CargoCommand<'a> {
|
|||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
dir: Option<PathBuf>,
|
||||
},
|
||||
ExampleBuild {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
|
@ -58,6 +59,7 @@ pub enum CargoCommand<'a> {
|
|||
target: Target<'a>,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
dir: Option<PathBuf>,
|
||||
},
|
||||
ExampleCheck {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
|
@ -111,6 +113,7 @@ pub enum CargoCommand<'a> {
|
|||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
arguments: Option<ExtraArguments>,
|
||||
dir: Option<PathBuf>,
|
||||
},
|
||||
CheckInDir {
|
||||
mode: BuildMode,
|
||||
|
@ -179,22 +182,32 @@ impl core::fmt::Display for CargoCommand<'_> {
|
|||
target,
|
||||
features,
|
||||
mode,
|
||||
} => write!(
|
||||
f,
|
||||
"Run example {example} in QEMU {}",
|
||||
details(target, mode, features, cargoarg)
|
||||
),
|
||||
dir,
|
||||
} => {
|
||||
let details = details(target, mode, features, cargoarg);
|
||||
if let Some(dir) = dir {
|
||||
let dir = dir.to_str().unwrap_or("Not displayable");
|
||||
write!(f, "Run example {example} in QEMU from {dir} {details}",)
|
||||
} else {
|
||||
write!(f, "Run example {example} in QEMU {details}",)
|
||||
}
|
||||
}
|
||||
CargoCommand::ExampleBuild {
|
||||
cargoarg,
|
||||
example,
|
||||
target,
|
||||
features,
|
||||
mode,
|
||||
} => write!(
|
||||
f,
|
||||
"Build example {example} {}",
|
||||
details(target, mode, features, cargoarg)
|
||||
),
|
||||
dir,
|
||||
} => {
|
||||
let details = details(target, mode, features, cargoarg);
|
||||
if let Some(dir) = dir {
|
||||
let dir = dir.to_str().unwrap_or("Not displayable");
|
||||
write!(f, "Build example {example} in {dir} {details}")
|
||||
} else {
|
||||
write!(f, "Build example {example} {details}",)
|
||||
}
|
||||
}
|
||||
CargoCommand::ExampleCheck {
|
||||
cargoarg,
|
||||
example,
|
||||
|
@ -221,7 +234,7 @@ impl core::fmt::Display for CargoCommand<'_> {
|
|||
)
|
||||
}
|
||||
CargoCommand::BuildInDir { mode, dir } => {
|
||||
let dir = dir.as_os_str().to_str().unwrap_or("Not displayable");
|
||||
let dir = dir.to_str().unwrap_or("Not displayable");
|
||||
write!(f, "Build {dir} ({mode})")
|
||||
}
|
||||
CargoCommand::Check {
|
||||
|
@ -239,7 +252,7 @@ impl core::fmt::Display for CargoCommand<'_> {
|
|||
)
|
||||
}
|
||||
CargoCommand::CheckInDir { mode, dir } => {
|
||||
let dir = dir.as_os_str().to_str().unwrap_or("Not displayable");
|
||||
let dir = dir.to_str().unwrap_or("Not displayable");
|
||||
write!(f, "Check {dir} ({mode})")
|
||||
}
|
||||
CargoCommand::Clippy {
|
||||
|
@ -315,12 +328,15 @@ impl core::fmt::Display for CargoCommand<'_> {
|
|||
features,
|
||||
mode,
|
||||
arguments: _,
|
||||
dir,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"Compute size of example {example} {}",
|
||||
details(target, mode, features, cargoarg)
|
||||
)
|
||||
let details = details(target, mode, features, cargoarg);
|
||||
if let Some(dir) = dir {
|
||||
let dir = dir.to_str().unwrap_or("Not displayable");
|
||||
write!(f, "Compute size of example {example} from {dir} {details}",)
|
||||
} else {
|
||||
write!(f, "Compute size of example {example} {details}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -328,9 +344,15 @@ impl core::fmt::Display for CargoCommand<'_> {
|
|||
|
||||
impl<'a> CargoCommand<'a> {
|
||||
pub fn as_cmd_string(&self) -> String {
|
||||
let cd = if let Some(Some(chdir)) = self.chdir().map(|p| p.to_str()) {
|
||||
format!("cd {chdir} && ")
|
||||
} else {
|
||||
format!("")
|
||||
};
|
||||
|
||||
let executable = self.executable();
|
||||
let args = self.args().join(" ");
|
||||
format!("{executable} {args}")
|
||||
format!("{cd}{executable} {args}")
|
||||
}
|
||||
|
||||
fn command(&self) -> &'static str {
|
||||
|
@ -406,6 +428,8 @@ impl<'a> CargoCommand<'a> {
|
|||
target,
|
||||
features,
|
||||
mode,
|
||||
// Dir is exposed through chdir instead
|
||||
dir: _,
|
||||
} => {
|
||||
let mut args = vec!["+nightly"];
|
||||
|
||||
|
@ -413,10 +437,6 @@ impl<'a> CargoCommand<'a> {
|
|||
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",
|
||||
|
@ -588,16 +608,14 @@ impl<'a> CargoCommand<'a> {
|
|||
target,
|
||||
features,
|
||||
mode,
|
||||
// Dir is exposed through chdir instead
|
||||
dir: _,
|
||||
} => {
|
||||
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",
|
||||
|
@ -648,16 +666,14 @@ impl<'a> CargoCommand<'a> {
|
|||
features,
|
||||
mode,
|
||||
arguments,
|
||||
// Dir is exposed through chdir instead
|
||||
dir: _,
|
||||
} => {
|
||||
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",
|
||||
|
@ -708,6 +724,9 @@ impl<'a> CargoCommand<'a> {
|
|||
CargoCommand::CheckInDir { dir, .. } | CargoCommand::BuildInDir { dir, .. } => {
|
||||
Some(dir)
|
||||
}
|
||||
CargoCommand::Qemu { dir, .. }
|
||||
| CargoCommand::ExampleBuild { dir, .. }
|
||||
| CargoCommand::ExampleSize { dir, .. } => dir.as_ref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -752,7 +771,7 @@ pub fn run_command(command: &CargoCommand, stderr_mode: OutputMode) -> anyhow::R
|
|||
.stderr(stderr_mode);
|
||||
|
||||
if let Some(dir) = command.chdir() {
|
||||
process.current_dir(dir);
|
||||
process.current_dir(dir.canonicalize()?);
|
||||
}
|
||||
|
||||
let result = process.output()?;
|
||||
|
@ -765,7 +784,9 @@ pub fn run_command(command: &CargoCommand, stderr_mode: OutputMode) -> anyhow::R
|
|||
log::info!("\n{}", stdout);
|
||||
}
|
||||
|
||||
if !exit_status.success() {
|
||||
if exit_status.success() {
|
||||
log::info!("✅ Success.")
|
||||
} else {
|
||||
log::error!("❌ Command failed. Run to completion for the summary.");
|
||||
}
|
||||
|
||||
|
@ -843,7 +864,7 @@ pub fn handle_results(globals: &Globals, results: Vec<FinalRunResult>) -> Result
|
|||
|
||||
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");
|
||||
let path = dir.to_str().unwrap_or("Not displayable");
|
||||
format!(" (in {path}")
|
||||
} else {
|
||||
format!("")
|
||||
|
@ -860,7 +881,7 @@ pub fn handle_results(globals: &Globals, results: Vec<FinalRunResult>) -> Result
|
|||
|
||||
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");
|
||||
let path = dir.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());
|
||||
|
|
Loading…
Reference in a new issue