checks for license information parity between Cargo.toml and source files
This commit is contained in:
parent
42abb1791d
commit
5670793f90
|
@ -2,23 +2,30 @@
|
|||
|
||||
set -e
|
||||
|
||||
# check usage
|
||||
if ! test -n "$1"; then
|
||||
printf "Usage: %s [pattern...]\n" "$0" 1>&2
|
||||
exit 64 # sysexits(3) EX_USAGE
|
||||
# check if we have tomcat(1)
|
||||
if ! command -v tomcat >/dev/null 2>&1; then
|
||||
printf "%s: Missing dependency: tomcat(1)\n"
|
||||
exit 69 # sysexits(3) EX_UNAVAILABLE
|
||||
fi
|
||||
|
||||
# check if we have rg(1); if not, use find(1) and sed(1) instead
|
||||
if ! command -v rg >/dev/null 2>&1; then
|
||||
files="$(find "$PWD" -name "$1")"
|
||||
for file in $files; do
|
||||
if ! test -n \
|
||||
"$(sed -n '\|// SPDX-License-Identifier: .*|p' <"$file")"
|
||||
for toml in $(find "$PWD" -name "Cargo.toml"); do
|
||||
printf "Project: %s\n" "$(tomcat package.name "$toml")"
|
||||
for file in $(find "$(printf "%s\n" "$toml" | sed 's/Cargo\.toml/src/g')" -name "*.rs"); do
|
||||
info="$(head -n 2 "$file")"
|
||||
toml_lic="$(tomcat package.license "$toml")"
|
||||
if ! test -n "$toml_lic"; then
|
||||
printf "%s: Missing license information\n" "$toml"
|
||||
continue 2
|
||||
fi
|
||||
if ! [ "$toml_lic" = "$(printf "%s\n" "$info" | tail -n 1 |\
|
||||
sed -n 's/\/\/ SPDX-License-Identifier: //p')" ]
|
||||
then
|
||||
! test "$file" = "$1" && printf "%s\n" "$file"
|
||||
printf "%s: Missing or malformed license information\n" "$file"
|
||||
fi
|
||||
if ! test -n "$(printf "%s\n" "$info" | head -n 1 |\
|
||||
sed -n '/\/\/ Copyright (c) .\+/p')"
|
||||
then
|
||||
printf "%s: Missing or malformed copyright holder information\n" "$file"
|
||||
fi
|
||||
done
|
||||
else
|
||||
rg --multiline --files-without-match --glob "$1" --pcre2 \
|
||||
'(?<!\n)((//)|(#)) Copyright \(c\) \d+ [A-z, ]+\n((//)|(#)) SPDX-License-Identifier: .*\n'
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue