xref: /dpdk/devtools/check-spdx-tag.sh (revision 68a03efeed657e6e05f281479b33b51102797e15)
1#! /bin/sh
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright 2020 Microsoft Corporation
4#
5# Produce a list of files with incorrect license tags
6
7errors=0
8warnings=0
9quiet=false
10verbose=false
11
12print_usage () {
13    echo "usage: $(basename $0) [-q] [-v]"
14    exit 1
15}
16
17check_spdx() {
18    if  $verbose;  then
19	echo "Files without SPDX License"
20	echo "--------------------------"
21    fi
22    git grep -L SPDX-License-Identifier -- \
23	':^.git*' ':^.ci/*' ':^.travis.yml' \
24	':^README' ':^MAINTAINERS' ':^VERSION' ':^ABI_VERSION' \
25	':^*/Kbuild' ':^*/README' \
26	':^license/' ':^config/' ':^buildtools/' \
27	':^*.cocci' ':^*.abignore' \
28	':^*.map' ':^*.ini' ':^*.data' ':^*.cfg' ':^*.txt' \
29	':^*.svg' ':^*.png'\
30	> $tmpfile
31
32    errors=$(wc -l < $tmpfile)
33    $quiet || cat $tmpfile
34}
35
36check_boilerplate() {
37    if $verbose ; then
38	echo
39	echo "Files with redundant license text"
40	echo "---------------------------------"
41    fi
42
43    git grep -l Redistribution -- \
44	':^license/' ':^/devtools/check-spdx-tag.sh' > $tmpfile
45
46    warnings=$(wc -l <$tmpfile)
47    $quiet || cat $tmpfile
48}
49
50while getopts qvh ARG ; do
51	case $ARG in
52		q ) quiet=true ;;
53		v ) verbose=true ;;
54		h ) print_usage ; exit 0 ;;
55		? ) print_usage ; exit 1 ;;
56	esac
57done
58shift $(($OPTIND - 1))
59
60tmpfile=$(mktemp -t dpdk.checkspdx.XXXXXX)
61trap 'rm -f -- "$tmpfile"' INT TERM HUP EXIT
62
63check_spdx
64$quiet || echo
65
66check_boilerplate
67
68$quiet || echo
69echo "total: $errors errors, $warnings warnings"
70exit $errors
71