summaryrefslogtreecommitdiff
path: root/util/lint/lint-000-license-headers
blob: c1110ec75d7567a33d45f723c8ec8c2990d13267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
# This file is part of the coreboot project.
#
# Copyright (C) 2010 coresystems GmbH
# Copyright (C) 2016 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
#
# DESCR: Check that files in have valid license headers
# $1 is an optional command line parameter containing directories to check

# regex list of files and directories to exclude from the search
HEADER_EXCLUDED="\
^src/lib/gnat/|\
^src/vendorcode/|\
^util/amdtools/example_input/|\
^util/cbfstool/lzma/|\
^util/kconfig/|\
Kconfig|\
\<COPYING\>|\
\<LICENSE\>|\
\<README\>|\
Changelog|\
TODO|\
EXAMPLE|\
NEWS|\
ChangeLog|\
Dockerfile|\
\.in$|\
\.[18]$|\
\.md$|\
\.wiki$|\
\.xxdump$|\
\.spec$|\
\.txt$|\
\.jpg$|\
\.cksum$|\
\.bin$|\
\.vbt$|\
\.hex$|\
\.patch$|\
_shipped$|\
/microcode-[^/]*.h$|\
/sdram-.*\.inc$|\
Makefile\.inc|\
\.fmd|\
\.cb|\
\.cfg$|\
\.spd|\
config|\
cmos\.layout|\
cmos\.default\
"

HEADER_TEXT="license header"

#space separated list of directories to test
if [ "$1" = "" ]; then
	HEADER_DIRS="src util"
else
	HEADER_DIRS="$1"
fi

if [ "$2" = "SPDX_ONLY" ]; then
	SPDX_ONLY=1
	HEADER_TEXT="SPDX identifier"
fi

LC_ALL=C export LC_ALL

#get initial list from git, removing HEADER_EXCLUDED files.
#make a copy to check for the old style header later.
headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)")

#update headerlist by removing files that match the license string
check_for_license() {
	if [ -n "$headerlist" ] && [ -z "$2" ]; then
		headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)"
	elif [ -n "$headerlist" ]; then
		p1list="$(grep -il "$1" $headerlist 2>/dev/null)"
		p2list="$(grep -il "$2" $headerlist 2>/dev/null)"

		# Make list of files that were in both previous lists
		pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \
			sort | uniq -d)"

		# Remove all files that were in both of the previous lists
		# Note that this is unstable if we ever get any filenames
		# with spaces.
		headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \
			sort | uniq -u)"
	fi
}

#search the files for license headers
check_for_license 'SPDX-License-Identifier: Apache-2.0'
check_for_license 'SPDX-License-Identifier: BSD-3-Clause'
check_for_license 'SPDX-License-Identifier: GPL-2.0-only'
check_for_license 'SPDX-License-Identifier: GPL-2.0-or-later'
check_for_license 'SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note'
check_for_license 'SPDX-License-Identifier: GPL-3.0-only'
check_for_license 'SPDX-License-Identifier: GPL-3.0-or-later'
check_for_license 'SPDX-License-Identifier: ISC'
check_for_license 'SPDX-License-Identifier: MIT'
check_for_license 'SPDX-License-Identifier: X11'

# This is 4 clause ("with advertising") but the University of Berkeley
# declared that 4th clause void, see
# ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
# With this, BSD-4-Clause-UC becomes GPLv2 compatible, and so SPDX doesn't
# differentiate between this license with or without advertising.
check_for_license 'SPDX-License-Identifier: BSD-4-Clause-UC'

if [ ! "${SPDX_ONLY}" = "1" ]; then
check_for_license "under the terms of the GNU General Public License" \
		"WITHOUT ANY WARRANTY"
check_for_license 'IS PROVIDED .*"AS IS"'
check_for_license 'IS DISTRIBUTED .*"AS IS"'
check_for_license "IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE"
check_for_license '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES'
check_for_license 'assumes any liability or responsibility for the use'
check_for_license 'THE AUTHORS DISCLAIM.*ALL WARRANTIES WITH REGARD TO THIS SOFTWARE'
check_for_license 'No license required'
check_for_license 'GNU Lesser General Public'
fi

for file in $headerlist; do
	# Verify the file exists, and has content that requires a header
	# This assumes that a file that has 4 lines or fewer is not notable
	# enough to require a license.
	if [ -f "$file" ] && [ "$(wc -l < "$file")" -gt 4 ]; then
		echo "$file has no recognized ${HEADER_TEXT}."
	fi
done