blob: e705929ce54794088708160007c901f11522bc22 [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="\
22^src/vendorcode/|\
23^util/kconfig/|\
24^util/romcc/tests|\
25^util/romcc/results|\
26^util/gitconfig|\
27Kconfig|\
28\<COPYING\>|\
29\<LICENSE\>|\
30\<README\>|\
31Changelog|\
32TODO|\
33EXAMPLE|\
34\.txt$|\
35\.jpg$|\
36\.cksum$|\
37\.bin$|\
38\.hex$|\
39\.patch$|\
40_shipped$|\
41/microcode-[^/]*.h$|\
42/sdram-.*\.inc$|\
Martin Roth84129b82016-04-11 13:35:59 -060043Makefile\.inc|\
44\.fmd|\
Naresh G Solanki358b2b32016-10-27 23:13:37 +053045\.cb|\
Martin Roth84129b82016-04-11 13:35:59 -060046\.cfg$|\
47\.spd|\
48config|\
49cmos\.layout|\
50cmos\.default\
Martin Rothc4511e22016-01-12 10:25:49 -070051"
52
53#space separated list of directories to test
54if [ "$1" = "" ]; then
55 HEADER_DIRS="src util"
56else
57 HEADER_DIRS="$1"
58fi
Patrick Georgie8826302010-11-19 10:16:43 +000059
60LC_ALL=C export LC_ALL
Martin Rothc4511e22016-01-12 10:25:49 -070061
62#get initial list from git, removing HEADER_EXCLUDED files.
63#make a copy to check for the old style header later.
64headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)")
65
66#update headerlist by removing files that match the license string
67check_for_license() {
Martin Roth84129b82016-04-11 13:35:59 -060068 if [ -n "$headerlist" ] && [ -z "$2" ]; then
Martin Rothf8db0282016-01-21 13:20:39 -070069 headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)"
Martin Roth84129b82016-04-11 13:35:59 -060070 elif [ -n "$headerlist" ]; then
71 p1list="$(grep -il "$1" $headerlist 2>/dev/null)"
72 p2list="$(grep -il "$2" $headerlist 2>/dev/null)"
Martin Rothf8db0282016-01-21 13:20:39 -070073
74 # Make list of files that were in both previous lists
Martin Roth84129b82016-04-11 13:35:59 -060075 pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \
Martin Rothf8db0282016-01-21 13:20:39 -070076 sort | uniq -d)"
77
78 # Remove all files that were in both of the previous lists
79 # Note that this is unstable if we ever get any filenames
80 # with spaces.
81 headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \
82 sort | uniq -u)"
83 fi
Martin Rothc4511e22016-01-12 10:25:49 -070084}
85
86#search the files for license headers
Martin Rothf8db0282016-01-21 13:20:39 -070087check_for_license "under the terms of the GNU General Public License" \
88 "WITHOUT ANY WARRANTY"
Martin Rothc4511e22016-01-12 10:25:49 -070089check_for_license 'IS PROVIDED .*"AS IS"'
Martin Roth84129b82016-04-11 13:35:59 -060090check_for_license 'IS DISTRIBUTED .*"AS IS"'
Martin Rothc4511e22016-01-12 10:25:49 -070091check_for_license "IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE"
92check_for_license '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES'
Martin Roth84129b82016-04-11 13:35:59 -060093check_for_license 'No license required'
Martin Rothc4511e22016-01-12 10:25:49 -070094
95for file in $headerlist; do
Martin Roth03e9d6a2017-02-09 16:44:24 -080096 # Verify the file exists, and has content that requires a header
97 # This assumes that a file that has 4 lines or fewer is not notable
98 # enough to require a license.
99 if [ -f "$file" ] && [ "$(wc -l < "$file")" -gt 4 ]; then
Martin Rothc4511e22016-01-12 10:25:49 -0700100 echo "$file has no recognized license header."
101 fi
102done