44#
55# Produce a list of files with incorrect license tags
66
7- errors=0
7+ missing_spdx=0
8+ wrong_license=0
89warnings=0
910quiet=false
1011verbose=false
@@ -14,29 +15,47 @@ print_usage () {
1415 exit 1
1516}
1617
18+ no_license_list=\
19+ ' :^.git* :^.mailmap :^.ci/* :^README :^*/README* :^MAINTAINERS :^VERSION :^ABI_VERSION ' \
20+ ' :^license/ :^config/ :^buildtools/ :^*.abignore :^*.cocci :^*/poetry.lock ' \
21+ ' :^*/Kbuild :^kernel/linux/uapi/version ' \
22+ ' :^*.map :^*.ini :^*.data :^*.json :^*.cfg :^*.txt :^*.svg :^*.png'
23+
1724check_spdx () {
18- if $verbose ; then
25+ if $verbose ; then
1926 echo " Files without SPDX License"
2027 echo " --------------------------"
2128 fi
22- git grep -L SPDX-License-Identifier -- \
23- ' :^.git*' ' :^.mailmap' ' :^.ci/*' \
24- ' :^README' ' :^MAINTAINERS' ' :^VERSION' ' :^ABI_VERSION' \
25- ' :^*/Kbuild' ' :^*/README*' \
26- ' :^license/' ' :^config/' ' :^buildtools/' ' :^*/poetry.lock' \
27- ' :^kernel/linux/uapi/version' \
28- ' :^*.cocci' ' :^*.abignore' \
29- ' :^*.map' ' :^*.ini' ' :^*.data' ' :^*.json' ' :^*.cfg' ' :^*.txt' \
30- ' :^*.svg' ' :^*.png' \
31- > $tmpfile
32-
33- errors=$( wc -l < $tmpfile )
29+ git grep -L SPDX-License-Identifier -- $no_license_list > $tmpfile
30+
31+ missing_spdx=$( wc -l < $tmpfile )
32+ $quiet || cat $tmpfile
33+ }
34+
35+ build_exceptions_list () {
36+ grep ' .*|.*|.*|.*' license/exceptions.txt | grep -v ' TB Approval Date' |
37+ while IFS=' |' read license tb_date gb_date pattern ; do
38+ license=$( echo $license ) # trim spaces
39+ git grep -l " SPDX-License-Identifier:[[:space:]]*$license " $pattern |
40+ sed -e ' s/^/:^/'
41+ done
42+ }
43+
44+ check_licenses () {
45+ if $verbose ; then
46+ echo " Files with wrong license and no exception"
47+ echo " -----------------------------------------"
48+ fi
49+ exceptions=$( build_exceptions_list)
50+ git grep -l SPDX-License-Identifier: -- $no_license_list $exceptions |
51+ xargs grep -L -E ' SPDX-License-Identifier:[[:space:]]*\(?BSD-3-Clause' > $tmpfile
52+
53+ wrong_license=$( wc -l < $tmpfile )
3454 $quiet || cat $tmpfile
3555}
3656
3757check_boilerplate () {
3858 if $verbose ; then
39- echo
4059 echo " Files with redundant license text"
4160 echo " ---------------------------------"
4261 fi
@@ -62,10 +81,13 @@ tmpfile=$(mktemp -t dpdk.checkspdx.XXXXXX)
6281trap ' rm -f -- "$tmpfile"' INT TERM HUP EXIT
6382
6483check_spdx
65- $quiet || echo
84+ $verbose && echo
85+
86+ check_licenses
87+ $verbose && echo
6688
6789check_boilerplate
90+ $verbose && echo
6891
69- $quiet || echo
70- echo " total: $errors errors, $warnings warnings"
71- exit $errors
92+ echo " total: $missing_spdx missing SPDX, $wrong_license license errors, $warnings warnings"
93+ exit $(( missing_spdx + wrong_license))
0 commit comments