Skip to content
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
26 changes: 7 additions & 19 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 rust/.clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
avoid-breaking-exported-api = true
msrv = "1.71.0"
7 changes: 1 addition & 6 deletions rust/cmsis-cffi/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Config {
pack_store: PathBuf,
}

#[derive(Default)]
pub struct ConfigBuilder {
pack_store: Option<PathBuf>,
}
Expand Down Expand Up @@ -40,12 +41,6 @@ impl ConfigBuilder {
}
}

impl Default for ConfigBuilder {
fn default() -> Self {
Self { pack_store: None }
}
}

impl Config {
pub fn new() -> Result<Config, Error> {
ConfigBuilder::default().build()
Expand Down
1 change: 1 addition & 0 deletions rust/cmsis-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl Config {
}
match OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&self.vidx_list)
{
Expand Down
32 changes: 15 additions & 17 deletions rust/cmsis-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn install_args() -> App<'static, 'static> {
)
}

pub fn install_command<'a>(conf: &Config, args: &ArgMatches<'a>) -> Result<(), Error> {
pub fn install_command(conf: &Config, args: &ArgMatches<'_>) -> Result<(), Error> {
let pdsc_list: Vec<_> = args
.values_of("PDSC")
.unwrap()
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn update_args<'a, 'b>() -> App<'a, 'b> {
.version("0.1.0")
}

pub fn update_command<'a>(conf: &Config, _: &ArgMatches<'a>) -> Result<(), Error> {
pub fn update_command(conf: &Config, _: &ArgMatches<'_>) -> Result<(), Error> {
let vidx_list = conf.read_vidx_list();
for url in vidx_list.iter() {
log::info!("Updating registry from `{}`", url);
Expand Down Expand Up @@ -136,7 +136,7 @@ pub fn dump_devices_args<'a, 'b>() -> App<'a, 'b> {
)
}

pub fn dump_devices_command<'a>(c: &Config, args: &ArgMatches<'a>) -> Result<(), Error> {
pub fn dump_devices_command(c: &Config, args: &ArgMatches<'_>) -> Result<(), Error> {
let files = args
.value_of("INPUT")
.map(|input| vec![Path::new(input).to_path_buf()]);
Expand Down Expand Up @@ -175,27 +175,27 @@ pub fn check_args<'a, 'b>() -> App<'a, 'b> {
)
}

pub fn check_command<'a>(_: &Config, args: &ArgMatches<'a>) -> Result<(), Error> {
pub fn check_command(_: &Config, args: &ArgMatches<'_>) -> Result<(), Error> {
let filename = args.value_of("INPUT").unwrap();
match Package::from_path(Path::new(filename)) {
Ok(c) => {
log::info!("Parsing succedded");
log::info!("{} Valid Conditions", c.conditions.0.iter().count());
log::info!("{} Valid Conditions", c.conditions.0.len());
let cond_lookup = c.make_condition_lookup();
let mut num_components = 0;
let mut num_files = 0;
for &Component {
ref class,
ref group,
ref condition,
ref files,
for Component {
class,
group,
condition,
files,
..
} in c.make_components().iter()
{
num_components += 1;
num_files += files.iter().count();
num_files += files.len();
if let Some(ref cond_name) = condition {
if cond_lookup.get(cond_name.as_str()).is_none() {
if !cond_lookup.contains_key(cond_name.as_str()) {
log::warn!(
"Component {}::{} references an unknown condition '{}'",
class,
Expand All @@ -204,14 +204,12 @@ pub fn check_command<'a>(_: &Config, args: &ArgMatches<'a>) -> Result<(), Error>
);
}
}
for &FileRef {
ref path,
ref condition,
..
for FileRef {
path, condition, ..
} in files.iter()
{
if let Some(ref cond_name) = condition {
if cond_lookup.get(cond_name.as_str()).is_none() {
if !cond_lookup.contains_key(cond_name.as_str()) {
log::warn!(
"File {:?} Component {}::{} references an unknown condition '{}'",
path,
Expand Down
4 changes: 2 additions & 2 deletions rust/cmsis-pack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ edition = "2018"
bytes = "1.0"
futures = "0.3.8"
log = "0.4.8"
minidom = "0.12.0"
roxmltree = "0.20.0"
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["macros", "rt"] }
reqwest = { version = "0.12.0", default_features = false, features = [
reqwest = { version = "0.12.0", default-features = false, features = [
"rustls-tls-native-roots",
"trust-dns",
"stream",
Expand Down
4 changes: 3 additions & 1 deletion rust/cmsis-pack/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::upper_case_acronyms)]

pub mod pack_index;
pub mod pdsc;
pub mod update;
Expand All @@ -6,8 +8,8 @@ pub mod utils;

extern crate futures;
extern crate log;
extern crate minidom;
extern crate reqwest;
extern crate roxmltree;
extern crate serde;
extern crate serde_json;
extern crate tokio;
41 changes: 30 additions & 11 deletions rust/cmsis-pack/src/pack_index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::utils::prelude::*;
use anyhow::Error;
use minidom::Element;
use roxmltree::Node;

#[derive(Debug, Clone)]
pub struct PdscRef {
Expand Down Expand Up @@ -31,7 +31,7 @@ pub struct Vidx {
}

impl FromElem for PdscRef {
fn from_elem(e: &Element) -> Result<Self, Error> {
fn from_elem(e: &Node) -> Result<Self, Error> {
assert_root_name(e, "pdsc")?;
Ok(Self {
url: attr_map(e, "url")?,
Expand All @@ -47,7 +47,7 @@ impl FromElem for PdscRef {
}

impl FromElem for Pidx {
fn from_elem(e: &Element) -> Result<Self, Error> {
fn from_elem(e: &Node) -> Result<Self, Error> {
assert_root_name(e, "pidx")?;
Ok(Self {
url: attr_map(e, "url")?,
Expand All @@ -58,20 +58,35 @@ impl FromElem for Pidx {
}

impl FromElem for Vidx {
fn from_elem(root: &Element) -> Result<Self, Error> {
fn from_elem(root: &Node) -> Result<Self, Error> {
assert_root_name(root, "index")?;
let vendor = child_text(root, "vendor")?;
let url = child_text(root, "url")?;

let mut timestamp: Option<String> = None;
let mut vendor_index: Vec<Pidx> = Vec::new();
let mut pdsc_index: Vec<PdscRef> = Vec::new();
for child in root.children() {
match child.tag_name().name() {
"timestamp" => {
timestamp = Some(child).map(|e| e.text().unwrap_or_default().to_string())
}
"vindex" => {
vendor_index = Pidx::vec_from_children(child.children());
}
"pindex" => {
pdsc_index = PdscRef::vec_from_children(child.children());
}
_ => continue,
}
}

Ok(Vidx {
vendor,
url,
timestamp: get_child_no_ns(root, "timestamp").map(Element::text),
vendor_index: get_child_no_ns(root, "vindex")
.map(|e| Pidx::vec_from_children(e.children()))
.unwrap_or_default(),
pdsc_index: get_child_no_ns(root, "pindex")
.map(|e| PdscRef::vec_from_children(e.children()))
.unwrap_or_default(),
timestamp,
vendor_index,
pdsc_index,
})
}
}
Expand Down Expand Up @@ -200,5 +215,9 @@ mod test {
let response = Vidx::from_string(good_string).unwrap();
assert_eq!(response.vendor, String::from("Vendor"));
assert_eq!(response.url, "Url");
assert_eq!(
response.timestamp,
Some(String::from("Fri Sep 1 13:26:41 CDT"))
);
}
}
52 changes: 26 additions & 26 deletions rust/cmsis-pack/src/pdsc/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;
use std::str::FromStr;

use anyhow::{format_err, Error};
use minidom::Element;
use roxmltree::Node;
use serde::Serialize;

use crate::utils::prelude::*;
Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct FileRef {
}

impl FromElem for FileRef {
fn from_elem(e: &Element) -> Result<Self, Error> {
fn from_elem(e: &Node) -> Result<Self, Error> {
assert_root_name(e, "file")?;
Ok(Self {
path: attr_map(e, "name")?,
Expand Down Expand Up @@ -112,7 +112,7 @@ pub struct ComponentBuilder {
}

impl FromElem for ComponentBuilder {
fn from_elem(e: &Element) -> Result<Self, Error> {
fn from_elem(e: &Node) -> Result<Self, Error> {
assert_root_name(e, "component")?;
let vendor: Option<String> = attr_map(e, "Cvendor").ok();
let class: Option<String> = attr_map(e, "Cclass").ok();
Expand All @@ -122,18 +122,18 @@ impl FromElem for ComponentBuilder {
let class_string = class.clone().unwrap_or_else(|| "Class".into());
let group_string = group.clone().unwrap_or_else(|| "Group".into());
let sub_group_string = sub_group.clone().unwrap_or_else(|| "SubGroup".into());
let files = get_child_no_ns(e, "files")
.map(move |child| {
log::debug!(
"Working on {}::{}::{}::{}",
vendor_string,
class_string,
group_string,
sub_group_string,
);
FileRef::vec_from_children(child.children())
})
.unwrap_or_default();
let files = if let Some(node) = e.children().find(|c| c.tag_name().name() == "files") {
log::debug!(
"Working on {}::{}::{}::{}",
vendor_string,
class_string,
group_string,
sub_group_string,
);
FileRef::vec_from_children(node.children())
} else {
Vec::new()
};
Ok(Self {
vendor,
class,
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Bundle {
}

impl FromElem for Bundle {
fn from_elem(e: &Element) -> Result<Self, Error> {
fn from_elem(e: &Node) -> Result<Self, Error> {
assert_root_name(e, "bundle")?;
let name: String = attr_map(e, "Cbundle")?;
let class: String = attr_map(e, "Cclass")?;
Expand All @@ -198,8 +198,8 @@ impl FromElem for Bundle {
let components = e
.children()
.filter_map(move |chld| {
if chld.name() == "component" {
ComponentBuilder::from_elem(chld).ok()
if chld.tag_name().name() == "component" {
ComponentBuilder::from_elem(&chld).ok()
} else {
None
}
Expand All @@ -217,10 +217,8 @@ impl FromElem for Bundle {
}
}

fn child_to_component_iter(
e: &Element,
) -> Result<Box<dyn Iterator<Item = ComponentBuilder>>, Error> {
match e.name() {
fn child_to_component_iter(e: &Node) -> Result<Box<dyn Iterator<Item = ComponentBuilder>>, Error> {
match e.tag_name().name() {
"bundle" => {
let bundle = Bundle::from_elem(e)?;
Ok(Box::new(bundle.into_components().into_iter()))
Expand All @@ -230,8 +228,9 @@ fn child_to_component_iter(
Ok(Box::new(Some(component).into_iter()))
}
_ => Err(format_err!(
"element of name {} is not allowed as a descendant of components",
e.name()
"element of name {} is not allowed as a descendant of components ({:?})",
e.tag_name().name(),
e
)),
}
}
Expand All @@ -240,11 +239,12 @@ fn child_to_component_iter(
pub struct ComponentBuilders(pub(crate) Vec<ComponentBuilder>);

impl FromElem for ComponentBuilders {
fn from_elem(e: &Element) -> Result<Self, Error> {
fn from_elem(e: &Node) -> Result<Self, Error> {
assert_root_name(e, "components")?;
Ok(ComponentBuilders(
e.children()
.flat_map(move |c| match child_to_component_iter(c) {
.filter(|e| e.is_element())
.flat_map(move |c| match child_to_component_iter(&c) {
Ok(iter) => iter,
Err(e) => {
log::error!("when trying to parse component: {}", e);
Expand Down
Loading
Loading