Martin Roth | 0ad5fbd | 2020-12-24 12:06:38 -0700 | [diff] [blame] | 1 | #!/usr/bin/env sh |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 2 | # |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 5 | # DESCR: Check that files in have valid license headers |
| 6 | # $1 is an optional command line parameter containing directories to check |
| 7 | |
| 8 | # regex list of files and directories to exclude from the search |
| 9 | HEADER_EXCLUDED="\ |
Patrick Georgi | deea25b | 2020-05-10 16:34:10 +0200 | [diff] [blame] | 10 | ^src/commonlib/bsd/lz4.c.inc\$|\ |
| 11 | ^src/cpu/x86/16bit/entry16.inc\$|\ |
| 12 | ^src/device/oprom/x86emu/|\ |
| 13 | ^src/device/oprom/include/x86emu/|\ |
| 14 | ^src/device/oprom/yabel/|\ |
Jacob Garber | 10999ea6 | 2020-05-18 13:36:58 -0600 | [diff] [blame] | 15 | ^src/drivers/net/ne2k.c\$|\ |
Patrick Georgi | deea25b | 2020-05-10 16:34:10 +0200 | [diff] [blame] | 16 | ^src/drivers/xgi/common/initdef.h\$|\ |
| 17 | ^src/drivers/xgi/common/vstruct.h\$|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 18 | ^src/lib/gnat/|\ |
Patrick Georgi | deea25b | 2020-05-10 16:34:10 +0200 | [diff] [blame] | 19 | ^src/lib/lzmadecode.[ch]\$|\ |
| 20 | ^src/lib/stack.c\$|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 21 | ^src/vendorcode/|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 22 | ^util/amdtools/example_input/|\ |
| 23 | ^util/cbfstool/lzma/|\ |
Patrick Georgi | deea25b | 2020-05-10 16:34:10 +0200 | [diff] [blame] | 24 | ^util/cbfstool/lz4/|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 25 | ^util/kconfig/|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 26 | Kconfig|\ |
| 27 | \<COPYING\>|\ |
| 28 | \<LICENSE\>|\ |
| 29 | \<README\>|\ |
| 30 | Changelog|\ |
Jacob Garber | 07201d7 | 2020-09-08 12:25:44 -0600 | [diff] [blame] | 31 | AUTHORS|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 32 | TODO|\ |
| 33 | EXAMPLE|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 34 | NEWS|\ |
| 35 | ChangeLog|\ |
| 36 | Dockerfile|\ |
| 37 | \.in$|\ |
| 38 | \.[18]$|\ |
| 39 | \.md$|\ |
| 40 | \.wiki$|\ |
| 41 | \.xxdump$|\ |
| 42 | \.spec$|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 43 | \.txt$|\ |
| 44 | \.jpg$|\ |
| 45 | \.cksum$|\ |
| 46 | \.bin$|\ |
Martin Roth | dea1333 | 2018-05-04 09:19:07 -0600 | [diff] [blame] | 47 | \.vbt$|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 48 | \.hex$|\ |
| 49 | \.patch$|\ |
| 50 | _shipped$|\ |
| 51 | /microcode-[^/]*.h$|\ |
| 52 | /sdram-.*\.inc$|\ |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 53 | Makefile\.inc|\ |
| 54 | \.fmd|\ |
Naresh G Solanki | 358b2b3 | 2016-10-27 23:13:37 +0530 | [diff] [blame] | 55 | \.cb|\ |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 56 | \.cfg$|\ |
| 57 | \.spd|\ |
| 58 | config|\ |
| 59 | cmos\.layout|\ |
| 60 | cmos\.default\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 61 | " |
| 62 | |
| 63 | #space separated list of directories to test |
| 64 | if [ "$1" = "" ]; then |
| 65 | HEADER_DIRS="src util" |
| 66 | else |
| 67 | HEADER_DIRS="$1" |
| 68 | fi |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 69 | |
| 70 | LC_ALL=C export LC_ALL |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 71 | |
| 72 | #get initial list from git, removing HEADER_EXCLUDED files. |
| 73 | #make a copy to check for the old style header later. |
| 74 | headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)") |
| 75 | |
| 76 | #update headerlist by removing files that match the license string |
| 77 | check_for_license() { |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 78 | if [ -n "$headerlist" ] && [ -z "$2" ]; then |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 79 | headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)" |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 80 | elif [ -n "$headerlist" ]; then |
| 81 | p1list="$(grep -il "$1" $headerlist 2>/dev/null)" |
| 82 | p2list="$(grep -il "$2" $headerlist 2>/dev/null)" |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 83 | |
| 84 | # Make list of files that were in both previous lists |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 85 | pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \ |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 86 | sort | uniq -d)" |
| 87 | |
| 88 | # Remove all files that were in both of the previous lists |
| 89 | # Note that this is unstable if we ever get any filenames |
| 90 | # with spaces. |
| 91 | headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \ |
| 92 | sort | uniq -u)" |
| 93 | fi |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | #search the files for license headers |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 97 | check_for_license 'SPDX-License-Identifier: Apache-2.0' |
Patrick Georgi | e03132a | 2020-05-10 19:56:54 +0200 | [diff] [blame] | 98 | check_for_license 'SPDX-License-Identifier: BSD-2-Clause' |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 99 | check_for_license 'SPDX-License-Identifier: BSD-3-Clause' |
| 100 | check_for_license 'SPDX-License-Identifier: GPL-2.0-only' |
| 101 | check_for_license 'SPDX-License-Identifier: GPL-2.0-or-later' |
Rajat Jain | 9990011 | 2020-03-27 13:12:47 -0700 | [diff] [blame] | 102 | check_for_license 'SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note' |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 103 | check_for_license 'SPDX-License-Identifier: GPL-3.0-only' |
| 104 | check_for_license 'SPDX-License-Identifier: GPL-3.0-or-later' |
Patrick Georgi | 878a7a7 | 2020-05-10 21:19:04 +0200 | [diff] [blame] | 105 | check_for_license 'SPDX-License-Identifier: HPND' |
| 106 | check_for_license 'SPDX-License-Identifier: HPND-sell-variant' |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 107 | check_for_license 'SPDX-License-Identifier: ISC' |
| 108 | check_for_license 'SPDX-License-Identifier: MIT' |
| 109 | check_for_license 'SPDX-License-Identifier: X11' |
| 110 | |
Patrick Georgi | e342cd3 | 2020-03-04 14:58:49 +0100 | [diff] [blame] | 111 | # This is 4 clause ("with advertising") but the University of Berkeley |
| 112 | # declared that 4th clause void, see |
| 113 | # ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change |
| 114 | # With this, BSD-4-Clause-UC becomes GPLv2 compatible, and so SPDX doesn't |
| 115 | # differentiate between this license with or without advertising. |
| 116 | check_for_license 'SPDX-License-Identifier: BSD-4-Clause-UC' |
| 117 | |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 118 | for file in $headerlist; do |
Martin Roth | 03e9d6a | 2017-02-09 16:44:24 -0800 | [diff] [blame] | 119 | # Verify the file exists, and has content that requires a header |
| 120 | # This assumes that a file that has 4 lines or fewer is not notable |
| 121 | # enough to require a license. |
| 122 | if [ -f "$file" ] && [ "$(wc -l < "$file")" -gt 4 ]; then |
Jacob Garber | d2fea1a | 2020-05-18 13:25:18 -0600 | [diff] [blame] | 123 | echo "$file has no recognized SPDX identifier." |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 124 | fi |
| 125 | done |