@@ -6,7 +6,7 @@ IFS=$'\n\t'
66cd " $( dirname " $0 " ) " /..
77
88# shellcheck disable=SC2154
9- trap ' s=$?; echo >&2 "$0: Error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR
9+ trap ' s=$?; echo >&2 "$0: error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR
1010
1111# USAGE:
1212# ./tools/tidy.sh
@@ -201,6 +201,44 @@ else
201201 warn " 'shellcheck' is not installed"
202202fi
203203
204+ # License check
205+ # TODO: This check is still experimental and does not track all files that should be tracked.
206+ if [[ -f tools/.tidy-check-license-headers ]]; then
207+ info " checking license headers (experimental)"
208+ failed_files=' '
209+ for p in $( eval $( < tools/.tidy-check-license-headers) ) ; do
210+ # TODO: More file types?
211+ case " $( basename " ${p} " ) " in
212+ * .sh) prefix=(" # " ) ;;
213+ * .rs | * .c | * .h | * .cpp | * .hpp | * .s | * .S) prefix=(" // " " /* " ) ;;
214+ * .ld | * .x) prefix=(" /* " ) ;;
215+ * ) error " unrecognized file type: ${p} " ;;
216+ esac
217+ # TODO: The exact line number is not actually important; it is important
218+ # that it be part of the top-level comments of the file.
219+ line=" 1"
220+ case " ${p} " in
221+ * .sh) line=" 2" ;; # shebang
222+ esac
223+ header_found=' '
224+ for pre in " ${prefix[@]} " ; do
225+ if [[ " $( grep -E -n " ${pre} SPDX-License-Identifier: " " ${p} " ) " == " ${line} :${pre} SPDX-License-Identifier: " * ]]; then
226+ header_found=' 1'
227+ continue
228+ fi
229+ done
230+ if [[ -z " ${header_found} " ]]; then
231+ failed_files+=" ${p} :${line} " $' \n '
232+ fi
233+ done
234+ if [[ -n " ${failed_files} " ]]; then
235+ error " license-check failed: please add SPDX-License-Identifier to the following files"
236+ echo " ======================================="
237+ echo -n " ${failed_files} "
238+ echo " ======================================="
239+ fi
240+ fi
241+
204242# Spell check (if config exists)
205243if [[ -f .cspell.json ]]; then
206244 info " spell checking"
0 commit comments