Skip to content

Commit

Permalink
Merge #111
Browse files Browse the repository at this point in the history
111: enum usage + expand_properties r=adamgreig a=burrbull

Closes #110 for rust svdtools version

Require stm32-rs/stm32-rs#734

Co-authored-by: Andrey Zgarbul <[email protected]>
  • Loading branch information
bors[bot] and burrbull authored May 15, 2022
2 parents 13dfa20 + 237aeec commit 2b330c9
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 52 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

env:
SVDTOOLS: svd

on:
push:
branches: [ staging, trying, master ]
Expand All @@ -11,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v2
with:
Expand Down Expand Up @@ -40,7 +43,7 @@ jobs:
- rp2040
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: release
on:
push:
branches:
- master
tags:
- v*.*.*
workflow_dispatch:

jobs:
build:
strategy:
matrix:
include:
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, suffix: .gz }
- { target: x86_64-apple-darwin, os: macos-latest, suffix: .gz }
- { target: aarch64-apple-darwin, os: macos-latest, suffix: .gz }
- { target: x86_64-pc-windows-msvc, os: windows-latest, suffix: .zip }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
target: ${{ matrix.target }}
override: true
- name: Cache Dependencies
uses: Swatinem/rust-cache@v1
with:
key: ${{ matrix.target }}
- uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.target }} --release

- name: (Not Windows) Move executables and compress
if: ${{ matrix.os != 'windows-latest' }}
run: gzip -c target/${{ matrix.target }}/release/svdtools > svdtools-${{ matrix.target }}${{ matrix.suffix }}

- name: (Windows) Move executables and compress
if: ${{ matrix.os == 'windows-latest' }}
run: Compress-Archive -Path target\${{ matrix.target }}\release\svdtools.exe -DestinationPath svdtools-${{ matrix.target }}${{ matrix.suffix }}

- uses: actions/upload-artifact@v3
with:
name: svdtools-${{ matrix.target }}
path: svdtools-${{ matrix.target }}${{ matrix.suffix }}

release:
name: release
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts
- run: ls -R ./artifacts

- name: Set current date as environment variable
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

- id: changelog-reader
uses: mindsers/[email protected]
with:
path: ./CHANGELOG-rust.md
version: ${{ (github.ref_type == 'tag' && github.ref_name) || 'Unreleased' }}

- uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.changelog-reader.outputs.version }}
name: ${{ (github.ref_type == 'tag' && steps.changelog-reader.outputs.version) || format('Prereleased {0}', env.CURRENT_DATE) }}
body: ${{ steps.changelog-reader.outputs.changes }}
prerelease: ${{ steps.changelog-reader.outputs.status == 'unreleased' }}
files: |
artifacts/**/*
17 changes: 10 additions & 7 deletions .github/workflows/rust-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Rust CI

env:
SVDTOOLS: svdtools

on:
push:
branches: [ staging, trying, master ]
Expand All @@ -13,7 +16,7 @@ jobs:
RUSTFLAGS: "-D warnings"
RUSTDOCFLAGS: "-D warnings"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -26,7 +29,7 @@ jobs:
RUSTFLAGS: "-D warnings"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -38,7 +41,7 @@ jobs:
RUSTFLAGS: "-D warnings"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -52,7 +55,7 @@ jobs:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -65,7 +68,7 @@ jobs:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -80,7 +83,7 @@ jobs:
- stm32
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
Expand All @@ -92,4 +95,4 @@ jobs:
run: |
cargo install svdtools --path .
- name: Check
run: env SVDTOOLS=svdtools bash tools/check_${{ matrix.target }}.sh
run: bash tools/check_${{ matrix.target }}.sh
4 changes: 4 additions & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This changelog tracks the Rust `svdtools` project. See

## [Unreleased]

* Added action to build binaries and release for every version tag and latest commit
* Use `svd-parser` 0.13.4, add `expand_properties` option in `convert`
* `patch`: check enum `usage`, don't add it if unneeded

## [v0.2.3] 2022-05-01

* Add support for `modifiedWriteValues` & `readAction` for fields
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ clap = { version = "3.0", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
quick-xml = { version = "0.18", features = ["serialize"] }
svd-rs = { version = "0.13.2", features = ["serde", "derive-from"] }
svd-parser = { version = "0.13.2", features = ["expand"] }
svd-parser = { version = "0.13.4", features = ["expand"] }
svd-encoder = "0.13.1"
yaml-rust = "0.4"
serde_yaml = "0.8.23"
Expand Down
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ enum Command {
#[clap(long)]
expand: bool,

/// Take size, access, reset_value, reset_mask from parents if absent in register
#[clap(long)]
expand_properties: bool,

/// Skip enumeratedValues and writeConstraints during parsing (XML input only)
#[clap(long)]
ignore_enums: bool,
Expand All @@ -88,13 +92,15 @@ impl Command {
input_format,
output_format,
expand,
expand_properties,
ignore_enums,
} => convert_cli::convert(
in_path,
out_path,
*input_format,
*output_format,
*expand,
*expand_properties,
*ignore_enums,
)?,
}
Expand Down
6 changes: 5 additions & 1 deletion src/convert/convert_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub fn convert(
input_format: Option<InputFormat>,
output_format: Option<OutputFormat>,
expand: bool,
expand_properties: bool,
ignore_enums: bool,
) -> Result<()> {
let input_format = match input_format {
Expand All @@ -69,14 +70,17 @@ pub fn convert(
let mut input = String::new();
File::open(in_path)?.read_to_string(&mut input)?;

let device = match input_format {
let mut device = match input_format {
InputFormat::Xml => svd_parser::parse_with_config(
&input,
&svd_parser::Config::default().ignore_enums(ignore_enums),
)?,
InputFormat::Yaml => serde_yaml::from_str(&input)?,
InputFormat::Json => serde_json::from_str(&input)?,
};
if expand_properties {
svd_parser::expand_properties(&mut device);
}
let device = if expand {
svd_parser::expand(&device)?
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/patch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ fn get_register_properties(h: &Hash) -> Result<RegisterProperties> {
.reset_mask(h.get_u64("resetMask")?))
}

fn make_ev_name(name: &str, usage: Usage) -> Result<String> {
fn make_ev_name(name: &str, usage: Option<Usage>) -> Result<String> {
if name.as_bytes()[0].is_ascii_digit() {
return Err(anyhow!(
"enumeratedValue {}: can't start with a number",
name
));
}
Ok(name.to_string()
+ match usage {
+ match usage.unwrap_or_default() {
Usage::Read => "R",
Usage::Write => "W",
Usage::ReadWrite => "",
Expand Down
Loading

0 comments on commit 2b330c9

Please sign in to comment.