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