diff options
Diffstat (limited to 'util')
23 files changed, 273 insertions, 152 deletions
diff --git a/util/lint/helper_functions.sh b/util/lint/helper_functions.sh new file mode 100644 index 0000000000..0c679d974f --- /dev/null +++ b/util/lint/helper_functions.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh +# +# SPDX-License-Identifier: GPL-2.0-only + +# This file is sourced by the linters so that each one doesn't have to +# specify these routines individually + +LC_ALL=C export LC_ALL + +if [ -z "$GIT" ]; then + GIT="$(command -v git)" +else + # If git is specified, Do a basic check that it runs and seems like + # it's actually git + if ! "${GIT}" --version | grep -q git; then + echo "Error: ${GIT} does not seem to be valid." + exit 1; + fi +fi + +if [ "$(${GIT} rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then + IN_GIT_TREE=1 +else + IN_GIT_TREE=0 +fi + +if [ "${IN_GIT_TREE}" -eq 1 ] && [ -z "${GIT}" ]; then + echo "This test needs git to run. Please install it, then run this test again." + exit 1 +fi + +# Use git ls-files if the code is in a git repo, otherwise use find. +if [ "${IN_GIT_TREE}" -eq 1 ]; then + FIND_FILES="${GIT} ls-files" +else + FIND_FILES="find src" +fi + +# Use git grep if the code is in a git repo, otherwise use grep. +if [ "${IN_GIT_TREE}" -eq 1 ]; then + GREP_FILES="${GIT} grep" +else + GREP_FILES="grep -r" +fi diff --git a/util/lint/lint-000-license-headers b/util/lint/lint-000-license-headers index f70b623d2d..233759b0bb 100755 --- a/util/lint/lint-000-license-headers +++ b/util/lint/lint-000-license-headers @@ -5,6 +5,15 @@ # DESCR: Check that files in have valid license headers # $1 is an optional command line parameter containing directories to check + +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + # regex list of files and directories to exclude from the search HEADER_EXCLUDED="\ ^src/commonlib/bsd/lz4.c.inc\$|\ @@ -69,11 +78,10 @@ else HEADER_DIRS="$1" fi -LC_ALL=C export LC_ALL #get initial list from git, removing HEADER_EXCLUDED files. #make a copy to check for the old style header later. -headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)") +headerlist=$(${FIND_FILES} $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)") #update headerlist by removing files that match the license string check_for_license() { diff --git a/util/lint/lint-007-checkpatch b/util/lint/lint-007-checkpatch index d7443b3b2c..a9cf782885 100755 --- a/util/lint/lint-007-checkpatch +++ b/util/lint/lint-007-checkpatch @@ -4,7 +4,13 @@ # DESCR: Checkpatch on .c, .h, & Kconfig files in the tree -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" # GNU BRE syntax list of files to examine INCLUDED_FILES='.*\.[ch]\|Kconfig.*$' @@ -36,7 +42,7 @@ fi # We want word splitting here, so disable the shellcheck warnings # shellcheck disable=SC2046,SC2086 -FILELIST=$( git ls-files $INCLUDED_DIRS | \ +FILELIST=$( ${FIND_FILES} $INCLUDED_DIRS | \ grep $INCLUDED_FILES | \ grep -v $EXCLUDED_DIRS ) diff --git a/util/lint/lint-008-kconfig b/util/lint/lint-008-kconfig index c24ff14069..248b519839 100755 --- a/util/lint/lint-008-kconfig +++ b/util/lint/lint-008-kconfig @@ -4,18 +4,21 @@ # DESCR: Check Kconfig files for warnings and errors -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" # Verify that the test can run, tell users the issue if [ -z "$(command -v perl)" ]; then echo "The kconfig lint tool uses perl. Please install it to run this test." fi -# If coreboot is in a git repo, use git grep to check as it will ignore any -# files in the tree that aren't checked into git -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then +# Don't use git if coreboot isn't in a repo +if [ "${IN_GIT_TREE}" -eq 1 ]; then env perl util/lint/kconfig_lint else env perl util/lint/kconfig_lint --no_git_grep diff --git a/util/lint/lint-014-qualified-types b/util/lint/lint-014-qualified-types index 48810cf3cd..0f9725e32b 100755 --- a/util/lint/lint-014-qualified-types +++ b/util/lint/lint-014-qualified-types @@ -4,22 +4,19 @@ # DESCR: Check that variables have fully qualified types -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" INCLUDED_DIRS='^src/\|^util/\|payloads/libpayload\|payloads/coreinfo' EXCLUDED_DIRS='^src/vendorcode\|cbfstool/lzma\|cbfstool/lz4' INCLUDED_FILES='\.[ch]:' -# Use git grep if the code is in a git repo, otherwise use grep. -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - GREP_FILES="git grep -n" -else - GREP_FILES="grep -rn" -fi - -${GREP_FILES} 'unsigned[[:space:]]' | \ +${GREP_FILES} -n 'unsigned[[:space:]]' | \ grep "$INCLUDED_DIRS" | \ grep -v "$EXCLUDED_DIRS" | \ grep "$INCLUDED_FILES" | \ diff --git a/util/lint/lint-extended-015-final-newlines b/util/lint/lint-extended-015-final-newlines index 55b48cf644..2c792839d2 100755 --- a/util/lint/lint-extended-015-final-newlines +++ b/util/lint/lint-extended-015-final-newlines @@ -4,22 +4,19 @@ # DESCR: Check that files end with a single newline -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" PIDS="" INCLUDED_DIRS_AND_FILES='util/* src/* payloads/* configs/* Makefile *.inc' EXCLUDED_DIRS='src/vendorcode/\|cbfstool/lzma/\|cbfstool/lz4/\|Documentation/\|build/\|3rdparty/\|\.git/\|coreboot-builds/\|util/nvidia/cbootimage/' EXCLUDED_FILES='\.gif$\|\.jpg$\|\.cksum$\|\.bin$\|\.vbt$\|\.hex$\|\.ico$\|\.o$\|\.bz2$\|\.xz$\|^.tmpconfig\|\.pyc$\|_shipped$\|sha256$\|\.png$\|\.patch$' -# Use git ls-files if the code is in a git repo, otherwise use find. -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - FIND_FILES="git ls-files" -else - FIND_FILES="find" -fi - HAVE_FILE=$(command -v file 1>/dev/null 2>&1; echo $?) is_eligible_executable() { @@ -57,7 +54,7 @@ test_for_final_newline() { } for directory in $INCLUDED_DIRS_AND_FILES ; do - ${FIND_FILES} ${directory} | sed 's|^\./||' | sort | \ + ${FIND_FILES} "${directory}" | sed 's|^\./||' | sort | \ grep -v "$EXCLUDED_DIRS" | \ grep -v "$EXCLUDED_FILES" | \ test_for_final_newline & diff --git a/util/lint/lint-extended-020-signed-off-by b/util/lint/lint-extended-020-signed-off-by index 6d569aa80a..abbed56a24 100755 --- a/util/lint/lint-extended-020-signed-off-by +++ b/util/lint/lint-extended-020-signed-off-by @@ -1,13 +1,22 @@ #!/usr/bin/env sh # SPDX-License-Identifier: GPL-2.0-or-later # -# DESCR: Check for a signed-off-by line on the latest git commit +# DESCR: Check for a signed-off-by line on the latest commit + + +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + +if [ "${IN_GIT_TREE}" -eq 0 ]; then + exit 0 +fi # This test is mainly for the jenkins server -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - if [ -z "$(git log -n 1 | grep '[[:space:]]\+Signed-off-by: ')" ]; then - echo "No Signed-off-by line in commit message" - fi +if ! ${GIT} log -n 1 | grep -q '[[:space:]]\+Signed-off-by: '; then + echo "No Signed-off-by line in commit message" fi diff --git a/util/lint/lint-stable-003-whitespace b/util/lint/lint-stable-003-whitespace index 5174120673..e46d93e2a4 100755 --- a/util/lint/lint-stable-003-whitespace +++ b/util/lint/lint-stable-003-whitespace @@ -4,20 +4,26 @@ # DESCR: Check for superfluous whitespace in the tree -LC_ALL=C export LC_ALL +INTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + EXCLUDELIST='^src/vendorcode/|^util/kconfig/|^util/nvidia/cbootimage$|^util/goswid$|COPYING|LICENSE|README|_shipped$|\.patch$|\.bin$|\.hex$|\.jpg$|\.gif$|\.ttf$|\.woff$|\.png$|\.eot$|\.vbt$|\.ico$|\.md$' INCLUDELIST="src util payloads Makefile* toolchain.inc tests" # shellcheck disable=SC2086,SC2046 if uname | grep -qi "linux"; then grep -n -H "[[:space:]][[:space:]]*$" \ - $(git ls-files $INCLUDELIST | \ + $(${FIND_FILES} $INCLUDELIST | \ grep -Ev "($EXCLUDELIST)" ) | \ sed -e "s,^.*$,File & has lines ending with whitespace.," else # The above form is much (100x) faster, but doesn't work # on all systems. A for loop also works but takes 30% longer - git ls-files $INCLUDELIST | \ + ${FIND_FILES} $INCLUDELIST | \ grep -Ev "($EXCLUDELIST)" | \ xargs -I % \ grep -l "[[:space:]][[:space:]]*$" % | \ diff --git a/util/lint/lint-stable-004-style-labels b/util/lint/lint-stable-004-style-labels index 393774fdae..2418cdf249 100755 --- a/util/lint/lint-stable-004-style-labels +++ b/util/lint/lint-stable-004-style-labels @@ -4,16 +4,13 @@ # DESCR: Check that C labels begin at start-of-line -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" -# Use git ls-files if the code is in a git repo, otherwise use find. -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - FIND_FILES="git ls-files" -else - FIND_FILES="find src" -fi +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" ${FIND_FILES} | \ grep "^src/.*\.[csS]$" | \ diff --git a/util/lint/lint-stable-005-board-status b/util/lint/lint-stable-005-board-status index 617440bd14..08cbc92c66 100755 --- a/util/lint/lint-stable-005-board-status +++ b/util/lint/lint-stable-005-board-status @@ -3,8 +3,16 @@ # # DESCR: Check that every board has a meaningful board_info.txt -LC_ALL=C export LC_ALL -for mobodir in $(git ls-files src/mainboard | sed -n 's,^\(src/mainboard/[^/]*/[^/]*\)/.*$,\1,p'|sort|uniq); do + +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + +for mobodir in $(${FIND_FILES} src/mainboard | sed -n 's,^\(src/mainboard/[^/]*/[^/]*\)/.*$,\1,p'|sort|uniq); do board_info="$mobodir/board_info.txt" if ! [ -f "$board_info" ]; then echo "No $board_info found" diff --git a/util/lint/lint-stable-008-kconfig b/util/lint/lint-stable-008-kconfig index 3323971fac..e8a3beae8d 100755 --- a/util/lint/lint-stable-008-kconfig +++ b/util/lint/lint-stable-008-kconfig @@ -4,18 +4,21 @@ # DESCR: Check Kconfig files for errors -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" # Verify that the test can run, tell users the issue if [ -z "$(command -v perl)" ]; then echo "The kconfig lint tool uses perl. Please install it to run this test." fi -# If coreboot is in a git repo, use git grep to check as it will ignore any -# files in the tree that aren't checked into git -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then +# Check whether coreboot is in a repo +if [ "${IN_GIT_TREE}" -eq 1 ]; then env perl util/lint/kconfig_lint --warnings_off 2>&1 else env perl util/lint/kconfig_lint --no_git_grep --warnings_off 2>&1 diff --git a/util/lint/lint-stable-009-old-licenses b/util/lint/lint-stable-009-old-licenses index 8226fdd642..0b772263fa 100755 --- a/util/lint/lint-stable-009-old-licenses +++ b/util/lint/lint-stable-009-old-licenses @@ -5,6 +5,15 @@ # DESCR: Verify that files don't have the old style header # regex list of files and directories to exclude from the search + +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + HEADER_EXCLUDED="\ ^src/lib/gnat/|\ ^src/vendorcode/|\ @@ -26,9 +35,7 @@ if [ -z "$HEADER_DIRS" ]; then HEADER_DIRS="src util tests" fi -LC_ALL=C export LC_ALL - -headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)") +headerlist=$(${FIND_FILES} $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)") #check for the old style header headerlist=$(grep -il "You should have received a copy of the GNU" \ diff --git a/util/lint/lint-stable-010-asm-syntax b/util/lint/lint-stable-010-asm-syntax index 474a05d423..e1ce948f02 100755 --- a/util/lint/lint-stable-010-asm-syntax +++ b/util/lint/lint-stable-010-asm-syntax @@ -4,5 +4,12 @@ # DESCR: Check that we use a single assembler syntax -LC_ALL=C export LC_ALL -git grep -n "\.\(att\|intel\)_syntax\>" | grep -v '\.patch:' +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + +${GREP_FILES} -n "\.\(att\|intel\)_syntax\>" | grep -v '\.patch:' diff --git a/util/lint/lint-stable-012-executable-bit b/util/lint/lint-stable-012-executable-bit index 640bb08870..17ba065f20 100755 --- a/util/lint/lint-stable-012-executable-bit +++ b/util/lint/lint-stable-012-executable-bit @@ -3,6 +3,18 @@ # # DESCR: Check that source files are not executable -LC_ALL=C export LC_ALL -git ls-tree --full-tree -r HEAD src tests |grep "^100[7531][7531][7531] blob " |cut -f2- |grep -v "\.sh$" | \ +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + +# Exit if the code isn't in a git repo +if [ "${IN_GIT_TREE}" -eq 0 ]; then + exit 0 +fi + +${GIT} ls-tree --full-tree -r HEAD src tests |grep "^100[7531][7531][7531] blob " | cut -f2- | grep -v "\.sh$" | \ sed -e "s,^.*$,File & has one or more executable bits set in the file permissions.," diff --git a/util/lint/lint-stable-013-site-local b/util/lint/lint-stable-013-site-local index 53693f21d3..7a7dc8b2e2 100755 --- a/util/lint/lint-stable-013-site-local +++ b/util/lint/lint-stable-013-site-local @@ -6,14 +6,22 @@ # Because site-local is intended for local use only, it should never be # pushed to coreboot.org. Even for committing it for local use, it's # recommended that it be kept in a separate repository, and pulled in -# as a git submodule. +# as a submodule. -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - if [ -n "$(git ls-files site-local/*)" ]; then - echo "Error: site-local must be kept separate from the coreboot repository." - fi +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + +# Exit if the code isn't in a git repo +if [ "${IN_GIT_TREE}" -eq 0 ]; then + exit 0 +fi + + +if [ -n "$(${FIND_FILES} site-local/*)" ]; then + echo "Error: site-local must be kept separate from the coreboot repository." fi diff --git a/util/lint/lint-stable-016-non-ascii b/util/lint/lint-stable-016-non-ascii index 52b6679aa1..dc074daef7 100755 --- a/util/lint/lint-stable-016-non-ascii +++ b/util/lint/lint-stable-016-non-ascii @@ -4,18 +4,22 @@ # DESCR: Check for non-ASCII and unprintable characters -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" INCLUDED_FILES='\.[chsS]$\|\.asl$\|\.cb$\|\.inc$\|Kconfig\|\.ld$|\.txt\|\.hex' EXCLUDED_DIRS='^payloads/external/\|^src/vendorcode/\|^Documentation/' EXCLUDED_FILES='to-wiki/towiki\.sh$\|vga/vga_font\|video/font\|PDCurses.*x11' EXCLUDED_PHRASES='Copyright\|Ported to\|Intel®\|°C\|°F\|Athlon™\|Copyright.*©' -# Exit if git isn't present or the code isn't in a git repo -if [ -z "$(command -v git)" ] || \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ] -then - exit +# Exit if the code isn't in a git repo +if [ "${IN_GIT_TREE}" -eq 0 ]; then + exit 0 fi # 1. Get the list of files to parse and send them through grep @@ -25,7 +29,7 @@ fi # 4. Run the result through grep again to highlight the issues that were # found. Without this step, the characters can be difficult to see. # shellcheck disable=SC2046 -git grep -lP "[^\t-~]" | \ +${GREP_FILES} -lP "[^\t-~]" | \ grep "$INCLUDED_FILES" | \ grep -v "$EXCLUDED_DIRS" | \ grep -v "$EXCLUDED_FILES" | \ diff --git a/util/lint/lint-stable-017-configs b/util/lint/lint-stable-017-configs index 311ef38cd0..3f92f53b3c 100755 --- a/util/lint/lint-stable-017-configs +++ b/util/lint/lint-stable-017-configs @@ -4,21 +4,18 @@ # DESCR: Check that saved config files are miniconfigs -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" -SYMBOLS='CONFIG_ARCH_\|CONFIG_MAINBOARD_HAS_' +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" -# Use git grep if the code is in a git repo, otherwise use grep. -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - GREP="git grep -l" -else - GREP="grep -rl" -fi +SYMBOLS='CONFIG_ARCH_\|CONFIG_MAINBOARD_HAS_' #look for a couple of things that should only be set by select keywords for file in \ - $($GREP "$SYMBOLS" configs) ; do \ + $(${GREP_FILES} -l "$SYMBOLS" configs) ; do \ echo "Error: $file seems to be a full config"; \ done diff --git a/util/lint/lint-stable-018-symlinks b/util/lint/lint-stable-018-symlinks index cd5c8440c1..060b470f8c 100755 --- a/util/lint/lint-stable-018-symlinks +++ b/util/lint/lint-stable-018-symlinks @@ -4,21 +4,23 @@ # DESCR: Report any symbolic links -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" EXCLUDED_DIRS='^3rdparty\|^site-local' -# If the code is in a git repo, only print files that are checked in -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - git ls-tree -r HEAD | \ - grep ^120000 | \ - cut -f2 | \ - grep -v "$EXCLUDED_DIRS" -else - # If the code isn't in a git repo, print everything - find . -type l | \ - sed 's|\.\/||' | \ - grep -v "$EXCLUDED_DIRS" +# Exit if the code isn't in a git repo +if [ "${IN_GIT_TREE}" -eq 0 ]; then + exit 0 fi + + +${GIT} ls-tree -r HEAD | \ + grep ^120000 | \ + cut -f2 | \ + grep -v "$EXCLUDED_DIRS" diff --git a/util/lint/lint-stable-019-header-files b/util/lint/lint-stable-019-header-files index f73e0e7549..28e8d6ee41 100755 --- a/util/lint/lint-stable-019-header-files +++ b/util/lint/lint-stable-019-header-files @@ -4,7 +4,13 @@ # DESCR: Check for auto-included headers -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" INCLUDED_DIRS='^src/' EXCLUDED_FILES='src/include/kconfig.h' @@ -33,17 +39,8 @@ elif [ "$1" = "--reset" ]; then exit 0 fi -# Use git grep if the code is in a git repo, otherwise use grep. -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - GREP_FILES="git grep -n" -else - GREP_FILES="grep -rn" -fi - for header in $HEADER_FILES; do - ${GREP_FILES} "#[[:blank:]]*include[[:blank:]]\+[\"<][[:blank:]]*${header}\.h[[:blank:]]*[\">]" | \ + ${GREP_FILES} -n "#[[:blank:]]*include[[:blank:]]\+[\"<][[:blank:]]*${header}\.h[[:blank:]]*[\">]" | \ grep "$INCLUDED_DIRS" | \ grep -v "$EXCLUDED_FILES"; \ done diff --git a/util/lint/lint-stable-021-coreboot-lowercase b/util/lint/lint-stable-021-coreboot-lowercase index b13cb4487e..33ade6ded3 100755 --- a/util/lint/lint-stable-021-coreboot-lowercase +++ b/util/lint/lint-stable-021-coreboot-lowercase @@ -4,22 +4,21 @@ # DESCR: Verify that the word 'coreboot' is lowercase -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" -EXCLUDE='^3rdparty/\|util/crossgcc/xgcc\|Binary file\|coreboot\|COREBOOT\|CorebootPayload\|CorebootModule\|minnowboard.org/Coreboot\|.*\.patch$\|CorebootBdsLib\|^payloads/external' +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" -# Use git grep if the code is in a git repo, otherwise use grep. -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - GREP_FILES="git grep -in" +EXCLUDE='^3rdparty/\|util/crossgcc/xgcc\|Binary file\|coreboot\|COREBOOT\|CorebootPayload\|CorebootModule\|minnowboard.org/Coreboot\|.*\.patch$\|CorebootBdsLib\|^payloads/external' - # Check last commit message - if [ -n "$(git log -n 1 | grep -i 'coreboot' | grep -v "$EXCLUDE" )" ]; then +# # Check last commit message if the code is in a git repo +if [ "${IN_GIT_TREE}" -eq 1 ]; then + if [ -n "$(${GIT} log -n 1 | grep -i 'coreboot' | grep -v "$EXCLUDE" )" ]; then echo "'coreboot' should be lowercase in commit message" fi -else - GREP_FILES="grep -rin" fi -${GREP_FILES} "coreboot" | grep -v "$EXCLUDE"; +${GREP_FILES} -in "coreboot" | grep -v "$EXCLUDE"; diff --git a/util/lint/lint-stable-022-clang-format b/util/lint/lint-stable-022-clang-format index 9c94fbc060..4a602f798a 100755 --- a/util/lint/lint-stable-022-clang-format +++ b/util/lint/lint-stable-022-clang-format @@ -4,14 +4,21 @@ # DESCR: Run clang-format on white-listed directories -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" -# until we require this by default, we need a list of opted-in directories -if [ ! -f .clang-format-scope ]; then +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + +# Until we require this by default, we need a list of opted-in directories +# If the script isn't looking at a git repository, just exit +if [ ! -f .clang-format-scope ] || [ "${IN_GIT_TREE}" -eq 0 ]; then exit 0 fi -files_to_check=$(git log HEAD~..HEAD --format= --name-only $(cat .clang-format-scope) |grep "\.[ch]$") +files_to_check=$(${GIT} log HEAD~..HEAD --format= --name-only $(cat .clang-format-scope) | grep "\.[ch]$") # nothing to do if [ -z "$files_to_check" ]; then @@ -19,9 +26,9 @@ if [ -z "$files_to_check" ]; then fi if [ $(clang-format $files_to_check | wc -l) -gt 0 ]; then - if [ "$(git diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff)" != "" ]; then + if [ "$(${GIT} diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff)" != "" ]; then echo "Coding style mismatch. The following patch fixes it:" - git diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff + ${GIT} diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff exit 0 fi fi diff --git a/util/lint/lint-stable-023-filenames b/util/lint/lint-stable-023-filenames index 8b519a80dd..c107deda7b 100755 --- a/util/lint/lint-stable-023-filenames +++ b/util/lint/lint-stable-023-filenames @@ -4,11 +4,17 @@ # DESCR: Check for illegal characters in filename -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" -# Skip check if git isn't available -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - git ls-files | grep "[^A-Za-z0-9/_\.-]" +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + +# Exit if the code isn't in a git repo +if [ "${IN_GIT_TREE}" -eq 0 ]; then + exit 0 fi + +${FIND_FILES} | grep "[^A-Za-z0-9/_\.-]" diff --git a/util/lint/lint-stable-026-line-endings b/util/lint/lint-stable-026-line-endings index ec895d144f..d1b8ed3c90 100755 --- a/util/lint/lint-stable-026-line-endings +++ b/util/lint/lint-stable-026-line-endings @@ -4,17 +4,14 @@ # DESCR: Verify that files don't contain windows line endings -LC_ALL=C export LC_ALL +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" -EXCLUDE='^3rdparty/\|^payloads/external\|^.git' +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" -# Use git grep if the code is in a git repo, otherwise use grep. -if [ -n "$(command -v git)" ] && \ - [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] -then - GREP_FILES="git grep -IlP" -else - GREP_FILES="grep -rIlP" -fi +EXCLUDE='^3rdparty/\|^payloads/external\|^.git\|build\|util/crossgcc/xgcc' -${GREP_FILES} "\r$" | grep -v "$EXCLUDE" +${GREP_FILES} -IlP "\r$" | grep -v "$EXCLUDE" |