Debian Codegraph @

tools/spdx-ensure

raw symbols SCIP
1 #!/bin/bash
2 # SPDX-FileCopyrightText: 2022 Tillitis AB <tillitis.se>
3 # SPDX-License-Identifier: BSD-2-Clause
4
5 set -eu
6
7 # Check for the SPDX tag in all files in the repo. Exit with a non-zero code if
8 # some is missing. The missingok arrays below contain files and directories
9 # with files where the the tag is not required.
10
11 cd "${0%/*}"
12 cd ..
13
14 tag="SPDX-License-Identifier:"
15
16 missingok_dirs=(
17 .github/workflows/
18 )
19
20 missingok_files=(
21 .editorconfig
22 .gitignore
23 .golangci.yml
24 LICENSE
25 LICENSES/BSD-2-Clause.txt
26 Makefile
27 RELEASE.md
28 README.md
29 go.mod
30 go.sum
31 )
32
33 is_missingok() {
34 item="$1"
35 # ok for empty files
36 [[ -f "$item" ]] && [[ ! -s "$item" ]] && return 0
37 for fileok in "${missingok_files[@]}"; do
38 [[ "$item" = "$fileok" ]] && return 0
39 done
40 for dirok in "${missingok_dirs[@]}"; do
41 [[ "$item" =~ ^$dirok ]] && return 0
42 done
43 return 1
44 }
45
46 printf "* Checking for SPDX tags in %s\n" "$PWD"
47
48 mapfile -t repofiles < <(git ls-files || true)
49 if [[ -z "${repofiles[*]}" ]]; then
50 printf "* No files in the repo?!\n"
51 exit 1
52 fi
53
54 failed=0
55
56 printed=0
57 for fileok in "${missingok_files[@]}"; do
58 [[ -f "$fileok" ]] && continue
59 if (( !printed )); then
60 printf "* Some files in missingok_files are themselves missing:\n"
61 printed=1
62 failed=1
63 fi
64 printf "%s\n" "$fileok"
65 done
66
67 printed=0
68 for dirok in "${missingok_dirs[@]}"; do
69 [[ -d "$dirok" ]] && continue
70 if (( !printed )); then
71 printf "* Some dirs in missingok_dirs are themselves missing:\n"
72 printed=1
73 failed=1
74 fi
75 printf "%s\n" "$dirok"
76 done
77
78 printed=0
79 for file in "${repofiles[@]}"; do
80 is_missingok "$file" && continue
81 if ! grep -q "$tag" "$file"; then
82 if (( !printed )); then
83 printf "* Files missing the SPDX tag:\n"
84 printed=1
85 failed=1
86 fi
87 printf "%s\n" "$file"
88 fi
89 done
90
91 exit "$failed"