util/lint: Update tools that use git to use a library

Each of the tools that used git had similar functionality. This combines
all of that into a single script that gets sourced by each.  This makes
maintenance much easier.

By doing this and updating each of the scripts to do the correct thing
if the script isn't being run in a git repository, it makes them work
much better for the releases, which are just released as a tarball,
without any attached git repository.

Change-Id: I61ba1cc4f7205e0d4baf993588bbc774120405cb
Signed-off-by: Martin Roth <martin@coreboot.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/64973
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Elyes Haouas <ehaouas@noos.fr>
This commit is contained in:
Martin Roth
2022-06-03 00:06:57 -06:00
committed by Martin L Roth
parent 7726a7f272
commit d81debd946
23 changed files with 273 additions and 152 deletions

View File

@ -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

View File

@ -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() {

View File

@ -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 )

View File

@ -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

View File

@ -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" | \

View File

@ -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 &

View File

@ -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
if ! ${GIT} log -n 1 | grep -q '[[:space:]]\+Signed-off-by: '; then
echo "No Signed-off-by line in commit message"
fi
fi

View File

@ -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:]]*$" % | \

View File

@ -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]$" | \

View File

@ -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"

View File

@ -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

View File

@ -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" \

View File

@ -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:'

View File

@ -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.,"

View File

@ -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

View File

@ -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" | \

View File

@ -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
)"
# shellcheck source=helper_functions.sh
. "${LINTDIR}/helper_functions.sh"
SYMBOLS='CONFIG_ARCH_\|CONFIG_MAINBOARD_HAS_'
# 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
#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

View File

@ -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 | \
# 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"
else
# If the code isn't in a git repo, print everything
find . -type l | \
sed 's|\.\/||' | \
grep -v "$EXCLUDED_DIRS"
fi

View File

@ -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

View File

@ -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
)"
# shellcheck source=helper_functions.sh
. "${LINTDIR}/helper_functions.sh"
EXCLUDE='^3rdparty/\|util/crossgcc/xgcc\|Binary file\|coreboot\|COREBOOT\|CorebootPayload\|CorebootModule\|minnowboard.org/Coreboot\|.*\.patch$\|CorebootBdsLib\|^payloads/external'
# 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"
# 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";

View File

@ -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

View File

@ -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/_\.-]"

View File

@ -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"