Check for license information parity #36

Merged
mars merged 9 commits from :main into main 2022-11-17 06:30:36 +00:00
1 changed files with 36 additions and 2 deletions

View File

@ -1,4 +1,38 @@
#!/bin/sh
# Depends on: `rg` (ripgrep)
! rg --multiline --files-without-match --glob '*.rs' --pcre2 '(?<!\n)((//)|(#)) Copyright \(c\) \d+ [A-z, ]+\n((//)|(#)) SPDX-License-Identifier: .*\n'
set -e
# 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
dir="$(pwd | sed 's/\//\n/g' | tail -n 1)"
for toml in $(find "$PWD" -name "Cargo.toml"); do
emma marked this conversation as resolved Outdated
Outdated
Review

This includes false positive generated Rust source files (i.e. from the wayland-protocols crate) in the target/ directory, so target/ needs to be excluded from the search path.

This includes false positive generated Rust source files (i.e. from the wayland-protocols crate) in the `target/` directory, so `target/` needs to be excluded from the search path.
printf "Project: %s\n" "$(tomcat package.name "$toml")"
for file in $(find "$(printf "%s\n" "$toml" |\
sed 's/Cargo\.toml/src/g')" -name "*.rs")
emma marked this conversation as resolved Outdated
Outdated
Review

You need to test for the // Copyright (c) 2022 Marceline Cramer copyright holder line at the beginning too.

You need to test for the `// Copyright (c) 2022 Marceline Cramer` copyright holder line at the beginning too.
do
info="$(head -n 2 "$file")"
toml_lic="$(tomcat package.license "$toml")"
if ! test -n "$toml_lic"; then
printf "%s: Missing license information\n" "$(printf "%s\n" "$toml" |\
sed "s/^.\+$dir\///g")"
emma marked this conversation as resolved Outdated
Outdated
Review

If you hate ripgrep this much you can go ahead and ditch support for it if you want.

If you hate ripgrep this much you can go ahead and ditch support for it if you want.
continue 2
fi
if ! [ "$toml_lic" = "$(printf "%s\n" "$info" | tail -n 1 |\
sed -n 's/\/\/ SPDX-License-Identifier: //p')" ]
then
printf "%s: Missing or malformed license information\n" \
"$(printf "%s\n" "$file" | sed "s/^.\+$dir\///g")"
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" \
"$(printf "%s\n" "$file" | sed "s/^.\+$dir\///g")"
fi
done
done