From 20880fe8b95bd9be0d27a98e8f833ab6b771a07a Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 2 Oct 2024 10:18:52 +0200 Subject: [PATCH] static_tests: Add test for Rust code formatting rules --- dist/tools/cargo-checks/check.sh | 31 +++++++++++++++++++++++++++++++ dist/tools/ci/static_tests.sh | 1 + 2 files changed, 32 insertions(+) create mode 100755 dist/tools/cargo-checks/check.sh diff --git a/dist/tools/cargo-checks/check.sh b/dist/tools/cargo-checks/check.sh new file mode 100755 index 000000000000..41303832f83c --- /dev/null +++ b/dist/tools/cargo-checks/check.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +set -eu + +FAILURES="" + +# This is a Make based environment, therefore we don't have funny names to take +# care of, and anyone who can cause commands to be run by injecting files can +# just as well modify the scripts being run. (Otherwise we'd need to go through +# a less readable print0 / read). +for CARGOTOML in `find -name Cargo.toml` +do + if cargo fmt --quiet --check --manifest-path "${CARGOTOML}"; then + continue + else + FAILURES="${FAILURES} ${CARGOTOML%Cargo.toml}" + fi +done + +if [ x"" != x"${FAILURES}" ]; then + echo "Some Rust files are following rustfmt, in particular in:" + echo "${FAILURES}" + echo "You can format the code locally using:" + echo + echo "find -name Cargo.toml -exec cargo fmt --manifest-path '{}' ';'" + if [ ! -z "${GITHUB_RUN_ID:-}" ]; then + echo + echo "The author of this test regrets not knowing how to provide an easy way to just click a button here that provides the right fixup commits." + fi + exit 1 +fi diff --git a/dist/tools/ci/static_tests.sh b/dist/tools/ci/static_tests.sh index fd78944ffabc..869b607dc634 100755 --- a/dist/tools/ci/static_tests.sh +++ b/dist/tools/ci/static_tests.sh @@ -128,6 +128,7 @@ run ./dist/tools/buildsystem_sanity_check/check.sh run ./dist/tools/feature_resolution/check.sh run ./dist/tools/boards_supported/check.sh run ./dist/tools/codespell/check.sh +run ./dist/tools/cargo-checks/check.sh if [ -z "${GITHUB_RUN_ID}" ]; then run ./dist/tools/uncrustify/uncrustify.sh --check else