| 1 | #!/usr/bin/env sh |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
| 5 | # DESCR: Check for superfluous whitespace in the tree |
| 6 | |
| 7 | LINTDIR="$( |
| 8 | cd -- "$(dirname "$0")" > /dev/null 2>&1 || return |
| 9 | pwd -P |
| 10 | )" |
| 11 | # shellcheck source=helper_functions.sh |
| 12 | . "${LINTDIR}/helper_functions.sh" |
| 13 | |
| 14 | EXCLUDELIST='^src/vendorcode/|^util/kconfig/|^util/nvidia/cbootimage|^util/goswid|__pycache__|COPYING|LICENSE|README|_shipped$|\.patch$|\.bin$|\.hex$|\.jpg$|\.gif$|\.ttf$|\.woff$|\.png$|\.eot$|\.vbt$|\.ico$|\.md$|\.apcb$|\.dtb$' |
| 15 | INCLUDELIST="src util payloads Makefile* toolchain.mk tests" |
| 16 | |
| 17 | # shellcheck disable=SC2086,SC2046 |
| 18 | if uname | grep -qi "linux"; then |
| 19 | grep -n -H "[[:space:]][[:space:]]*$" \ |
| 20 | $(${FIND_FILES} ${INCLUDELIST} ${FINDOPTS} | \ |
| 21 | grep -Ev "($EXCLUDELIST)" ) | \ |
| 22 | sed -e "s,^.*$,File & has lines ending with whitespace.," |
| 23 | else |
| 24 | # The above form is much (100x) faster, but doesn't work |
| 25 | # on all systems. A for loop also works but takes 30% longer |
| 26 | ${FIND_FILES} ${INCLUDELIST} ${FINDOPTS}| \ |
| 27 | grep -Ev "($EXCLUDELIST)" | \ |
| 28 | xargs -I % \ |
| 29 | grep -l "[[:space:]][[:space:]]*$" % | \ |
| 30 | sed -e "s,^.*$,File & has lines ending with whitespace.," |
| 31 | fi |