blob: 9b3553b4a4b61092cf85bb375ba3581df3c0fb87 [file] [log] [blame]
Patrick Georgie8826302010-11-19 10:16:43 +00001#!/bin/sh
2# This file is part of the coreboot project.
3#
4# Copyright (C) 2010 coresystems GmbH
Martin Rothc4511e22016-01-12 10:25:49 -07005# Copyright (C) 2016 Google Inc.
Patrick Georgie8826302010-11-19 10:16:43 +00006#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
Patrick Georgie8826302010-11-19 10:16:43 +000016#
Martin Rothc4511e22016-01-12 10:25:49 -070017# DESCR: Check that files in have valid license headers
18# $1 is an optional command line parameter containing directories to check
19
20# regex list of files and directories to exclude from the search
21HEADER_EXCLUDED="\
Martin Rothbdad9a82018-05-26 19:47:07 -060022^src/lib/gnat/|\
Martin Rothc4511e22016-01-12 10:25:49 -070023^src/vendorcode/|\
Martin Rothbdad9a82018-05-26 19:47:07 -060024^util/amdtools/example_input/|\
25^util/cbfstool/lzma/|\
Martin Rothc4511e22016-01-12 10:25:49 -070026^util/kconfig/|\
27^util/romcc/tests|\
28^util/romcc/results|\
Martin Rothc4511e22016-01-12 10:25:49 -070029Kconfig|\
30\<COPYING\>|\
31\<LICENSE\>|\
32\<README\>|\
33Changelog|\
34TODO|\
35EXAMPLE|\
Martin Rothbdad9a82018-05-26 19:47:07 -060036NEWS|\
37ChangeLog|\
38Dockerfile|\
39\.in$|\
40\.[18]$|\
41\.md$|\
42\.wiki$|\
43\.xxdump$|\
44\.spec$|\
Martin Rothc4511e22016-01-12 10:25:49 -070045\.txt$|\
46\.jpg$|\
47\.cksum$|\
48\.bin$|\
Martin Rothdea13332018-05-04 09:19:07 -060049\.vbt$|\
Martin Rothc4511e22016-01-12 10:25:49 -070050\.hex$|\
51\.patch$|\
52_shipped$|\
53/microcode-[^/]*.h$|\
54/sdram-.*\.inc$|\
Martin Roth84129b82016-04-11 13:35:59 -060055Makefile\.inc|\
56\.fmd|\
Naresh G Solanki358b2b32016-10-27 23:13:37 +053057\.cb|\
Martin Roth84129b82016-04-11 13:35:59 -060058\.cfg$|\
59\.spd|\
60config|\
61cmos\.layout|\
62cmos\.default\
Martin Rothc4511e22016-01-12 10:25:49 -070063"
64
65#space separated list of directories to test
66if [ "$1" = "" ]; then
67 HEADER_DIRS="src util"
68else
69 HEADER_DIRS="$1"
70fi
Patrick Georgie8826302010-11-19 10:16:43 +000071
72LC_ALL=C export LC_ALL
Martin Rothc4511e22016-01-12 10:25:49 -070073
74#get initial list from git, removing HEADER_EXCLUDED files.
75#make a copy to check for the old style header later.
76headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)")
77
78#update headerlist by removing files that match the license string
79check_for_license() {
Martin Roth84129b82016-04-11 13:35:59 -060080 if [ -n "$headerlist" ] && [ -z "$2" ]; then
Martin Rothf8db0282016-01-21 13:20:39 -070081 headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)"
Martin Roth84129b82016-04-11 13:35:59 -060082 elif [ -n "$headerlist" ]; then
83 p1list="$(grep -il "$1" $headerlist 2>/dev/null)"
84 p2list="$(grep -il "$2" $headerlist 2>/dev/null)"
Martin Rothf8db0282016-01-21 13:20:39 -070085
86 # Make list of files that were in both previous lists
Martin Roth84129b82016-04-11 13:35:59 -060087 pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \
Martin Rothf8db0282016-01-21 13:20:39 -070088 sort | uniq -d)"
89
90 # Remove all files that were in both of the previous lists
91 # Note that this is unstable if we ever get any filenames
92 # with spaces.
93 headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \
94 sort | uniq -u)"
95 fi
Martin Rothc4511e22016-01-12 10:25:49 -070096}
97
98#search the files for license headers
Martin Rothf8db0282016-01-21 13:20:39 -070099check_for_license "under the terms of the GNU General Public License" \
100 "WITHOUT ANY WARRANTY"
Martin Rothc4511e22016-01-12 10:25:49 -0700101check_for_license 'IS PROVIDED .*"AS IS"'
Martin Roth84129b82016-04-11 13:35:59 -0600102check_for_license 'IS DISTRIBUTED .*"AS IS"'
Martin Rothc4511e22016-01-12 10:25:49 -0700103check_for_license "IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE"
104check_for_license '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES'
Martin Rothed0ee0a2017-04-04 14:35:42 -0600105check_for_license 'assumes any liability or responsibility for the use'
106check_for_license 'THE AUTHORS DISCLAIM.*ALL WARRANTIES WITH REGARD TO THIS SOFTWARE'
Martin Roth84129b82016-04-11 13:35:59 -0600107check_for_license 'No license required'
Martin Rothbdad9a82018-05-26 19:47:07 -0600108check_for_license 'GNU Lesser General Public'
Ronald G. Minnich688eec12018-09-14 01:09:46 -0700109check_for_license 'SPDX-License-Identifier:.*GPL-2.0-or-later'
Martin Rothc4511e22016-01-12 10:25:49 -0700110
111for file in $headerlist; do
Martin Roth03e9d6a2017-02-09 16:44:24 -0800112 # Verify the file exists, and has content that requires a header
113 # This assumes that a file that has 4 lines or fewer is not notable
114 # enough to require a license.
115 if [ -f "$file" ] && [ "$(wc -l < "$file")" -gt 4 ]; then
Martin Rothc4511e22016-01-12 10:25:49 -0700116 echo "$file has no recognized license header."
117 fi
118done