Debian Codegraph @

tools/check-license

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 set -euo pipefail
3
4 # Pretty fancy method to get reliable the absolute path of a shell
5 # script, *even if it is sourced*. Credits go to GreenFox on
6 # stackoverflow: http://stackoverflow.com/a/12197518/194894
7 pushd . > /dev/nullscip-shell filesystem . . `/dev/null`.
8 SCRIPTDIR="${BASH_SOURCE[0]}";
9 while([scip-shell system . . `[`. -h "${SCRIPTDIR}" ]); do
10 cd "`dirnamescip-shell system . . dirname. "${SCRIPTDIR}"`"
11 SCRIPTDIR="$(readlinkscip-shell system . . readlink. "`basenamescip-shell system . . basename. "${SCRIPTDIR}"`")";
12 done
13 cd "`dirnamescip-shell system . . dirname. "${SCRIPTDIR}"`" > /dev/nullscip-shell filesystem . . `/dev/null`.
14 SCRIPTDIR="`pwdscip-shell system . . pwd.`";
15 popd > /dev/nullscip-shell filesystem . . `/dev/null`.
16
17 while getopts :d OPT; do
18 case $OPT in
19 d)
20 set -x
21 ;;
22 *)
23 echoscip-shell system . . echo. "usage: ${0##*/} [-d]"
24 exit 2
25 esac
26 done
27 shift $(( OPTIND - 1 ))
28 OPTIND=1
29
30 export ROOTDIR
31 ROOTDIR=$(readlinkscip-shell system . . readlink. -f "${SCRIPTDIR}/..")
32
33 export CHECKED_FILES_FILE
34 CHECKED_FILES_FILE=$(mktempscip-shell system . . mktemp.)
35 trap 'rm "${CHECKED_FILES_FILE}"' EXIT
36
37 # Safely call bash function from xargs
38 # https://stackoverflow.com/questions/11003418/calling-shell-functions-with-xargs/11003457#11003457
39 check_licensescip-shell shell shell-project 0.0.0 check_license().() {
40 local license_identifier="# SPDX-License-Identifier: GPL-3.0-or-later"
41 local sed_cmd="{N; /^${license_identifier}\n/!{q1}}"
42
43 local full_path="${ROOTDIR}/${1}"
44 if ! headscip-shell system . . head. --lines=3 "${full_path}" |\
45 sed --regexp-extended --quiet "${sed_cmd}" >/dev/nullscip-shell filesystem . . `/dev/null`.
46 then
47 echoscip-shell system . . echo. "$1": missing or invalid license header
48 return 1
49 fi
50
51 echoscip-shell system . . echo. -e "${1}\0" >> "${CHECKED_FILES_FILE}"
52 }
53 export -f check_license
54
55
56 MAX_PROCS=$(nprocscip-shell system . . nproc.)
57
58 cd "${ROOTDIR}"
59 findscip-shell system . . find. . \( -path '*/\.*' -o -path "./build*" -o -path "./bin/*" \) -prune -o \
60 -type f -regextype posix-extended -regex '.*\.(py)' -print0 |\
61 xargs --null --max-args=1 --max-procs="${MAX_PROCS}" -I {} \
62 bash -c 'check_license "$@"' _ "{}"
63
64 FILE_COUNT=$(<"${CHECKED_FILES_FILE}" trscip-shell system . . tr. -cd '\0' | wcscip-shell system . . wc. -c)
65 echoscip-shell system . . echo. "Checked ${FILE_COUNT} files for license headers"
66