Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check rustc+cargo, espflash, probe-rs #88

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
88 changes: 88 additions & 0 deletions src/check.rs
Original file line number Diff line number Diff line change
@@ -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));
MabezDev marked this conversation as resolved.
Show resolved Hide resolved
print_result("espflash", check_version(espflash_version, 3, 3, 0));
print_result("probe-rs", check_version(probers_version, 0, 25, 0));
SergioGasquez marked this conversation as resolved.
Show resolved Hide resolved
}

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<Version>, 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<Version> {
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::<u8>().unwrap();
let minor = version.next().unwrap().parse::<u8>().unwrap();
let patch = version.next().unwrap().parse::<u8>().unwrap();
return Some(Version {
major,
minor,
patch,
});
}
}
}

None
}
Err(_) => None,
}
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use esp_metadata::Chip;
use taplo::formatter::Options;
use update_informer::{registry, Check};

mod check;
mod template_files;
mod tui;

Expand Down Expand Up @@ -375,6 +376,8 @@ fn main() -> Result<(), Box<dyn Error>> {
log::warn!("Current directory is already in a git repository, skipping git initialization");
}

check::check(args.chip);

Ok(())
}

Expand Down