Update scripts

This commit is contained in:
Taiki Endo
2023-06-05 22:58:32 +09:00
parent c5540270ed
commit 2ef37fafbe
6 changed files with 43 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -euo pipefail
IFS=$'\n\t'

View File

@@ -0,0 +1 @@
git ls-files '*.sh' # TODO: check more files

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..

View File

@@ -201,6 +201,44 @@ else
warn "'shellcheck' is not installed"
fi
# License check
# TODO: This check is still experimental and does not track all files that should be tracked.
if [[ -f tools/.tidy-check-license-headers ]]; then
info "checking license headers (experimental)"
failed_files=''
for p in $(eval $(<tools/.tidy-check-license-headers)); do
# TODO: More file types?
case "$(basename "${p}")" in
*.sh) prefix=("# ") ;;
*.rs | *.c | *.h | *.cpp | *.hpp | *.s | *.S) prefix=("// " "/* ") ;;
*.ld | *.x) prefix=("/* ") ;;
*) error "unrecognized file type: ${p}" ;;
esac
# TODO: The exact line number is not actually important; it is important
# that it be part of the top-level comments of the file.
line="1"
case "${p}" in
*.sh) line="2" ;; # shebang
esac
header_found=''
for pre in "${prefix[@]}"; do
if [[ "$(grep -E -n "${pre}SPDX-License-Identifier: " "${p}")" == "${line}:${pre}SPDX-License-Identifier: "* ]]; then
header_found='1'
continue
fi
done
if [[ -z "${header_found}" ]]; then
failed_files+="${p}:${line}"$'\n'
fi
done
if [[ -n "${failed_files}" ]]; then
error "license-check failed: please add SPDX-License-Identifier to the following files"
echo "======================================="
echo -n "${failed_files}"
echo "======================================="
fi
fi
# Spell check (if config exists)
if [[ -f .cspell.json ]]; then
info "spell checking"