toxcore/other/astyle/format-source

76 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/bin/sh
set -ex
2016-08-20 02:31:08 +08:00
SOURCE_DIR="$1"
ASTYLE="$2"
APIDSL="$3"
2016-08-20 02:31:08 +08:00
# Go to the source root.
if [ -z "$SOURCE_DIR" ]; then
SOURCE_DIR=.
fi
cd "$SOURCE_DIR"
if [ -z "$ASTYLE" ] || ! which "$ASTYLE"; then
ASTYLE=astyle
fi
if ! which "$ASTYLE"; then
# If we couldn't find or install an astyle binary, don't do anything.
echo "Could not find an astyle binary; please install astyle."
exit 1
fi
if ! which "$APIDSL"; then
if [ -f ../apidsl/apigen.native ]; then
APIDSL=../apidsl/apigen.native
else
APIDSL=apidsl_curl
fi
2016-08-20 02:31:08 +08:00
fi
apidsl_curl() {
curl -X POST --data-binary @"$1" https://apidsl.herokuapp.com/apidsl
}
# Check if apidsl generated sources are up to date.
$APIDSL toxcore/LAN_discovery.api.h > toxcore/LAN_discovery.h &
$APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h &
$APIDSL toxcore/ping.api.h > toxcore/ping.h &
$APIDSL toxcore/ping_array.api.h > toxcore/ping_array.h &
$APIDSL toxcore/tox.api.h > toxcore/tox.h &
$APIDSL toxav/toxav.api.h > toxav/toxav.h &
$APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h &
wait; wait; wait; wait; wait; wait; wait
2016-08-20 02:31:08 +08:00
if grep '<unresolved>' */*.h; then
echo "error: some apidsl references were unresolved"
exit 1
fi
CC_SOURCES=`find . '(' -name '*.cc' ')'`
CC_SOURCES="$CC_SOURCES toxcore/crypto_core.c"
CC_SOURCES="$CC_SOURCES toxcore/ping_array.c"
for bin in clang-format-6.0 clang-format-5.0 clang-format; do
if which "$bin"; then
"$bin" -i -style='{BasedOnStyle: Google, ColumnLimit: 100}' $CC_SOURCES
break
fi
done
FIND="find ."
FIND="$FIND '(' -name '*.[ch]' ')'"
FIND="$FIND -and -not -name '*.api.h'"
FIND="$FIND -and -not -wholename './super_donators/*'"
FIND="$FIND -and -not -wholename './third_party/*'"
FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'"
C_SOURCES=`eval "$FIND"`
$ASTYLE -n --options=other/astyle/astylerc $C_SOURCES
2016-08-20 02:31:08 +08:00
git diff --exit-code