summaryrefslogtreecommitdiffstats
path: root/extras/scripts
diff options
context:
space:
mode:
authorRay Kinsella <mdr@ashroe.eu>2021-03-12 15:57:29 +0000
committerDamjan Marion <dmarion@me.com>2021-03-16 21:36:28 +0000
commit718359881ddae4569de0d029faa60fea05920922 (patch)
treecf8ffbfeff7047499bad0f9007a23d83b079d246 /extras/scripts
parent04208c6cfb4ec1ce5c30775736c51ce4899f7c23 (diff)
misc: fix checkstyle on fedora
The fedora clang-format command helpfully does not include the version suffix, and places clang-format-diff in /usr/share/clang. Have summited #1939018 in Fedora, to fix upstream. https://bugzilla.redhat.com/show_bug.cgi?id=1939018 Until then ... Type: fix Signed-off-by: Ray Kinsella <mdr@ashroe.eu> Change-Id: Ibceae0fc15e7461c24288ee04f4d28943f889c36
Diffstat (limited to 'extras/scripts')
-rwxr-xr-xextras/scripts/checkstyle.sh54
1 files changed, 51 insertions, 3 deletions
diff --git a/extras/scripts/checkstyle.sh b/extras/scripts/checkstyle.sh
index ab0e6e46331..d7587cb369b 100755
--- a/extras/scripts/checkstyle.sh
+++ b/extras/scripts/checkstyle.sh
@@ -15,12 +15,60 @@
set -eEo pipefail
+CLANG_FORMAT_VER_REGEX='([0-9]+)\.[0-9]+\.[0-9]+'
+CLANG_FORMAT_DIFF="/usr/share/clang/clang-format-diff.py"
+
CLANG_FORMAT_VER=10
GIT_DIFF_ARGS="-U0 --no-color --relative HEAD~1"
CLANG_FORMAT_DIFF_ARGS="-style file -p1"
SUFFIX="-${CLANG_FORMAT_VER}"
-clang-format${SUFFIX} --version
+# Attempt to find clang-format to confirm Clang version.
+if command -v clang-format${SUFFIX} &> /dev/null;
+then
+ CLANG_FORMAT=clang-format${SUFFIX}
+elif command -v clang-format &> /dev/null;
+then
+ CLANG_FORMAT=clang-format
+fi
+
+CLANG_FORMAT_VERSION=$(${CLANG_FORMAT} --version)
+echo $CLANG_FORMAT_VERSION
+
+# Confirm that Clang is the expected version.
+if [[ ! $CLANG_FORMAT_VERSION =~ $CLANG_FORMAT_VER_REGEX ]];
+then
+ echo "*******************************************************************"
+ echo "* CHECKSTYLE VERSION REGEX CHECK FAILED"
+ echo "* $CLANG_FORMAT_VERSION"
+ echo "*******************************************************************"
+ exit 1
+fi
+
+if [[ ! $CLANG_FORMAT_VER == "${BASH_REMATCH[1]}" ]];
+then
+ echo "*******************************************************************"
+ echo "* CHECKSTYLE VERSION CHECK FAILED"
+ echo "* Expected major version $CLANG_FORMAT_VER, found ${BASH_REMATCH[1]}"
+ echo "*******************************************************************"
+ exit 1
+fi
+
+# Attempt to find clang-format-diff.
+if command -v clang-format-diff${SUFFIX} &> /dev/null;
+then
+ CLANG_FORMAT_DIFF=clang-format-diff${SUFFIX}
+elif command -v clang-format-diff &> /dev/null;
+then
+ CLANG_FORMAT=clang-format-diff
+elif [ ! -f $CLANG_FORMAT_DIFF ] ;
+then
+ echo "*******************************************************************"
+ echo "* CHECKSTYLE FAILED"
+ echo "* Could not locate the clang-format-diff script"
+ echo "*******************************************************************"
+ exit 1
+fi
in=$(mktemp)
git diff ${GIT_DIFF_ARGS} ':!*.patch' > ${in}
@@ -39,7 +87,7 @@ if [ ${line_count} -gt 0 ] ; then
fi
if [ "${1}" == "--fix" ]; then
- cat ${in} | clang-format-diff${SUFFIX} ${CLANG_FORMAT_DIFF_ARGS} -i
+ cat ${in} | ${CLANG_FORMAT_DIFF} ${CLANG_FORMAT_DIFF_ARGS} -i
filelist=$(sed -n 's/^+++ b\/\(.*\.[ch]\)/\1/p' ${in})
git status ${filelist}
rm ${in}
@@ -61,7 +109,7 @@ fi
out=$(mktemp)
-cat ${in} | clang-format-diff${SUFFIX} ${CLANG_FORMAT_DIFF_ARGS} > ${out}
+cat ${in} | ${CLANG_FORMAT_DIFF} ${CLANG_FORMAT_DIFF_ARGS} > ${out}
rm ${in}
line_count=$(cat ${out} | wc -l)