From 9ed40e87fb17952c87475d9daeec1973cf354494 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Mon, 22 Mar 2021 14:46:48 -0700 Subject: [PATCH 01/14] scripts: coccinelle: Check rule 5.7 This coccinelle script can check some violations for rule 5.7. It can identify things like: struct device *device But it is not capable to identify: struct test { ... } ... int test; Signed-off-by: Flavio Ceolin --- scripts/coccinelle/same_identifier.cocci | 76 ++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 scripts/coccinelle/same_identifier.cocci diff --git a/scripts/coccinelle/same_identifier.cocci b/scripts/coccinelle/same_identifier.cocci new file mode 100644 index 0000000000000..8bb3bdcd1663e --- /dev/null +++ b/scripts/coccinelle/same_identifier.cocci @@ -0,0 +1,76 @@ +// Check violations for rule 5.7 +// https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_05_07.c +// +// Confidence: Moderate +// Copyright: (C) 2020 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 + +virtual report + +@initialize:python@ +@@ + +@common_case@ +position p; +identifier t, v; +@@ +( +struct t *v@p; +| +struct t v@p; +| +union t v@p; +) + +@ script:python @ +t << common_case.t; +v << common_case.v; +p << common_case.p; +@@ + +msg = "WARNING: Violation to rule 5.7 (Tag name should be unique) tag: {}".format(v) +if t == v: + coccilib.report.print_report(p[0], msg) + +@per_type@ +type T; +identifier v; +position p; +@@ +( +T v@p; +| +T *v@p; +) + +@ script:python @ +t << per_type.T; +v << per_type.v; +p << per_type.p; +@@ + +msg = "WARNING: Violation to rule 5.7 (Tag name should be unique) tag: {}".format(v) +if t == v: + coccilib.report.print_report(p[0], msg) + +@function_match@ +type T1, T2; +identifier function, v; +position p; +parameter list[n] P1; +parameter list[n1] P2; +@@ +T1 function(P1, T2 *v@p, P2) { +... +} + +@ script:python @ +v << function_match.v; +t << function_match.T2; +p << function_match.p; +@@ + +msg = "WARNING: Violation to rule 5.7 (Tag name should be unique) tag: {}".format(v) +if v == t.split(" ")[-1]: + coccilib.report.print_report(p[0], msg) From 84bb433d44a12aec4250bf0be71d334f5a16c3b5 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Mon, 22 Mar 2021 16:16:14 -0700 Subject: [PATCH 02/14] scripts: coccinelle: Check rule 21.2 This coccinelle script can check some violations for rule 21.2. Currently it is checking the follow reserved names: "remove", "rewind", "malloc", "free", "exp", "signal" It can easily be extended in the future though. Signed-off-by: Flavio Ceolin Rebnase --- scripts/coccinelle/reserved_names.cocci | 86 +++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 scripts/coccinelle/reserved_names.cocci diff --git a/scripts/coccinelle/reserved_names.cocci b/scripts/coccinelle/reserved_names.cocci new file mode 100644 index 0000000000000..688b3a9419acc --- /dev/null +++ b/scripts/coccinelle/reserved_names.cocci @@ -0,0 +1,86 @@ +// Check violations for rule 5.7 +// https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_02.c +// +// Confidence: Moderate +// Copyright: (C) 2020 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 + +virtual report + +@initialize:python@ +@@ + +@common_case@ +position p; +identifier t, v; +expression E; +type T; +@@ +( +struct t *v@p; +| +struct t v@p; +| +union t v@p; +| +T v@p; +| +T *v@p; +| +struct t *v@p = E; +| +struct t v@p = E; +| +union t v@p = E; +| +T v@p = E; +| +T *v@p = E; +) + +@ script:python @ +v << common_case.v; +p << common_case.p; +@@ + +msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v) +if v in ["remove", "rewind", "malloc", "free", "exp", "signal"]: + coccilib.report.print_report(p[0], msg) + +@function_match@ +type T; +identifier f; +position p; +@@ +T f@p(...) { +... +} + +@ script:python @ +v << function_match.f; +@@ + +msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v) +if v in ["remove", "rewind", "malloc", "free", "exp", "signal"]: + coccilib.report.print_report(p[0], msg) + +@function_parameter@ +type T1, T2; +identifier function, v; +position p; +parameter list[n] P1; +parameter list[n1] P2; +@@ +T1 function(P1, T2 *v@p, P2) { +... +} + +@ script:python @ +v << function_parameter.v; +p << function_parameter.p; +@@ + +msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v) +if v in ["remove", "rewind", "malloc", "free", "exp", "signal"]: + coccilib.report.print_report(p[0], msg) From 98220247db34ca98c5e5ccbf22d383805ba0a0d1 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Tue, 23 Mar 2021 15:06:01 -0700 Subject: [PATCH 03/14] ci: Apply coccinelle scripts in git diffs This scripts receives the same parameter of what_changed.py. And run coccinelle scripts for code guideline compliance in the given git commits. e.g: ./guideline_check.py --commits origin/master..HEAD Signed-off-by: Flavio Ceolin --- scripts/ci/guideline_check.py | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 scripts/ci/guideline_check.py diff --git a/scripts/ci/guideline_check.py b/scripts/ci/guideline_check.py new file mode 100755 index 0000000000000..e338864d44c7f --- /dev/null +++ b/scripts/ci/guideline_check.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2021 Intel Corporation + +import os +import sh +import argparse +import re +from unidiff import PatchSet + +if "ZEPHYR_BASE" not in os.environ: + exit("$ZEPHYR_BASE environment variable undefined.") + +repository_path = os.environ['ZEPHYR_BASE'] + +sh_special_args = { + '_tty_out': False, + '_cwd': repository_path +} + +coccinelle_scripts = ["/scripts/coccinelle/reserved_names.cocci", + "/scripts/coccinelle/same_identifier.cocci", + "/scripts/coccinelle/identifier_length.cocci", + ] + + +def parse_coccinelle(contents: str, violations: dict): + reg = re.compile("([a-zA-Z0-9/]*\\.[ch]:[0-9]*)(:[0-9\\-]*: )(.*)") + for line in contents.split("\n"): + r = reg.match(line) + if r: + f = r.group(1) + if f in violations: + violations[f].append(r.group(3)) + else: + violations[r.group(1)] = [r.group(3)] + + +def parse_args(): + parser = argparse.ArgumentParser( + description="Check if change requires full twister") + parser.add_argument('-c', '--commits', default=None, + help="Commit range in the form: a..b") + return parser.parse_args() + + +def main(): + args = parse_args() + if not args.commits: + exit("missing commit range") + + commit = sh.git("diff", args.commits, **sh_special_args) + patch_set = PatchSet(commit) + zephyr_base = os.getenv("ZEPHYR_BASE") + violations = {} + numViolations = 0 + + for f in patch_set: + if not f.path.endswith(".c") and not f.path.endswith(".h") or not os.path.exists(zephyr_base + "/" + f.path): + continue + + for script in coccinelle_scripts: + script_path = os.getenv("ZEPHYR_BASE") + "/" + script + cocci = sh.coccicheck( + "--mode=report", + "--cocci=" + + script_path, + f.path, + **sh_special_args) + parse_coccinelle(cocci, violations) + + for hunk in f: + for line in hunk: + if line.is_added: + violation = "{}:{}".format(f.path, line.target_line_no) + if violation in violations: + numViolations += 1 + print( + "{}:{}".format( + violation, "\t\n".join( + violations[violation]))) + + return numViolations + + +if __name__ == "__main__": + ret = main() + exit(ret) From ac12de2ca4f06de319127590866b8d69781b5e24 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Wed, 24 Mar 2021 09:33:49 -0700 Subject: [PATCH 04/14] scripts: coccinelle: Add guideline number on a script output Add information about the guideline number in the script checking a identifier length. Signed-off-by: Flavio Ceolin --- scripts/coccinelle/identifier_length.cocci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/coccinelle/identifier_length.cocci b/scripts/coccinelle/identifier_length.cocci index 29ad406d5b3d0..fee4015649da7 100644 --- a/scripts/coccinelle/identifier_length.cocci +++ b/scripts/coccinelle/identifier_length.cocci @@ -26,5 +26,5 @@ pos << r_idlen.p; @@ if (len(id) > 31): - msg="WARNING: Identifier %s length %d > 31" % (id, len(id)) + msg="WARNING: Violation to rule 5.1 or 5.2 (Identifiers shall be distinct) %s length %d > 31" % (id, len(id)) coccilib.report.print_report(pos[0], msg) From d04bf8aa952f55f874ae9344fc6127c8bcf32546 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Wed, 24 Mar 2021 15:54:16 -0700 Subject: [PATCH 05/14] ci: coccinelle: Add support to write to a file Add parameter to write the script output to a file. Signed-off-by: Flavio Ceolin --- scripts/ci/guideline_check.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/ci/guideline_check.py b/scripts/ci/guideline_check.py index e338864d44c7f..acaa68209ef21 100755 --- a/scripts/ci/guideline_check.py +++ b/scripts/ci/guideline_check.py @@ -41,6 +41,8 @@ def parse_args(): description="Check if change requires full twister") parser.add_argument('-c', '--commits', default=None, help="Commit range in the form: a..b") + parser.add_argument("-o", "--output", required=False, + help="Print violation into a file") return parser.parse_args() @@ -75,10 +77,16 @@ def main(): violation = "{}:{}".format(f.path, line.target_line_no) if violation in violations: numViolations += 1 - print( - "{}:{}".format( - violation, "\t\n".join( - violations[violation]))) + if args.output: + with open(args.output, "a+") as fp: + fp.write("{}:{}\n".format( + violation, "\t\n".join( + violations[violation]))) + else: + print( + "{}:{}".format( + violation, "\t\n".join( + violations[violation]))) return numViolations From d89a0ee2fdca8f50666a0f39e7e6f3366b302167 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Wed, 24 Mar 2021 16:18:43 -0700 Subject: [PATCH 06/14] ci: coccinelle: Suppress pylint false positive Suppress pylint false positive on 'sh' library. Signed-off-by: Flavio Ceolin --- scripts/ci/guideline_check.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/ci/guideline_check.py b/scripts/ci/guideline_check.py index acaa68209ef21..b1aff66932ceb 100755 --- a/scripts/ci/guideline_check.py +++ b/scripts/ci/guideline_check.py @@ -51,6 +51,8 @@ def main(): if not args.commits: exit("missing commit range") + # pylint does not like the 'sh' library + # pylint: disable=too-many-function-args,unexpected-keyword-arg commit = sh.git("diff", args.commits, **sh_special_args) patch_set = PatchSet(commit) zephyr_base = os.getenv("ZEPHYR_BASE") From b5e001ff75a1d1a6ef4d733cf966ed3ad15f0ecc Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 25 Mar 2021 08:07:42 -0400 Subject: [PATCH 07/14] ci: guideline_check: fix indentation Signed-off-by: Anas Nashif --- scripts/ci/guideline_check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/guideline_check.py b/scripts/ci/guideline_check.py index b1aff66932ceb..0cbfc35ca0413 100755 --- a/scripts/ci/guideline_check.py +++ b/scripts/ci/guideline_check.py @@ -90,7 +90,7 @@ def main(): violation, "\t\n".join( violations[violation]))) - return numViolations + return numViolations if __name__ == "__main__": From d79b46118e3b1b308c194e4a17d5ae9689f4d060 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 25 Mar 2021 07:59:15 -0400 Subject: [PATCH 08/14] coccinelle: check reserved symbols based on a file Signed-off-by: Anas Nashif --- scripts/coccinelle/reserved_names.cocci | 18 +- scripts/coccinelle/symbols.txt | 293 ++++++++++++++++++++++++ 2 files changed, 305 insertions(+), 6 deletions(-) create mode 100644 scripts/coccinelle/symbols.txt diff --git a/scripts/coccinelle/reserved_names.cocci b/scripts/coccinelle/reserved_names.cocci index 688b3a9419acc..af383db411073 100644 --- a/scripts/coccinelle/reserved_names.cocci +++ b/scripts/coccinelle/reserved_names.cocci @@ -45,8 +45,10 @@ p << common_case.p; @@ msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v) -if v in ["remove", "rewind", "malloc", "free", "exp", "signal"]: - coccilib.report.print_report(p[0], msg) +with open("scripts/coccinelle/symbols.txt", "r") as fp: + symbols = fp.read().splitlines() + if v in symbols: + coccilib.report.print_report(p[0], msg) @function_match@ type T; @@ -62,8 +64,10 @@ v << function_match.f; @@ msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v) -if v in ["remove", "rewind", "malloc", "free", "exp", "signal"]: - coccilib.report.print_report(p[0], msg) +with open("scripts/coccinelle/symbols.txt", "r") as fp: + symbols = fp.read().splitlines() + if v in symbols: + coccilib.report.print_report(p[0], msg) @function_parameter@ type T1, T2; @@ -82,5 +86,7 @@ p << function_parameter.p; @@ msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v) -if v in ["remove", "rewind", "malloc", "free", "exp", "signal"]: - coccilib.report.print_report(p[0], msg) +with open("scripts/coccinelle/symbols.txt", "r") as fp: + symbols = fp.read().splitlines() + if v in symbols: + coccilib.report.print_report(p[0], msg) diff --git a/scripts/coccinelle/symbols.txt b/scripts/coccinelle/symbols.txt new file mode 100644 index 0000000000000..3b32b3800cd88 --- /dev/null +++ b/scripts/coccinelle/symbols.txt @@ -0,0 +1,293 @@ +abort +abs +acos +asctime +asctime_r +asin +assert +atan +atan2 +atexit +atof +atoi +atol +bsearch +btowc +calloc +catclose6 +catgets6 +catopen6 +ceil +clearerr +clock +cos +cosh +ctime +ctime64 +ctime_r +ctime64_r +difftime +difftime64 +div +erf +erfc +exit +exp +fabs +fclose +fdopen5 +feof +ferror +fflush1 +fgetc1 +fgetpos1 +fgets1 +fgetwc6 +fgetws6 +fileno5 +floor +fmod +fopen +fprintf +fputc1 +fputs1 +fputwc6 +fputws6 +fread +free +freopen +frexp +fscanf +fseek1 +fsetpos1 +ftell1 +fwide6 +fwprintf6 +fwrite +fwscanf6 +gamma +getc1 +getchar1 +getenv +gets +getwc6 +getwchar6 +gmtime +gmtime64 +gmtime_r +gmtime64_r +hypot +isalnum +isalpha +isascii4 +isblank +iscntrl +isdigit +isgraph +islower +isprint +ispunct +isspace +isupper +iswalnum4 +iswalpha4 +iswblank4 +iswcntrl4 +iswctype4 +iswdigit4 +iswgraph4 +iswlower4 +iswprint4 +iswpunct4 +iswspace4 +iswupper4 +iswxdigit4 +isxdigit4 +j0 +j1 +jn +labs +ldexp +ldiv +localeconv +localtime +localtime64 +localtime_r +localtime64_r +log +log10 +longjmp +malloc +mblen +mbrlen4 +mbrtowc4 +mbsinit4 +mbsrtowcs4 +mbstowcs +mbtowc +memchr +memcmp +memcpy +memmove +memset +mktime +mktime64 +modf +nextafter +nextafterl +nexttoward +nexttowardl +nl_langinfo4 +perror +pow +printf +putc1 +putchar1 +putenv +puts +putwc6 +putwchar6 +qsort +quantexpd32 +quantexpd64 +quantexpd128 +quantized32 +quantized64 +quantized128 +samequantumd32 +samequantumd64 +samequantumd128 +raise +rand +rand_r +realloc +regcomp +regerror +regexec +regfree +remove +rename +rewind1 +scanf +setbuf +setjmp +setlocale +setvbuf +signal +sin +sinh +snprintf +sprintf +sqrt +srand +sscanf +strcasecmp +strcat +strchr +strcmp +strcoll +strcpy +strcspn +strerror +strfmon4 +strftime +strlen +strncasecmp +strncat +strncmp +strncpy +strpbrk +strptime4 +strrchr +strspn +strstr +strtod +strtod32 +strtod64 +strtod128 +strtof +strtok +strtok_r +strtol +strtold +strtoul +strxfrm +swprintf +swscanf +system +tan +tanh +time +time64 +tmpfile +tmpnam +toascii +tolower +toupper +towctrans +towlower4 +towupper4 +ungetc1 +ungetwc6 +va_arg +va_copy +va_end +va_start +vfprintf +vfscanf +vfwprintf6 +vfwscanf +vprintf +vscanf +vsprintf +vsnprintf +vsscanf +vswprintf +vswscanf +vwprintf6 +vwscanf +wcrtomb4 +wcscat +wcschr +wcscmp +wcscoll4 +wcscpy +wcscspn +wcsftime +wcslen +wcslocaleconv +wcsncat +wcsncmp +wcsncpy +wcspbrk +wcsptime +wcsrchr +wcsrtombs4 +wcsspn +wcsstr +wcstod +wcstod32 +wcstod64 +wcstod128 +wcstof +wcstok +wcstol +wcstold +wcstombs +wcstoul +wcsxfrm4 +wctob +wctomb +wctrans +wctype4 +wcwidth +wmemchr +wmemcmp +wmemcpy +wmemmove +wmemset +wprintf6 +wscanf6 +y0 +y1 +yn From b896b84515b43b16d7969e57ccdb0739428e54ca Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 24 Mar 2021 10:54:54 -0400 Subject: [PATCH 09/14] ci: add coding guideline workflow Signed-off-by: Anas Nashif --- .github/workflows/coding_guidelines.yml | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/coding_guidelines.yml diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml new file mode 100644 index 0000000000000..27528b6872650 --- /dev/null +++ b/.github/workflows/coding_guidelines.yml @@ -0,0 +1,59 @@ +name: Coding Guidelines + +on: pull_request + +jobs: + compliance_job: + runs-on: ubuntu-latest + name: Run coding guidelines checks on patch series (PR) + steps: + - name: Checkout the code + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: cache-pip + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-doc-pip + + - name: Install python dependencies + run: | + pip3 install unidiff + pip3 install wheel + pip3 install sh + + - name: Install Packages + run: | + sudo apt-get install ocaml-base-nox + wget https://launchpad.net/~npalix/+archive/ubuntu/coccinelle/+files/coccinelle_1.0.8~20.04npalix1_amd64.deb + sudo dpkg -i coccinelle_1.0.8~20.04npalix1_amd64.deb + + - name: Run Coding Guildeines Checks + continue-on-error: true + id: coding_guidelines + env: + BASE_REF: ${{ github.base_ref }} + run: | + export ZEPHYR_BASE=$PWD + source zephyr-env.sh + # debug + ls -la + git log --pretty=oneline | head -n 10 + ./scripts/ci/guideline_check.py --output output.txt -c origin/${BASE_REF}.. + + - name: check-warns + run: | + if [[ -s "output.txt" ]]; then + errors=$(cat output.txt) + errors="${errors//'%'/'%25'}" + errors="${errors//$'\n'/'%0A'}" + errors="${errors//$'\r'/'%0D'}" + echo "::error file=output.txt::$errors" + exit=1 + fi + if [ ${exit} == 1 ]; then + exit 1; + fi From d5e534bc3641e6ec324b323a6e815d18a1b4114e Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 25 Mar 2021 09:34:35 -0400 Subject: [PATCH 10/14] add annotations Signed-off-by: Anas Nashif --- .github/workflows/coding_guidelines.yml | 19 +++++++++++++------ scripts/ci/guideline_check.py | 12 +++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml index 27528b6872650..ec1c69a9d7ee1 100644 --- a/.github/workflows/coding_guidelines.yml +++ b/.github/workflows/coding_guidelines.yml @@ -47,13 +47,20 @@ jobs: - name: check-warns run: | if [[ -s "output.txt" ]]; then - errors=$(cat output.txt) - errors="${errors//'%'/'%25'}" - errors="${errors//$'\n'/'%0A'}" - errors="${errors//$'\r'/'%0D'}" - echo "::error file=output.txt::$errors" - exit=1 + errors=$(cat output.txt) + errors="${errors//'%'/'%25'}" + errors="${errors//$'\n'/'%0A'}" + errors="${errors//$'\r'/'%0D'}" + echo "::error file=output.txt::$errors" + exit=1 fi if [ ${exit} == 1 ]; then exit 1; fi + + - name: Annotate + uses: Attest/annotations-action@v1.0.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + input: './violations.json' + title: 'Violations' diff --git a/scripts/ci/guideline_check.py b/scripts/ci/guideline_check.py index 0cbfc35ca0413..f8d69eedf7de2 100755 --- a/scripts/ci/guideline_check.py +++ b/scripts/ci/guideline_check.py @@ -7,6 +7,7 @@ import argparse import re from unidiff import PatchSet +import json if "ZEPHYR_BASE" not in os.environ: exit("$ZEPHYR_BASE environment variable undefined.") @@ -58,6 +59,7 @@ def main(): zephyr_base = os.getenv("ZEPHYR_BASE") violations = {} numViolations = 0 + vlist = [] for f in patch_set: if not f.path.endswith(".c") and not f.path.endswith(".h") or not os.path.exists(zephyr_base + "/" + f.path): @@ -78,6 +80,13 @@ def main(): if line.is_added: violation = "{}:{}".format(f.path, line.target_line_no) if violation in violations: + v = {} + v['message'] = "\t\n".join(violations[violation]) + v['path'] = violation.split(":")[0] + v['line'] = { "start": violation.split(":")[1], "end": violation.split(":")[1] } + v['column'] = { "start": 0, "end": 0 } + v['level'] = "warning" + vlist.append(v) numViolations += 1 if args.output: with open(args.output, "a+") as fp: @@ -89,7 +98,8 @@ def main(): "{}:{}".format( violation, "\t\n".join( violations[violation]))) - + with open('violations.json', 'w') as outfile: + json.dump(vlist, outfile) return numViolations From d56b766a9764caae96b00c86f71e5b8d5bae8444 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 25 Mar 2021 09:53:21 -0400 Subject: [PATCH 11/14] remove check-warn Signed-off-by: Anas Nashif --- .github/workflows/coding_guidelines.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml index ec1c69a9d7ee1..afa7cb19cf544 100644 --- a/.github/workflows/coding_guidelines.yml +++ b/.github/workflows/coding_guidelines.yml @@ -44,20 +44,6 @@ jobs: git log --pretty=oneline | head -n 10 ./scripts/ci/guideline_check.py --output output.txt -c origin/${BASE_REF}.. - - name: check-warns - run: | - if [[ -s "output.txt" ]]; then - errors=$(cat output.txt) - errors="${errors//'%'/'%25'}" - errors="${errors//$'\n'/'%0A'}" - errors="${errors//$'\r'/'%0D'}" - echo "::error file=output.txt::$errors" - exit=1 - fi - if [ ${exit} == 1 ]; then - exit 1; - fi - - name: Annotate uses: Attest/annotations-action@v1.0.3 with: From bb87998a961d5cbd95dd4af51c444850e6b4d158 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 25 Mar 2021 09:36:31 -0400 Subject: [PATCH 12/14] violations Signed-off-by: Anas Nashif --- drivers/i2c/i2c_imx.c | 2 +- kernel/sem.c | 1 + lib/os/heap.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_imx.c b/drivers/i2c/i2c_imx.c index f52631bec5d31..edcf31992c882 100644 --- a/drivers/i2c/i2c_imx.c +++ b/drivers/i2c/i2c_imx.c @@ -26,7 +26,7 @@ LOG_MODULE_REGISTER(i2c_imx); struct i2c_imx_config { I2C_Type *base; - void (*irq_config_func)(const struct device *dev); + void (*irq_config_func)(const struct device *device); uint32_t bitrate; }; diff --git a/kernel/sem.c b/kernel/sem.c index 78e93adb62c02..dbb134bbb5f3a 100644 --- a/kernel/sem.c +++ b/kernel/sem.c @@ -48,6 +48,7 @@ struct k_sem *_trace_list_k_sem; static int init_sem_module(const struct device *dev) { ARG_UNUSED(dev); + int exp; Z_STRUCT_SECTION_FOREACH(k_sem, sem) { SYS_TRACING_OBJ_INIT(k_sem, sem); diff --git a/lib/os/heap.c b/lib/os/heap.c index 363427a3e58f4..10777c48daa57 100644 --- a/lib/os/heap.c +++ b/lib/os/heap.c @@ -21,6 +21,7 @@ static void *chunk_mem(struct z_heap *h, chunkid_t c) static void free_list_remove_bidx(struct z_heap *h, chunkid_t c, int bidx) { struct z_heap_bucket *b = &h->buckets[bidx]; + int remove; CHECK(!chunk_used(h, c)); CHECK(b->next != 0); From 9df883686de2c0f2b4b9d8133af9ec6399d9340d Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 25 Mar 2021 09:56:12 -0400 Subject: [PATCH 13/14] action Signed-off-by: Anas Nashif --- .github/workflows/coding_guidelines.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml index afa7cb19cf544..cf470ca83d190 100644 --- a/.github/workflows/coding_guidelines.yml +++ b/.github/workflows/coding_guidelines.yml @@ -47,6 +47,5 @@ jobs: - name: Annotate uses: Attest/annotations-action@v1.0.3 with: - token: ${{ secrets.GITHUB_TOKEN }} - input: './violations.json' + path: './violations.json' title: 'Violations' From a752db77d234d2f2883605624cacd31cd24b9054 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 25 Mar 2021 10:58:18 -0400 Subject: [PATCH 14/14] new action Signed-off-by: Anas Nashif --- .github/workflows/coding_guidelines.yml | 7 ++++--- scripts/ci/guideline_check.py | 7 +++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml index cf470ca83d190..052334b461b9f 100644 --- a/.github/workflows/coding_guidelines.yml +++ b/.github/workflows/coding_guidelines.yml @@ -1,6 +1,6 @@ name: Coding Guidelines -on: pull_request +on: pull_request_target jobs: compliance_job: @@ -45,7 +45,8 @@ jobs: ./scripts/ci/guideline_check.py --output output.txt -c origin/${BASE_REF}.. - name: Annotate - uses: Attest/annotations-action@v1.0.3 + uses: yuzutech/annotations-action@v0.3.0 with: - path: './violations.json' + repo-token: "${{ secrets.GITHUB_TOKEN }}" + input: './violations.json' title: 'Violations' diff --git a/scripts/ci/guideline_check.py b/scripts/ci/guideline_check.py index f8d69eedf7de2..3800199a7978f 100755 --- a/scripts/ci/guideline_check.py +++ b/scripts/ci/guideline_check.py @@ -82,10 +82,9 @@ def main(): if violation in violations: v = {} v['message'] = "\t\n".join(violations[violation]) - v['path'] = violation.split(":")[0] - v['line'] = { "start": violation.split(":")[1], "end": violation.split(":")[1] } - v['column'] = { "start": 0, "end": 0 } - v['level'] = "warning" + v['file'] = violation.split(":")[0] + v['line'] = violation.split(":")[1] + v['annotation_level'] = "failure" vlist.append(v) numViolations += 1 if args.output: