tidy: Update tools/tidy.sh and add SPDX-License-Identifier

This commit is contained in:
Taiki Endo
2023-09-16 17:56:46 +09:00
parent 1c8b6e3bf4
commit b441885d30
3 changed files with 13 additions and 8 deletions

View File

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

View File

@@ -1,3 +1,5 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
use anyhow::{bail, Context as _, Result}; use anyhow::{bail, Context as _, Result};
use fs_err as fs; use fs_err as fs;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@@ -250,19 +250,22 @@ if [[ -f tools/.tidy-check-license-headers ]]; then
info "checking license headers (experimental)" info "checking license headers (experimental)"
failed_files='' failed_files=''
for p in $(eval $(<tools/.tidy-check-license-headers)); do for p in $(eval $(<tools/.tidy-check-license-headers)); do
# TODO: More file types?
case "$(basename "${p}")" in case "$(basename "${p}")" in
*.sh) prefix=("# ") ;; *.stderr | *.expanded.rs) continue ;; # generated files
*.rs | *.c | *.h | *.cpp | *.hpp | *.s | *.S) prefix=("// " "/* ") ;; *.sh | *.py | *.rb | *Dockerfile) prefix=("# ") ;;
*.rs | *.c | *.h | *.cpp | *.hpp | *.s | *.S | *.js) prefix=("// " "/* ") ;;
*.ld | *.x) prefix=("/* ") ;; *.ld | *.x) prefix=("/* ") ;;
*) error "unrecognized file type: ${p}" ;; # TODO: More file types?
*) continue ;;
esac esac
# TODO: The exact line number is not actually important; it is important # TODO: The exact line number is not actually important; it is important
# that it be part of the top-level comments of the file. # that it be part of the top-level comments of the file.
line="1" line="1"
case "${p}" in if IFS= LC_ALL=C read -rn3 -d '' shebang <"${p}" && [[ "${shebang}" == '#!/' ]]; then
*.sh) line="2" ;; # shebang line="2"
esac elif [[ "${p}" == *"Dockerfile" ]] && IFS= LC_ALL=C read -rn9 -d '' syntax <"${p}" && [[ "${syntax}" == '# syntax=' ]]; then
line="2"
fi
header_found='' header_found=''
for pre in "${prefix[@]}"; do for pre in "${prefix[@]}"; do
if [[ "$(grep -E -n "${pre}SPDX-License-Identifier: " "${p}")" == "${line}:${pre}SPDX-License-Identifier: "* ]]; then if [[ "$(grep -E -n "${pre}SPDX-License-Identifier: " "${p}")" == "${line}:${pre}SPDX-License-Identifier: "* ]]; then