From 8c7bf9e05cd4a0ca2385cc1425fd1f4d521bbad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Quentin?= Date: Tue, 4 Feb 2025 11:17:08 +0100 Subject: [PATCH 1/2] Check rustc+cargo, espflash, probe-rs --- src/check.rs | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 ++ 2 files changed, 91 insertions(+) create mode 100644 src/check.rs diff --git a/src/check.rs b/src/check.rs new file mode 100644 index 0000000..123700f --- /dev/null +++ b/src/check.rs @@ -0,0 +1,88 @@ +use core::str; + +use esp_metadata::Chip; + +struct Version { + major: u8, + minor: u8, + patch: u8, +} + +enum CheckResult { + Ok, + WrongVersion, + NotFound, +} + +pub fn check(chip: Chip) { + let rust_version = get_version( + "cargo", + if chip.is_xtensa() { + &["+esp"] + } else { + &["+stable"] + }, + ); + + let espflash_version = get_version("espflash", &[]); + let probers_version = get_version("probe-rs", &[]); + + println!("\nChecking installed versions"); + print_result("Rust", check_version(rust_version, 1, 84, 0)); + print_result("espflash", check_version(espflash_version, 3, 3, 0)); + print_result("probe-rs", check_version(probers_version, 0, 25, 0)); +} + +fn print_result(name: &str, check_result: CheckResult) { + match check_result { + CheckResult::Ok => println!("🆗 {}", name), + CheckResult::WrongVersion => println!("🛑 {}", name), + CheckResult::NotFound => println!("❌ {}", name), + } +} + +fn check_version(version: Option, major: u8, minor: u8, patch: u8) -> CheckResult { + match version { + Some(version) => { + if version.major >= major && version.minor >= minor && version.patch >= patch { + CheckResult::Ok + } else { + CheckResult::WrongVersion + } + } + None => CheckResult::NotFound, + } +} + +fn get_version(cmd: &str, args: &[&str]) -> Option { + let output = std::process::Command::new(cmd) + .args(args) + .arg("--version") + .output(); + + match output { + Ok(output) => { + if output.status.success() { + if let Ok(output) = str::from_utf8(&output.stdout) { + let mut parts = output.split_whitespace(); + let _name = parts.next(); + let version = parts.next(); + if let Some(version) = version { + let mut version = version.split(&['.', '-', '+']); + let major = version.next().unwrap().parse::().unwrap(); + let minor = version.next().unwrap().parse::().unwrap(); + let patch = version.next().unwrap().parse::().unwrap(); + return Some(Version { + major, + minor, + patch, + }); + } + } + } + + None + } + Err(_) => None, + } +} diff --git a/src/main.rs b/src/main.rs index 2ed4fd9..3dfa79d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use esp_metadata::Chip; use taplo::formatter::Options; use update_informer::{registry, Check}; +mod check; mod template_files; mod tui; @@ -375,6 +376,8 @@ fn main() -> Result<(), Box> { log::warn!("Current directory is already in a git repository, skipping git initialization"); } + check::check(args.chip); + Ok(()) } From 8b6da82d2f0d56802659997817303f5fb32a29be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Quentin?= Date: Tue, 4 Feb 2025 14:26:52 +0100 Subject: [PATCH 2/2] CHANGELOG.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfb2a07..59e6b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Added a version checker that prints a wanr message if not using latest esp-generate version (#87) +- Added a version checker that prints a warn message if not using latest esp-generate version (#87) + +- After generating the project the tool now checks the rust version, espflash version and probe-rs version (#88) + ### Changed - Update `probe-rs run` arguments (#90)