Skip to content

Commit 2cf58eb

Browse files
committed
Update scripts
1 parent f100788 commit 2cf58eb

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

ci/publish.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
23
set -euo pipefail
34
IFS=$'\n\t'
45
cd "$(dirname "$0")"/..
56

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

910
# A list of paths to the crate to be published.
1011
# It will be published in the order listed.

tools/.tidy-check-license-headers

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git ls-files '*.sh' # TODO: check more files

tools/ci.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
23
set -euo pipefail
34
IFS=$'\n\t'
45

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

89
# Run a simplified version of the checks done by CI.
910
#

tools/publish.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
23
set -euo pipefail
34
IFS=$'\n\t'
45
cd "$(dirname "$0")"/..
56

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

910
# Publish a new release.
1011
#

tools/tidy.sh

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ IFS=$'\n\t'
66
cd "$(dirname "$0")"/..
77

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

1111
# USAGE:
1212
# ./tools/tidy.sh
@@ -201,6 +201,44 @@ else
201201
warn "'shellcheck' is not installed"
202202
fi
203203

204+
# License check
205+
# TODO: This check is still experimental and does not track all files that should be tracked.
206+
if [[ -f tools/.tidy-check-license-headers ]]; then
207+
info "checking license headers (experimental)"
208+
failed_files=''
209+
for p in $(eval $(<tools/.tidy-check-license-headers)); do
210+
# TODO: More file types?
211+
case "$(basename "${p}")" in
212+
*.sh) prefix=("# ") ;;
213+
*.rs | *.c | *.h | *.cpp | *.hpp | *.s | *.S) prefix=("// " "/* ") ;;
214+
*.ld | *.x) prefix=("/* ") ;;
215+
*) error "unrecognized file type: ${p}" ;;
216+
esac
217+
# TODO: The exact line number is not actually important; it is important
218+
# that it be part of the top-level comments of the file.
219+
line="1"
220+
case "${p}" in
221+
*.sh) line="2" ;; # shebang
222+
esac
223+
header_found=''
224+
for pre in "${prefix[@]}"; do
225+
if [[ "$(grep -E -n "${pre}SPDX-License-Identifier: " "${p}")" == "${line}:${pre}SPDX-License-Identifier: "* ]]; then
226+
header_found='1'
227+
continue
228+
fi
229+
done
230+
if [[ -z "${header_found}" ]]; then
231+
failed_files+="${p}:${line}"$'\n'
232+
fi
233+
done
234+
if [[ -n "${failed_files}" ]]; then
235+
error "license-check failed: please add SPDX-License-Identifier to the following files"
236+
echo "======================================="
237+
echo -n "${failed_files}"
238+
echo "======================================="
239+
fi
240+
fi
241+
204242
# Spell check (if config exists)
205243
if [[ -f .cspell.json ]]; then
206244
info "spell checking"

0 commit comments

Comments
 (0)