From cf04377c790ca10f47bde0a3196c3fd5c91a2d82 Mon Sep 17 00:00:00 2001 From: Arnaud Pouliquen Date: Thu, 31 Mar 2022 17:45:32 +0200 Subject: [PATCH] CI: add codespell support to check typos Enable the use of codespell tool in checkpatch.pl For this the checkpatch.pl as been partially rebased on the Linux one. Signed-off-by: Arnaud Pouliquen --- .github/workflows/compliance.yml | 2 +- scripts/checkpatch.pl | 26 ++++++++++++++++++++++++-- scripts/ci/check_compliance.py | 3 ++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index ef39020..17fe465 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -19,7 +19,7 @@ jobs: - name: Install python dependencies run: | pip3 install setuptools - pip3 install junitparser==1.6.3 gitlint + pip3 install junitparser==1.6.3 gitlint codespell - uses: actions/checkout@v1 - name: Run Compliance Tests continue-on-error: true diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e033f7b..e35679d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -56,6 +56,7 @@ my $min_conf_desc_length = 4; my $spelling_file = "$D/spelling.txt"; my $codespell = 0; my $codespellfile = "/usr/share/codespell/dictionary.txt"; +my $user_codespellfile = ""; my $conststructsfile = "$D/const_structs.checkpatch"; my $typedefsfile = ""; my $color = "auto"; @@ -115,7 +116,7 @@ Options: --ignore-perl-version override checking of perl version. expect runtime errors. --codespell Use the codespell dictionary for spelling/typos - (default:/usr/share/codespell/dictionary.txt) + (default:$codespellfile) --codespellfile Use this codespell dictionary --typedefsfile Read additional types from this file --color[=WHEN] Use colors 'always', 'never', or only when output @@ -223,7 +224,7 @@ GetOptions( 'debug=s' => \%debug, 'test-only=s' => \$tst_only, 'codespell!' => \$codespell, - 'codespellfile=s' => \$codespellfile, + 'codespellfile=s' => \$user_codespellfile, 'typedefsfile=s' => \$typedefsfile, 'color=s' => \$color, 'no-color' => \$color, #keep old behaviors of -nocolor @@ -234,6 +235,27 @@ GetOptions( help(0) if ($help); +if ($user_codespellfile) { + # Use the user provided codespell file unconditionally + $codespellfile = $user_codespellfile; +} elsif (!(-f $codespellfile)) { + # If /usr/share/codespell/dictionary.txt is not present, try to find it + # under codespell's install directory: /data/dictionary.txt + if (($codespell || $help) && which("codespell") ne "" && which("python") ne "") { + my $python_codespell_dict = << "EOF"; + +import os.path as op +import codespell_lib +codespell_dir = op.dirname(codespell_lib.__file__) +codespell_file = op.join(codespell_dir, 'data', 'dictionary.txt') +print(codespell_file, end='') +EOF + + my $codespell_dict = `python -c "$python_codespell_dict" 2> /dev/null`; + $codespellfile = $codespell_dict if (-f $codespell_dict); + } +} + list_types(0) if ($list_types); $fix = 1 if ($fix_inplace); diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 06efb17..e083b45 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -194,7 +194,8 @@ class CheckPatch(ComplianceTest): diff = subprocess.Popen(('git', 'diff', COMMIT_RANGE), stdout=subprocess.PIPE) try: - subprocess.check_output(checkpatch + ' --mailback' + ' --no-tree' + ' -', + subprocess.check_output(checkpatch + ' --mailback' + ' --codespell' + + ' --no-tree' + ' -', stdin=diff.stdout, stderr=subprocess.STDOUT, shell=True, cwd=GIT_TOP)