2020-06-12 20:32:13 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-06-18 15:44:13 +02:00
|
|
|
|
2021-03-10 01:16:36 +01:00
|
|
|
CLANG_FORMAT_DESIRED_VERSION=11
|
|
|
|
|
2021-10-15 02:02:23 +02:00
|
|
|
binary=$(command -v clang-format-$CLANG_FORMAT_DESIRED_VERSION 2>/dev/null)
|
2021-08-26 01:54:08 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
2021-10-15 02:02:23 +02:00
|
|
|
binary=$(command -v clang-format-mp-$CLANG_FORMAT_DESIRED_VERSION 2>/dev/null)
|
2021-08-26 01:54:08 +02:00
|
|
|
fi
|
2021-03-10 01:16:36 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
2021-10-15 02:02:23 +02:00
|
|
|
binary=$(command -v clang-format 2>/dev/null)
|
2021-03-10 01:16:36 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Please install clang-format version $CLANG_FORMAT_DESIRED_VERSION and re-run this script."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
version=$(clang-format --version)
|
|
|
|
if [[ ! $version == *"clang-format version $CLANG_FORMAT_DESIRED_VERSION"* ]]; then
|
|
|
|
echo "Please install clang-format version $CLANG_FORMAT_DESIRED_VERSION and re-run this script."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-05-12 13:36:00 +02:00
|
|
|
cd "$(dirname $0)/../"
|
|
|
|
if [ "$1" = "verify" ] ; then
|
2022-09-19 17:22:28 +02:00
|
|
|
if [ $($binary --output-replacements-xml $(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|m(m)?)$' | grep -v '#') | grep '</replacement>' | wc -l) -ne 0 ] ; then
|
2021-10-15 02:02:23 +02:00
|
|
|
exit 2
|
2021-05-14 19:07:44 +02:00
|
|
|
fi
|
2021-05-12 13:36:00 +02:00
|
|
|
else
|
2022-09-19 17:22:28 +02:00
|
|
|
$binary -i $(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|m(m)?)$' | grep -v '#') &> /dev/null
|
2021-05-12 13:36:00 +02:00
|
|
|
fi
|
2021-05-14 19:07:44 +02:00
|
|
|
|
2021-10-15 02:02:23 +02:00
|
|
|
swift_format=$(command -v swiftformat 2>/dev/null)
|
2021-05-14 19:07:44 +02:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
if [ "$1" = "verify" ] ; then
|
2022-09-19 17:22:28 +02:00
|
|
|
for f in $(find daemon | grep -E '\.swift$' | grep -v '#') ; do
|
2021-05-14 19:07:44 +02:00
|
|
|
if [ $($swift_format --quiet --dryrun < "$f" | diff "$f" - | wc -l) -ne 0 ] ; then
|
2021-10-15 02:02:23 +02:00
|
|
|
exit 3
|
2021-05-14 19:07:44 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
2022-09-19 17:22:28 +02:00
|
|
|
$swift_format --quiet $(find daemon | grep -E '\.swift$' | grep -v '#')
|
2021-05-14 19:07:44 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2021-10-15 02:01:33 +02:00
|
|
|
|
|
|
|
jsonnet_format=$(command -v jsonnetfmt 2>/dev/null)
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
if [ "$1" = "verify" ]; then
|
|
|
|
if ! $jsonnet_format --test .drone.jsonnet; then
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
$jsonnet_format --in-place .drone.jsonnet
|
|
|
|
fi
|
|
|
|
fi
|