Skip to content
Snippets Groups Projects

work work work

Merged Florian Fischer requested to merge work-work-work into main
16 files
+ 277
141
Compare changes
  • Side-by-side
  • Inline
Files
16
+ 51
0
#!/usr/bin/env bash
set -euo pipefail
# Pretty fancy method to get reliable the absolute path of a shell
# script, *even if it is sourced*. Credits go to GreenFox on
# stackoverflow: http://stackoverflow.com/a/12197518/194894
pushd . > /dev/null
SCRIPTDIR="${BASH_SOURCE[0]}";
while([ -h "${SCRIPTDIR}" ]); do
cd "`dirname "${SCRIPTDIR}"`"
SCRIPTDIR="$(readlink "`basename "${SCRIPTDIR}"`")";
done
cd "`dirname "${SCRIPTDIR}"`" > /dev/null
SCRIPTDIR="`pwd`";
popd > /dev/null
DEBUG=false
while getopts d OPT; do
case $OPT in
d)
set -x
DEBUG=true
;;
*)
echo "usage: ${0##*/} [-dq} [--] ARGS..."
exit 2
esac
done
shift $(( OPTIND - 1 ))
OPTIND=1
ROOTDIR=$(readlink -f "${SCRIPTDIR}/..")
MAX_PROCS=$(nproc)
CHECKED_FILES_FILE=$(mktemp)
if ! $DEBUG; then
trap 'rm "${CHECKED_FILES_FILE}"' EXIT
fi
cd "${ROOTDIR}"
# Note that the --dry-run and --Werror clang-format arguments require
# clang-format 10 or higher. See https://reviews.llvm.org/D68554
find . \( -path '*/\.*' -o -path "./subprojects*" -o -path "./build*" \) -prune -o \
-type f -regextype posix-extended -regex '.*\.(c|h|cpp|hpp)' -print0 |\
tee "${CHECKED_FILES_FILE}" |\
xargs --null --max-args=3 --max-procs="${MAX_PROCS}" \
clang-format --style=file --dry-run -Werror
FILE_COUNT=$(<"${CHECKED_FILES_FILE}" tr -cd '\0' | wc -c)
echo "Checked ${FILE_COUNT} files for format violations"
Loading