Skip to content

Commit 2b330c9

Browse files
bors[bot]burrbull
andauthored
Merge #111
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]>
2 parents 13dfa20 + 237aeec commit 2b330c9

File tree

9 files changed

+201
-52
lines changed

9 files changed

+201
-52
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: CI
22

3+
env:
4+
SVDTOOLS: svd
5+
36
on:
47
push:
58
branches: [ staging, trying, master ]
@@ -11,7 +14,7 @@ jobs:
1114
runs-on: ubuntu-latest
1215
steps:
1316
- name: Checkout code
14-
uses: actions/checkout@v2
17+
uses: actions/checkout@v3
1518
- name: Install Python
1619
uses: actions/setup-python@v2
1720
with:
@@ -40,7 +43,7 @@ jobs:
4043
- rp2040
4144
steps:
4245
- name: Checkout code
43-
uses: actions/checkout@v2
46+
uses: actions/checkout@v3
4447
- name: Install Rust
4548
uses: actions-rs/toolchain@v1
4649
with:

.github/workflows/release.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- v*.*.*
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
strategy:
13+
matrix:
14+
include:
15+
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, suffix: .gz }
16+
- { target: x86_64-apple-darwin, os: macos-latest, suffix: .gz }
17+
- { target: aarch64-apple-darwin, os: macos-latest, suffix: .gz }
18+
- { target: x86_64-pc-windows-msvc, os: windows-latest, suffix: .zip }
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: stable
25+
profile: minimal
26+
target: ${{ matrix.target }}
27+
override: true
28+
- name: Cache Dependencies
29+
uses: Swatinem/rust-cache@v1
30+
with:
31+
key: ${{ matrix.target }}
32+
- uses: actions-rs/cargo@v1
33+
with:
34+
command: build
35+
args: --target ${{ matrix.target }} --release
36+
37+
- name: (Not Windows) Move executables and compress
38+
if: ${{ matrix.os != 'windows-latest' }}
39+
run: gzip -c target/${{ matrix.target }}/release/svdtools > svdtools-${{ matrix.target }}${{ matrix.suffix }}
40+
41+
- name: (Windows) Move executables and compress
42+
if: ${{ matrix.os == 'windows-latest' }}
43+
run: Compress-Archive -Path target\${{ matrix.target }}\release\svdtools.exe -DestinationPath svdtools-${{ matrix.target }}${{ matrix.suffix }}
44+
45+
- uses: actions/upload-artifact@v3
46+
with:
47+
name: svdtools-${{ matrix.target }}
48+
path: svdtools-${{ matrix.target }}${{ matrix.suffix }}
49+
50+
release:
51+
name: release
52+
runs-on: ubuntu-latest
53+
needs: [build]
54+
steps:
55+
- uses: actions/checkout@v3
56+
- uses: actions/download-artifact@v3
57+
with:
58+
path: artifacts
59+
- run: ls -R ./artifacts
60+
61+
- name: Set current date as environment variable
62+
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
63+
64+
- id: changelog-reader
65+
uses: mindsers/[email protected]
66+
with:
67+
path: ./CHANGELOG-rust.md
68+
version: ${{ (github.ref_type == 'tag' && github.ref_name) || 'Unreleased' }}
69+
70+
- uses: softprops/action-gh-release@v1
71+
with:
72+
tag_name: ${{ steps.changelog-reader.outputs.version }}
73+
name: ${{ (github.ref_type == 'tag' && steps.changelog-reader.outputs.version) || format('Prereleased {0}', env.CURRENT_DATE) }}
74+
body: ${{ steps.changelog-reader.outputs.changes }}
75+
prerelease: ${{ steps.changelog-reader.outputs.status == 'unreleased' }}
76+
files: |
77+
artifacts/**/*

.github/workflows/rust-ci.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Rust CI
22

