Skip to content

Commit

Permalink
Merge pull request #184 from rust-embedded/post-validate
Browse files Browse the repository at this point in the history
post patch validate
  • Loading branch information
Emilgardis authored Dec 21, 2023
2 parents 9537e0f + f2a55ba commit ce20880
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This changelog tracks the Rust `svdtools` project. See
* Strip `alternateRegister` too
* Add `modifiedWriteValues` and `readAction` field patch (#156)
* Fix #144
* Flag to check for errors after patching

## [v0.3.6] 2023-11-01

Expand Down
8 changes: 8 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ enum Command {
#[clap(long)]
format_config: Option<PathBuf>,

/// Check for errors after patching
#[clap(long)]
post_validate: bool,

/// When a patch error happens print formatted yaml with all rules included
#[clap(long)]
show_patch_on_error: bool,
Expand Down Expand Up @@ -125,10 +129,14 @@ impl Command {
yaml_file,
out_path,
format_config,
post_validate,
show_patch_on_error,
enum_derive,
} => {
let mut config = svdtools::patch::Config::default();
if *post_validate {
config.post_validate = svd_rs::ValidateLevel::Strict;
}
config.show_patch_on_error = *show_patch_on_error;
if let Some(enum_derive) = enum_derive.as_ref() {
config.enum_derive = *enum_derive;
Expand Down
4 changes: 4 additions & 0 deletions src/patch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const VAL_LVL: ValidateLevel = ValidateLevel::Weak;
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct Config {
pub post_validate: ValidateLevel,
pub show_patch_on_error: bool,
pub enum_derive: EnumAutoDerive,
pub update_fields: bool,
Expand All @@ -56,6 +57,7 @@ pub enum EnumAutoDerive {
impl Default for Config {
fn default() -> Self {
Self {
post_validate: ValidateLevel::Disabled,
show_patch_on_error: false,
enum_derive: Default::default(),
update_fields: true,
Expand Down Expand Up @@ -115,6 +117,8 @@ pub fn process_file(
}
})?;

svd.validate_all(config.post_validate)?;

// SVD should now be updated, write it out
let config = get_encoder_config(format_config)?;
let svd_out = svd_encoder::encode_with_config(&svd, &config)?;
Expand Down

0 comments on commit ce20880

Please sign in to comment.