diff --git a/.github/workflows/checkpatch_pull.yml b/.github/workflows/checkpatch_pull.yml index 353c1f9a0..992238ea5 100644 --- a/.github/workflows/checkpatch_pull.yml +++ b/.github/workflows/checkpatch_pull.yml @@ -24,31 +24,4 @@ jobs: - name: Run checkpatch.pl run: | - ignore=( - MISSING_SIGN_OFF - EMAIL_SUBJECT - UNKNOWN_COMMIT_ID - NO_AUTHOR_SIGN_OFF - COMMIT_LOG_USE_LINK - BAD_REPORTED_BY_LINK - FILE_PATH_CHANGES - SPDX_LICENSE_TAG - LINUX_VERSION_CODE - CONSTANT_COMPARISON - NEW_TYPEDEFS - SPACING - ) - ignore_str=${ignore[*]} - - base_commit=${{github.event.pull_request.base.sha}} - commits=$(git log --pretty=format:"%h" $base_commit..HEAD) - err=0 - - for commit in $commits; do - echo "Running checkpatch.pl for commit $commit" - echo "========================================" - git format-patch -1 --stdout $commit | ./checkpatch.pl --no-tree --show-types --strict --ignore="${ignore_str// /,}" - || err=1 - echo - done - - exit $err + CHECKPATCH_PATH=. ./scripts/checkpatch_commits ${{github.event.pull_request.base.sha}} diff --git a/.github/workflows/checkpatch_push.yml b/.github/workflows/checkpatch_push.yml index ac3755ed0..a1ea507df 100644 --- a/.github/workflows/checkpatch_push.yml +++ b/.github/workflows/checkpatch_push.yml @@ -29,20 +29,4 @@ jobs: - name: Run checkpatch.pl run: | - ignore=( - MISSING_SIGN_OFF - EMAIL_SUBJECT - UNKNOWN_COMMIT_ID - NO_AUTHOR_SIGN_OFF - COMMIT_LOG_USE_LINK - BAD_REPORTED_BY_LINK - FILE_PATH_CHANGES - SPDX_LICENSE_TAG - LINUX_VERSION_CODE - CONSTANT_COMPARISON - NEW_TYPEDEFS - SPACING - ) - ignore_str=${ignore[*]} - - git format-patch -1 --stdout | ./checkpatch.pl --no-tree --show-types --strict --ignore="${ignore_str// /,}" - + git format-patch -1 --stdout | CHECKPATCH_PATH=. ./scripts/checkpatch diff --git a/scripts/checkpatch b/scripts/checkpatch index 40937e523..5c9d3ba1f 100755 --- a/scripts/checkpatch +++ b/scripts/checkpatch @@ -1,17 +1,22 @@ #!/usr/bin/env bash +set -e + +scriptpath=${CHECKPATCH_PATH:-/lib/modules/$(uname -r)/build/scripts} + ignore=( - CONSTANT_COMPARISON - LINUX_VERSION_CODE - LONG_LINE - LONG_LINE_COMMENT - LONG_LINE_STRING - RETURN_VOID + MISSING_SIGN_OFF + EMAIL_SUBJECT + UNKNOWN_COMMIT_ID + NO_AUTHOR_SIGN_OFF + COMMIT_LOG_USE_LINK + BAD_REPORTED_BY_LINK + FILE_PATH_CHANGES SPDX_LICENSE_TAG - SYMBOLIC_PERMS + LINUX_VERSION_CODE + CONSTANT_COMPARISON + NEW_TYPEDEFS ) ignore_str=${ignore[*]} -src_files=$(list-source-files | grep -vE '^debian/|^fcst/linux-patches|patch$|pdf$|png$|^iscsi-scst/usr|^qla|^scripts/|^scstadmin/|^usr/|^www/') - -../linux-kernel/scripts/checkpatch.pl -f --show-types --strict --ignore="${ignore_str// /,}" $src_files | sed 's/^#[0-9]*: FILE: \(.*\):/\1:1:/' +${scriptpath}/checkpatch.pl --no-tree --show-types --strict --ignore="${ignore_str// /,}" $@ diff --git a/scripts/checkpatch_commits b/scripts/checkpatch_commits new file mode 100755 index 000000000..d83285125 --- /dev/null +++ b/scripts/checkpatch_commits @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -e + +rootdir=$(readlink -f $(dirname $0)/..) +scriptsdir=${rootdir}/scripts +base_commit=${1:-master} + +commits=$(cd ${rootdir} && git log --pretty=format:"%h" ${base_commit}..HEAD) +err=0 + +for commit in $commits; do + echo "Running checkpatch for commit $commit" + echo -e "========================================\n" + + (cd ${rootdir} && + git format-patch -1 --stdout $commit | ${scriptsdir}/checkpatch -) || err=1 + echo -e "\n" +done + +exit $err diff --git a/scripts/checkpatch_diff b/scripts/checkpatch_diff new file mode 100755 index 000000000..02b064a69 --- /dev/null +++ b/scripts/checkpatch_diff @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e + +rootdir=$(readlink -f $(dirname $0)/..) +scriptsdir=${rootdir}/scripts +base_commit=${1:-master} + +err=0 + +(cd ${rootdir} && git diff ${base_commit} | ${scriptsdir}/checkpatch -) || err=1 + +exit $err diff --git a/scripts/checkpatch_scan b/scripts/checkpatch_scan new file mode 100755 index 000000000..cc539b3e4 --- /dev/null +++ b/scripts/checkpatch_scan @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -e + +rootdir=$(readlink -f $(dirname $0)/..) +scriptsdir=${rootdir}/scripts +outputfile=checkpatch.out + +src_files=$(${scriptsdir}/list-source-files ${rootdir} | \ + grep -vE '^debian/|^fcst/linux-patches|patch$|pdf$|png$|^iscsi-scst/usr|^qla|^scripts/|^scstadmin/|^usr/|^www/' | \ + while read -r filename; do echo "${rootdir}/$filename"; done) + +${scriptsdir}/checkpatch -f $src_files 1> ${outputfile} || true + +errors=$(grep -c '^ERROR' "${outputfile}") +warnings=$(grep -c '^WARNING' "${outputfile}") +checks=$(grep -c '^CHECK' "${outputfile}") + +echo "${errors} errors / ${warnings} warnings / ${checks} checks." + +grep -E '^WARNING|^ERROR|^CHECK' "${outputfile}" | + sort | + sed 's/^CHECK:CAMELCASE: Avoid CamelCase:.*/CHECK:CAMELCASE Avoid CamelCase/' | + uniq -c