Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

Added metadata parsing for flash configuration #31

Merged
merged 3 commits into from
May 17, 2020
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
32 changes: 27 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ lazy_static = "1.4.0"
colored = "1.8.3"
probe-rs = { version = "0.6.2", git = "https://github.com/probe-rs/probe-rs" }
gdb-server = { version = "0.6.1", git = "https://github.com/probe-rs/probe-rs" }
cargo_toml = "0.8.0"
serde = { version = "1.0.110", features = [ "derive" ] }
24 changes: 21 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod logging;

use structopt;

use cargo_toml::Manifest;
use colored::*;
use failure::format_err;
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
Expand All @@ -17,6 +18,8 @@ use std::{
};
use structopt::StructOpt;

use serde::Deserialize;

use probe_rs::{
architecture::arm::ap::AccessPortError,
config::TargetSelector,
Expand Down Expand Up @@ -140,6 +143,11 @@ const ARGUMENTS_TO_REMOVE: &[&str] = &[
"log=",
];

#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct Meta {
pub chip: Option<String>,
}

fn main() {
match main_try() {
Ok(_) => (),
Expand Down Expand Up @@ -174,6 +182,13 @@ fn main_try() -> Result<(), failure::Error> {

logging::init(opt.log);

// Load cargo manifest if available and parse out meta object
// TODO: should we pull out a relative path here?
let meta = match Manifest::<Meta>::from_path_with_metadata("Cargo.toml") {
Ok(m) => m.package.map(|p| p.metadata).flatten(),
Err(_e) => None,
};

// Make sure we load the config given in the cli parameters.
if let Some(cdp) = opt.chip_description_path {
probe_rs::config::registry::add_target_from_yaml(&Path::new(&cdp))?;
Expand All @@ -183,9 +198,12 @@ fn main_try() -> Result<(), failure::Error> {
print_families()?;
std::process::exit(0);
} else {
opt.chip
.map(|chip| chip.into())
.unwrap_or(TargetSelector::Auto)
// First use command line, then manifest, then default to auto
match (opt.chip, meta.map(|m| m.chip).flatten()) {
(Some(c), _) => c.into(),
(_, Some(c)) => c.into(),
_ => TargetSelector::Auto,
}
};

args.remove(0); // Remove executable name
Expand Down