Skip to content

Commit

Permalink
Update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jun 5, 2023
1 parent a99f94d commit bb7f63e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions tools/.tidy-check-license-headers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git ls-files '*.sh' # TODO: check more files
3 changes: 2 additions & 1 deletion tools/ci.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -euo pipefail
IFS=$'\n\t'

# shellcheck disable=SC2154
trap 's=$?; echo >&2 "$0: Error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR
trap 's=$?; echo >&2 "$0: error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR

# Run a simplified version of the checks done by CI.
#
Expand Down
3 changes: 2 additions & 1 deletion tools/publish.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..

# shellcheck disable=SC2154
trap 's=$?; echo >&2 "$0: Error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR
trap 's=$?; echo >&2 "$0: error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR

# Publish a new release.
#
Expand Down
40 changes: 39 additions & 1 deletion tools/tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IFS=$'\n\t'
cd "$(dirname "$0")"/..

# shellcheck disable=SC2154
trap 's=$?; echo >&2 "$0: Error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR
trap 's=$?; echo >&2 "$0: error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR

# USAGE:
# ./tools/tidy.sh
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit bb7f63e

Please sign in to comment.