3+
env:
4+
SVDTOOLS: svdtools
5+
36
on:
47
push:
58
branches: [ staging, trying, master ]
@@ -13,7 +16,7 @@ jobs:
1316
RUSTFLAGS: "-D warnings"
1417
RUSTDOCFLAGS: "-D warnings"
1518
steps:
16-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v3
1720
- uses: actions-rs/toolchain@v1
1821
with:
1922
toolchain: stable
@@ -26,7 +29,7 @@ jobs:
2629
RUSTFLAGS: "-D warnings"
2730
runs-on: ubuntu-latest
2831
steps:
29-
- uses: actions/checkout@v2
32+
- uses: actions/checkout@v3
3033
- uses: actions-rs/toolchain@v1
3134
with:
3235
toolchain: stable
@@ -38,7 +41,7 @@ jobs:
3841
RUSTFLAGS: "-D warnings"
3942
runs-on: ubuntu-latest
4043
steps:
41-
- uses: actions/checkout@v2
44+
- uses: actions/checkout@v3
4245
- uses: actions-rs/toolchain@v1
4346
with:
4447
toolchain: stable
@@ -52,7 +55,7 @@ jobs:
5255
name: Clippy
5356
runs-on: ubuntu-latest
5457
steps:
55-
- uses: actions/checkout@v2
58+
- uses: actions/checkout@v3
5659
- uses: actions-rs/toolchain@v1
5760
with:
5861
toolchain: stable
@@ -65,7 +68,7 @@ jobs:
6568
name: Format
6669
runs-on: ubuntu-latest
6770
steps:
68-
- uses: actions/checkout@v2
71+
- uses: actions/checkout@v3
6972
- uses: actions-rs/toolchain@v1
7073
with:
7174
toolchain: stable
@@ -80,7 +83,7 @@ jobs:
8083
- stm32
8184
steps:
8285
- name: Checkout code
83-
uses: actions/checkout@v2
86+
uses: actions/checkout@v3
8487
- name: Install Rust
8588
uses: actions-rs/toolchain@v1
8689
with:
@@ -92,4 +95,4 @@ jobs:
9295
run: |
9396
cargo install svdtools --path .
9497
- name: Check
95-
run: env SVDTOOLS=svdtools bash tools/check_${{ matrix.target }}.sh
98+
run: bash tools/check_${{ matrix.target }}.sh

CHANGELOG-rust.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This changelog tracks the Rust `svdtools` project. See
55

66
## [Unreleased]
77

8+
* Added action to build binaries and release for every version tag and latest commit
9+
* Use `svd-parser` 0.13.4, add `expand_properties` option in `convert`
10+
* `patch`: check enum `usage`, don't add it if unneeded
11+
812
## [v0.2.3] 2022-05-01
913

1014
* Add support for `modifiedWriteValues` & `readAction` for fields

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ clap = { version = "3.0", features = ["derive"] }
2828
serde = { version = "1.0", features = ["derive"] }
2929
quick-xml = { version = "0.18", features = ["serialize"] }
3030
svd-rs = { version = "0.13.2", features = ["serde", "derive-from"] }
31-
svd-parser = { version = "0.13.2", features = ["expand"] }
31+
svd-parser = { version = "0.13.4", features = ["expand"] }
3232
svd-encoder = "0.13.1"
3333
yaml-rust = "0.4"
3434
serde_yaml = "0.8.23"

src/cli.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ enum Command {
6464
#[clap(long)]
6565
expand: bool,
6666

67+
/// Take size, access, reset_value, reset_mask from parents if absent in register
68+
#[clap(long)]
69+
expand_properties: bool,
70+
6771
/// Skip enumeratedValues and writeConstraints during parsing (XML input only)
6872
#[clap(long)]
6973
ignore_enums: bool,
@@ -88,13 +92,15 @@ impl Command {
8892
input_format,
8993
output_format,
9094
expand,
95+
expand_properties,
9196
ignore_enums,
9297
} => convert_cli::convert(
9398
in_path,
9499
out_path,
95100
*input_format,
96101
*output_format,
97102
*expand,
103+
*expand_properties,
98104
*ignore_enums,
99105
)?,
100106
}

src/convert/convert_cli.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub fn convert(
4949
input_format: Option<InputFormat>,
5050
output_format: Option<OutputFormat>,
5151
expand: bool,
52+
expand_properties: bool,
5253
ignore_enums: bool,
5354
) -> Result<()> {
5455
let input_format = match input_format {
@@ -69,14 +70,17 @@ pub fn convert(
6970
let mut input = String::new();
7071
File::open(in_path)?.read_to_string(&mut input)?;
7172

72-
let device = match input_format {
73+
let mut device = match input_format {
7374
InputFormat::Xml => svd_parser::parse_with_config(
7475
&input,
7576
&svd_parser::Config::default().ignore_enums(ignore_enums),
7677
)?,
7778
InputFormat::Yaml => serde_yaml::from_str(&input)?,
7879
InputFormat::Json => serde_json::from_str(&input)?,
7980
};
81+
if expand_properties {
82+
svd_parser::expand_properties(&mut device);
83+
}
8084
let device = if expand {
8185
svd_parser::expand(&device)?
8286
} else {

src/patch/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ fn get_register_properties(h: &Hash) -> Result<RegisterProperties> {
220220
.reset_mask(h.get_u64("resetMask")?))
221221
}
222222

223-
fn make_ev_name(name: &str, usage: Usage) -> Result<String> {
223+
fn make_ev_name(name: &str, usage: Option<Usage>) -> Result<String> {
224224
if name.as_bytes()[0].is_ascii_digit() {
225225
return Err(anyhow!(
226226
"enumeratedValue {}: can't start with a number",
227227
name
228228
));
229229
}
230230
Ok(name.to_string()
231-
+ match usage {
231+
+ match usage.unwrap_or_default() {
232232
Usage::Read => "R",
233233
Usage::Write => "W",
234234
Usage::ReadWrite => "",

0 commit comments

Comments
 (0)