From 77f5d5c7ce2996d15cf5dc0eba6f9a486452155a Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 11 Nov 2022 23:56:48 -0500 Subject: [PATCH 1/8] added dependency check for rg --- check_licenses.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/check_licenses.sh b/check_licenses.sh index c02b162..099ee23 100755 --- a/check_licenses.sh +++ b/check_licenses.sh @@ -1,4 +1,12 @@ #!/bin/sh -# Depends on: `rg` (ripgrep) -! rg --multiline --files-without-match --glob '*.rs' --pcre2 '(?/dev/null 2>&1; then + printf "%s: Missing dependency: rg(1)\n" "$0" 1>&2 + exit 71 # sysexits(3) EX_OSERR +else + rg --multiline --files-without-match --glob '*.rs' --pcre2 \ + '(? Date: Fri, 11 Nov 2022 23:59:40 -0500 Subject: [PATCH 2/8] exit code --- check_licenses.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_licenses.sh b/check_licenses.sh index 099ee23..b0b9d32 100755 --- a/check_licenses.sh +++ b/check_licenses.sh @@ -5,7 +5,7 @@ set -e # check if we have rg(1) if ! command -v rg >/dev/null 2>&1; then printf "%s: Missing dependency: rg(1)\n" "$0" 1>&2 - exit 71 # sysexits(3) EX_OSERR + exit 69 # sysexits(3) EX_UNAVAILABLE else rg --multiline --files-without-match --glob '*.rs' --pcre2 \ '(? Date: Sat, 12 Nov 2022 01:22:37 -0500 Subject: [PATCH 3/8] usage --- check_licenses.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/check_licenses.sh b/check_licenses.sh index b0b9d32..3dada87 100755 --- a/check_licenses.sh +++ b/check_licenses.sh @@ -2,11 +2,17 @@ set -e +# check usage +if ! test -n "$1"; then + printf "Usage: %s [path...]\n" "$0" 1>&2 + exit 64 # sysexits(3) EX_USAGE +fi + # check if we have rg(1) if ! command -v rg >/dev/null 2>&1; then printf "%s: Missing dependency: rg(1)\n" "$0" 1>&2 exit 69 # sysexits(3) EX_UNAVAILABLE else - rg --multiline --files-without-match --glob '*.rs' --pcre2 \ + rg --multiline --files-without-match --glob "$1" --pcre2 \ '(? Date: Sat, 12 Nov 2022 01:29:09 -0500 Subject: [PATCH 4/8] file, not path --- check_licenses.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_licenses.sh b/check_licenses.sh index 3dada87..a23408c 100755 --- a/check_licenses.sh +++ b/check_licenses.sh @@ -4,7 +4,7 @@ set -e # check usage if ! test -n "$1"; then - printf "Usage: %s [path...]\n" "$0" 1>&2 + printf "Usage: %s [file...]\n" "$0" 1>&2 exit 64 # sysexits(3) EX_USAGE fi From 31d8bb1fd6ce44013887bfe9c61d75127a787f68 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 12 Nov 2022 03:11:20 -0500 Subject: [PATCH 5/8] portability B) --- "\\" | 26 ++++++++++++++++++++++++++ check_licenses.sh | 12 +++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 "\\" diff --git "a/\\" "b/\\" new file mode 100644 index 0000000..5250114 --- /dev/null +++ "b/\\" @@ -0,0 +1,26 @@ +#!/bin/sh + +set -e + +# check usage +if ! test -n "$1"; then + printf "Usage: %s [file...]\n" "$0" 1>&2 + exit 64 # sysexits(3) EX_USAGE +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 \ + '\|Copyright\|p' \ + <"$file")" + then + ! test "$file" = "$1" && printf "%s\n" "$file" + fi + done +else + rg --multiline --files-without-match --glob "$1" --pcre2 \ + '(?/dev/null 2>&1; then - printf "%s: Missing dependency: rg(1)\n" "$0" 1>&2 - exit 69 # sysexits(3) EX_UNAVAILABLE + files="$(find "$PWD" -name "$1")" + for file in $files; do + if ! test -n \ + "$(sed -n '\|// SPDX-License-Identifier: .*|p' <"$file")" + then + ! test "$file" = "$1" && printf "%s\n" "$file" + fi + done else rg --multiline --files-without-match --glob "$1" --pcre2 \ '(? Date: Sat, 12 Nov 2022 03:17:40 -0500 Subject: [PATCH 6/8] pattern, not file --- "\\" | 26 -------------------------- check_licenses.sh | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 "\\" diff --git "a/\\" "b/\\" deleted file mode 100644 index 5250114..0000000 --- "a/\\" +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -set -e - -# check usage -if ! test -n "$1"; then - printf "Usage: %s [file...]\n" "$0" 1>&2 - exit 64 # sysexits(3) EX_USAGE -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 \ - '\|Copyright\|p' \ - <"$file")" - then - ! test "$file" = "$1" && printf "%s\n" "$file" - fi - done -else - rg --multiline --files-without-match --glob "$1" --pcre2 \ - '(?&2 + printf "Usage: %s [pattern...]\n" "$0" 1>&2 exit 64 # sysexits(3) EX_USAGE fi From 5670793f90b4c0637fad7587dec3a12ebf9d125d Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 16 Nov 2022 00:50:39 -0500 Subject: [PATCH 7/8] checks for license information parity between Cargo.toml and source files --- check_licenses.sh | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/check_licenses.sh b/check_licenses.sh index 7eac853..5e7caa8 100755 --- a/check_licenses.sh +++ b/check_licenses.sh @@ -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 \ - '(? Date: Wed, 16 Nov 2022 01:25:08 -0500 Subject: [PATCH 8/8] clipped absolute paths --- check_licenses.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/check_licenses.sh b/check_licenses.sh index 5e7caa8..aad8cd3 100755 --- a/check_licenses.sh +++ b/check_licenses.sh @@ -8,24 +8,31 @@ if ! command -v tomcat >/dev/null 2>&1; then 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 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 + 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" + printf "%s: Missing license information\n" "$(printf "%s\n" "$toml" |\ + sed "s/^.\+$dir\///g")" 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" "$file" + 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" "$file" + printf "%s: Missing or malformed copyright holder information\n" \ + "$(printf "%s\n" "$file" | sed "s/^.\+$dir\///g")" fi done done