coreboot-kgpe-d16/util/lint/lint-stable-019-header-files
Martin Roth d81debd946 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>
2022-09-30 19:19:53 +00:00

46 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env sh
#
# SPDX-License-Identifier: GPL-2.0-only
# DESCR: Check for auto-included headers
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'
HEADER_FILES="k\?config rules compiler"
TESTFILE1="src/lib/version.c"
TESTFILE2="src/lib/string.c"
TESTFILE3="src/lib/malloc.c"
TESTFILE4="src/lib/hardwaremain.c"
EXPECTED_FAILURES=4
# Configure to make sure tests fail
if [ "$1" = "--test" ]; then
sed -i.bak "s|^.*SPDX-License-Identifier.*|&\n\n#include <config.h>\n|" "${TESTFILE1}"
sed -i.bak "s|^.*SPDX-License-Identifier.*|&\n\n#include \"kconfig.h\"\n|" "${TESTFILE2}"
sed -i.bak "s|^.*SPDX-License-Identifier.*|&\n\n#include \"compiler.h\"\n|" "${TESTFILE3}"
sed -i.bak "s|^.*SPDX-License-Identifier.*|&\n\n#include <rules.h>\n|" "${TESTFILE4}"
echo "Expect ${EXPECTED_FAILURES} failures."
exit 0
elif [ "$1" = "--reset" ]; then
mv "${TESTFILE1}.bak" "${TESTFILE1}"
mv "${TESTFILE2}.bak" "${TESTFILE2}"
mv "${TESTFILE3}.bak" "${TESTFILE3}"
mv "${TESTFILE4}.bak" "${TESTFILE4}"
exit 0
fi
for header in $HEADER_FILES; do
${GREP_FILES} -n "#[[:blank:]]*include[[:blank:]]\+[\"<][[:blank:]]*${header}\.h[[:blank:]]*[\">]" | \
grep "$INCLUDED_DIRS" | \
grep -v "$EXCLUDED_FILES"; \
done