From 5b1a14d8b243077e6c3e2cfdde4e6b6401b197bb Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 23 Aug 2024 21:19:05 +0300 Subject: [PATCH] github: workflows: Improve compliance check Add compliance check configuration files from the Zephyr main tree, and make sure the necessary python dependencies are installed (this is also taken from the main tree compliance workflow). Signed-off-by: Johan Hedberg --- .clang-format | 105 +++++++++++++++++++++++++++++++ .editorconfig | 92 +++++++++++++++++++++++++++ .github/workflows/compliance.yml | 4 ++ .gitlint | 61 ++++++++++++++++++ .yamllint | 16 +++++ 5 files changed, 278 insertions(+) create mode 100644 .clang-format create mode 100644 .editorconfig create mode 100644 .gitlint create mode 100644 .yamllint diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..2b438bf --- /dev/null +++ b/.clang-format @@ -0,0 +1,105 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Note: The list of ForEachMacros can be obtained using: +# +# git grep -h '^#define [^[:space:]]*FOR_EACH[^[:space:]]*(' include/ \ +# | sed "s,^#define \([^[:space:]]*FOR_EACH[^[:space:]]*\)(.*$, - '\1'," \ +# | sort | uniq +# +# References: +# - https://clang.llvm.org/docs/ClangFormatStyleOptions.html + +--- +BasedOnStyle: LLVM +AlignConsecutiveMacros: AcrossComments +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AttributeMacros: + - __aligned + - __deprecated + - __packed + - __printf_like + - __syscall + - __syscall_always_inline + - __subsystem +BitFieldColonSpacing: After +BreakBeforeBraces: Linux +ColumnLimit: 100 +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 8 +ForEachMacros: + - 'ARRAY_FOR_EACH' + - 'ARRAY_FOR_EACH_PTR' + - 'FOR_EACH' + - 'FOR_EACH_FIXED_ARG' + - 'FOR_EACH_IDX' + - 'FOR_EACH_IDX_FIXED_ARG' + - 'FOR_EACH_NONEMPTY_TERM' + - 'FOR_EACH_FIXED_ARG_NONEMPTY_TERM' + - 'RB_FOR_EACH' + - 'RB_FOR_EACH_CONTAINER' + - 'SYS_DLIST_FOR_EACH_CONTAINER' + - 'SYS_DLIST_FOR_EACH_CONTAINER_SAFE' + - 'SYS_DLIST_FOR_EACH_NODE' + - 'SYS_DLIST_FOR_EACH_NODE_SAFE' + - 'SYS_SFLIST_FOR_EACH_CONTAINER' + - 'SYS_SFLIST_FOR_EACH_CONTAINER_SAFE' + - 'SYS_SFLIST_FOR_EACH_NODE' + - 'SYS_SFLIST_FOR_EACH_NODE_SAFE' + - 'SYS_SLIST_FOR_EACH_CONTAINER' + - 'SYS_SLIST_FOR_EACH_CONTAINER_SAFE' + - 'SYS_SLIST_FOR_EACH_NODE' + - 'SYS_SLIST_FOR_EACH_NODE_SAFE' + - '_WAIT_Q_FOR_EACH' + - 'Z_FOR_EACH' + - 'Z_FOR_EACH_ENGINE' + - 'Z_FOR_EACH_EXEC' + - 'Z_FOR_EACH_FIXED_ARG' + - 'Z_FOR_EACH_FIXED_ARG_EXEC' + - 'Z_FOR_EACH_IDX' + - 'Z_FOR_EACH_IDX_EXEC' + - 'Z_FOR_EACH_IDX_FIXED_ARG' + - 'Z_FOR_EACH_IDX_FIXED_ARG_EXEC' + - 'Z_GENLIST_FOR_EACH_CONTAINER' + - 'Z_GENLIST_FOR_EACH_CONTAINER_SAFE' + - 'Z_GENLIST_FOR_EACH_NODE' + - 'Z_GENLIST_FOR_EACH_NODE_SAFE' + - 'STRUCT_SECTION_FOREACH' + - 'STRUCT_SECTION_FOREACH_ALTERNATE' + - 'TYPE_SECTION_FOREACH' + - 'K_SPINLOCK' + - 'COAP_RESOURCE_FOREACH' + - 'COAP_SERVICE_FOREACH' + - 'COAP_SERVICE_FOREACH_RESOURCE' + - 'HTTP_RESOURCE_FOREACH' + - 'HTTP_SERVER_CONTENT_TYPE_FOREACH' + - 'HTTP_SERVICE_FOREACH' + - 'HTTP_SERVICE_FOREACH_RESOURCE' +IfMacros: + - 'CHECKIF' +# Disabled for now, see bug https://github.com/zephyrproject-rtos/zephyr/issues/48520 +#IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^".*\.h"$' + Priority: 0 + - Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$' + Priority: 1 + - Regex: '^\$' + Priority: 2 + - Regex: '.*' + Priority: 3 +IndentCaseLabels: false +IndentGotoLabels: false +IndentWidth: 8 +InsertBraces: true +SpaceBeforeInheritanceColon: False +SpaceBeforeParens: ControlStatementsExceptControlMacros +SortIncludes: Never +UseTab: ForContinuationAndIndentation +WhitespaceSensitiveMacros: + - STRINGIFY + - Z_STRINGIFY diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..988cb95 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,92 @@ +# EditorConfig: https://editorconfig.org/ + +# top-most EditorConfig file +root = true + +# All (Defaults) +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +max_line_length = 100 + +# Assembly +[*.S] +indent_style = tab +indent_size = 8 + +# C +[*.{c,h}] +indent_style = tab +indent_size = 8 + +# C++ +[*.{cpp,hpp}] +indent_style = tab +indent_size = 8 + +# Linker Script +[*.ld] +indent_style = tab +indent_size = 8 + +# Python +[*.py] +indent_style = space +indent_size = 4 + +# Perl +[*.pl] +indent_style = tab +indent_size = 8 + +# reStructuredText +[*.rst] +indent_style = space +indent_size = 3 + +# YAML +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +# Shell Script +[*.sh] +indent_style = space +indent_size = 4 + +# Windows Command Script +[*.cmd] +end_of_line = crlf +indent_style = tab +indent_size = 8 + +# Valgrind Suppression File +[*.supp] +indent_style = space +indent_size = 3 + +# CMake +[{CMakeLists.txt,*.cmake}] +indent_style = space +indent_size = 2 + +# Makefile +[Makefile] +indent_style = tab +indent_size = 8 + +# Device tree +[*.{dts,dtsi,overlay}] +indent_style = tab +indent_size = 8 + +# Git commit messages +[COMMIT_EDITMSG] +max_line_length = 75 + +# Kconfig +[Kconfig*] +indent_style = tab +indent_size = 8 diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index 46882fc..afd66d2 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -30,6 +30,10 @@ jobs: app-path: zephyr-silabs toolchains: arm-zephyr-eabi + - name: Install compliance-specific python dependencies + run: | + pip3 install python-magic lxml junitparser gitlint pylint pykwalify yamllint clang-format unidiff + - name: Run Compliance Tests continue-on-error: true id: compliance diff --git a/.gitlint b/.gitlint new file mode 100644 index 0000000..2eb381b --- /dev/null +++ b/.gitlint @@ -0,0 +1,61 @@ +# All these sections are optional, edit this file as you like. +# Zephyr-specific defaults are located in scripts/gitlint/zephyr_commit_rules.py +[general] +ignore=title-trailing-punctuation, T3, title-max-length, T1, body-hard-tab, B3, B1 +# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this +verbosity = 3 +# By default gitlint will ignore merge commits. Set to 'false' to disable. +ignore-merge-commits=false +ignore-revert-commits=false +ignore-fixup-commits=false +ignore-squash-commits=false +# Enable debug mode (prints more output). Disabled by default +debug = false + +# Set the extra-path where gitlint will search for user defined rules +# See http://jorisroovers.github.io/gitlint/user_defined_rules for details +extra-path=../zephyr/scripts/gitlint + +[title-max-length-no-revert] +# line-length=75 + +[body-min-line-count] +# min-line-count=1 + +[body-max-line-count] +# max-line-count=200 + +[title-starts-with-subsystem] +regex = ^(?!subsys:)(?!treewide:)(([^:]+):)(\s([^:]+):)*\s(.+)$ + +[title-must-not-contain-word] +# Comma-separated list of words that should not occur in the title. Matching is case +# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING" +# will not cause a violation, but "WIP: my title" will. +words=wip + +[title-match-regex] +# python like regex (https://docs.python.org/2/library/re.html) that the +# commit-msg title must be matched to. +# Note that the regex can contradict with other rules if not used correctly +# (e.g. title-must-not-contain-word). +#regex=^US[0-9]* + +[max-line-length-with-exceptions] +# B1 = body-max-line-length +# line-length=75 + +[body-min-length] +min-length=3 + +[body-is-missing] +# Whether to ignore this rule on merge commits (which typically only have a title) +# default = True +ignore-merge-commits=false + +[body-changed-file-mention] +# List of files that need to be explicitly mentioned in the body when they are changed +# This is useful for when developers often erroneously edit certain files or git submodules. +# By specifying this rule, developers can only change the file when they explicitly reference +# it in the commit message. +#files=gitlint/rules.py,README.md diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..73bafc2 --- /dev/null +++ b/.yamllint @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: Apache-2.0 + +extends: default + +rules: + line-length: + max: 100 + comments: + min-spaces-from-content: 1 + indentation: + spaces: 2 + indent-sequences: consistent + document-start: + present: false + truthy: + check-keys: false