From 7c86dd407041b01b010a55609ad737853024c03d Mon Sep 17 00:00:00 2001 From: Andreas Wallner <20979738+andreasWallnerIFX@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:32:39 +0000 Subject: [PATCH 1/4] Add initial CI --- .github/workflows/check-and-lint.yaml | 86 +++++++++++++++++++++++++++ .github/workflows/test.yaml | 34 +++++++++++ 2 files changed, 120 insertions(+) create mode 100644 .github/workflows/check-and-lint.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/check-and-lint.yaml b/.github/workflows/check-and-lint.yaml new file mode 100644 index 0000000..6664859 --- /dev/null +++ b/.github/workflows/check-and-lint.yaml @@ -0,0 +1,86 @@ +name: Check and Lint + +on: [push, pull_request] + +env: + CARGO_TERM_COLOR: always + +jobs: + check: + name: Cargo check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Get toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: cargo check + - run: cargo check --all-features + + clippy: + name: Lint with Clippy + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Get toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: clippy + override: true + - run: cargo clippy --all-features -- -D warnings + + format: + name: Check formatting + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Get toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - run: cargo fmt --all -- --check + + doc: + name: Lint Documentation + runs-on: ubuntu-latest + env: + RUSTDOCFLAGS: -D warnings + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Get toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Check documentation + run: cargo doc --no-deps --all-features --document-private-items + + cargo-deny: + runs-on: ubuntu-latest + strategy: + matrix: + checks: + - advisories + - bans licenses sources + + # Prevent sudden announcement of a new advisory from failing ci: + continue-on-error: ${{ matrix.checks == 'advisories' }} + + steps: + - uses: actions/checkout@v3 + - uses: EmbarkStudios/cargo-deny-action@v1 + with: + command: check ${{ matrix.checks }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..42c1419 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,34 @@ +name: Test + +on: [push, pull_request] + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Get toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Cache dependencies + uses: actions/cache@v2 + env: + cache-name: cache-dependencies + with: + path: | + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + ~/.cargo/bin + ~/.cargo/registry/index + ~/.cargo/registry/cache + target + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }} + - run: cargo test --verbose --all -- --nocapture From a10d0788dfb0589630765812aa9629a6da56af46 Mon Sep 17 00:00:00 2001 From: Andreas Wallner <20979738+andreasWallnerIFX@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:40:43 +0000 Subject: [PATCH 2/4] Fix clippy warnings --- src/rust_gen/xml2ir.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rust_gen/xml2ir.rs b/src/rust_gen/xml2ir.rs index 9634075..217a2e6 100644 --- a/src/rust_gen/xml2ir.rs +++ b/src/rust_gen/xml2ir.rs @@ -267,7 +267,7 @@ fn get_cluster( if !registers.is_empty() || !clusters.is_empty() { error!("Cluster with derivedFrom attributes are supported only if they doesn't contains registers and/or clusters. Included registers and clusters are ignored") } - get_parent_struct_name_cluster(device, container, &derived_path) + get_parent_struct_name_cluster(device, container, derived_path) } else { let mut struct_name = cluster.struct_name().to_sanitized_struct_ident(); struct_name.insert_str(0, "self::"); @@ -367,7 +367,7 @@ fn get_peripherals_types( /// # Result /// /// Device containing all information of svd file -fn parse_xml(xml: &mut String, svd_validation_level: SvdValidationLevel) -> Result { +fn parse_xml(xml: &mut str, svd_validation_level: SvdValidationLevel) -> Result { let mut parser_config = svd_parser::Config::default(); parser_config.expand_properties = true; parser_config.ignore_enums = false; @@ -412,7 +412,7 @@ fn get_interrupt_table( } pub(super) fn parse_xml2ir( - xml: &mut String, + xml: &mut str, svd_validation_level: SvdValidationLevel, custom_license_text: &Option, ) -> Result { From b7a49cc3f427706e0cf417f2a3c96ae363bcfb9c Mon Sep 17 00:00:00 2001 From: Andreas Wallner <20979738+andreasWallnerIFX@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:55:07 +0200 Subject: [PATCH 3/4] Fix formatting --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0e95b9c..cda58ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ //! - Support [tracing](#tracing) of register accesses and additionally mocking of registers on non-embedded devices through //! external libraries. This allows the execution unit tests for code that uses the generated libraries on non-embedded devices. //! - PAC shall have ideally 0 dependencies to any other crates. -//! +//! //! # chiptool features implemented by `svd2pac` //! //! - No owned data structure -> unsafe api that can be used from any interrupts or thread. @@ -33,10 +33,10 @@ //! - Support also for 8,16,64 bit size registers. //! - Avoid long type and bitfield names (chiptool concatenates identifiers) by generating modules for registers and svd clusters. //! - No support for SVD transformation. -//! +//! //! # Limitations //! -//! * Inheritance via `derivedFrom` attribute is supported only in `cluster` declaration and requires +//! * Inheritance via `derivedFrom` attribute is supported only in `cluster` declaration and requires //! that child is not overriding anything except `name`, `description` and `offset` //! * `headerStructName` tag is considered only in `cluster`` tag //! * `resetMask` tag is ignored From 2db2d37fa6581a810e76d8648fed0335a6257b54 Mon Sep 17 00:00:00 2001 From: Andreas Wallner <20979738+andreasWallnerIFX@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:55:07 +0200 Subject: [PATCH 4/4] Prevent triggering workflows twice Workflows are currently triggered twice if the branch being PR'd is in the repo. Limit to main branch only. --- .github/workflows/check-and-lint.yaml | 6 +++++- .github/workflows/test.yaml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-and-lint.yaml b/.github/workflows/check-and-lint.yaml index 6664859..f10d3e5 100644 --- a/.github/workflows/check-and-lint.yaml +++ b/.github/workflows/check-and-lint.yaml @@ -1,6 +1,10 @@ name: Check and Lint -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 42c1419..b7cffbb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,6 +1,10 @@ name: Test -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: env: CARGO_TERM_COLOR: always