Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # This file is part of the coreboot project. |
| 3 | # |
| 4 | # Copyright (C) 2010 coresystems GmbH |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 5 | # Copyright (C) 2016 Google Inc. |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 6 | # |
| 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 Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 16 | # |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 17 | # 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 |
| 21 | HEADER_EXCLUDED="\ |
| 22 | ^src/vendorcode/|\ |
| 23 | ^util/kconfig/|\ |
| 24 | ^util/romcc/tests|\ |
| 25 | ^util/romcc/results|\ |
| 26 | ^util/gitconfig|\ |
| 27 | Kconfig|\ |
| 28 | \<COPYING\>|\ |
| 29 | \<LICENSE\>|\ |
| 30 | \<README\>|\ |
| 31 | Changelog|\ |
| 32 | TODO|\ |
| 33 | EXAMPLE|\ |
| 34 | \.txt$|\ |
| 35 | \.jpg$|\ |
| 36 | \.cksum$|\ |
| 37 | \.bin$|\ |
| 38 | \.hex$|\ |
| 39 | \.patch$|\ |
| 40 | _shipped$|\ |
| 41 | /microcode-[^/]*.h$|\ |
| 42 | /sdram-.*\.inc$|\ |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 43 | Makefile\.inc|\ |
| 44 | \.fmd|\ |
Naresh G Solanki | 358b2b3 | 2016-10-27 23:13:37 +0530 | [diff] [blame] | 45 | \.cb|\ |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 46 | \.cfg$|\ |
| 47 | \.spd|\ |
| 48 | config|\ |
| 49 | cmos\.layout|\ |
| 50 | cmos\.default\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 51 | " |
| 52 | |
| 53 | #space separated list of directories to test |
| 54 | if [ "$1" = "" ]; then |
| 55 | HEADER_DIRS="src util" |
| 56 | else |
| 57 | HEADER_DIRS="$1" |
| 58 | fi |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 59 | |
| 60 | LC_ALL=C export LC_ALL |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 61 | |
| 62 | #get initial list from git, removing HEADER_EXCLUDED files. |
| 63 | #make a copy to check for the old style header later. |
| 64 | headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)") |
| 65 | |
| 66 | #update headerlist by removing files that match the license string |
| 67 | check_for_license() { |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 68 | if [ -n "$headerlist" ] && [ -z "$2" ]; then |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 69 | headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)" |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 70 | elif [ -n "$headerlist" ]; then |
| 71 | p1list="$(grep -il "$1" $headerlist 2>/dev/null)" |
| 72 | p2list="$(grep -il "$2" $headerlist 2>/dev/null)" |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 73 | |
| 74 | # Make list of files that were in both previous lists |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 75 | pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \ |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 76 | 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 Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | #search the files for license headers |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 87 | check_for_license "under the terms of the GNU General Public License" \ |
| 88 | "WITHOUT ANY WARRANTY" |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 89 | check_for_license 'IS PROVIDED .*"AS IS"' |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 90 | check_for_license 'IS DISTRIBUTED .*"AS IS"' |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 91 | check_for_license "IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE" |
| 92 | check_for_license '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES' |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 93 | check_for_license 'No license required' |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 94 | |
| 95 | for file in $headerlist; do |
Martin Roth | 03e9d6a | 2017-02-09 16:44:24 -0800 | [diff] [blame] | 96 | # 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 Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 100 | echo "$file has no recognized license header." |
| 101 | fi |
| 102 | done |