2020-03-23 08:46:02 +08:00
|
|
|
#!/bin/bash
|
2016-08-20 06:36:49 +08:00
|
|
|
|
2018-02-21 22:15:57 +08:00
|
|
|
set -ex
|
2016-08-20 02:31:08 +08:00
|
|
|
|
|
|
|
SOURCE_DIR="$1"
|
2018-02-19 08:09:49 +08:00
|
|
|
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"
|
|
|
|
|
2016-09-07 18:09:00 +08:00
|
|
|
if [ -z "$ASTYLE" ] || ! which "$ASTYLE"; then
|
2016-08-20 06:36:49 +08:00
|
|
|
ASTYLE=astyle
|
|
|
|
fi
|
|
|
|
|
2016-09-07 18:09:00 +08:00
|
|
|
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
|
|
|
|
|
2016-09-21 17:51:58 +08:00
|
|
|
if ! which "$APIDSL"; then
|
|
|
|
if [ -f ../apidsl/apigen.native ]; then
|
|
|
|
APIDSL=../apidsl/apigen.native
|
|
|
|
else
|
|
|
|
APIDSL=apidsl_curl
|
2016-10-24 23:06:09 +08:00
|
|
|
fi
|
2016-08-20 02:31:08 +08:00
|
|
|
fi
|
|
|
|
|
2020-03-23 08:46:02 +08:00
|
|
|
TO_JSON='s/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g;s/^(.*)$/"$1"/'
|
|
|
|
FROM_JSON='s/\\"/"/g;s/^"(.*)"$/$1/;s/\\\\/\\/g;s/\\n/\n/g'
|
|
|
|
|
|
|
|
apidsl_request() {
|
|
|
|
TMPFILE=$(mktemp /tmp/apidsl.XXXXXX)
|
2020-04-08 23:06:40 +08:00
|
|
|
curl -s -o "$TMPFILE" -X POST --data @<(
|
2020-03-23 08:46:02 +08:00
|
|
|
echo '["Request",';
|
|
|
|
cat $2;
|
2020-04-08 23:06:40 +08:00
|
|
|
echo ']') https://apidsl.herokuapp.com/$1
|
2020-03-23 08:46:02 +08:00
|
|
|
if grep '\[1,"' "$TMPFILE" > /dev/null; then
|
|
|
|
echo "Error: $(grep -o '".*"' /tmp/apidsl-$$ | perl -0777 -pe "$FROM_JSON")" >&2
|
|
|
|
rm "$TMPFILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
perl -0777 -pe 's/^\[0,(.*)\]$/$1/' "$TMPFILE"
|
|
|
|
rm "$TMPFILE"
|
|
|
|
}
|
|
|
|
|
2016-08-20 02:31:08 +08:00
|
|
|
apidsl_curl() {
|
2020-05-03 08:09:06 +08:00
|
|
|
echo "apidsl_curl $*" >&2
|
2020-03-23 08:46:02 +08:00
|
|
|
apidsl_request "c" <(
|
|
|
|
apidsl_request "parse" <(
|
|
|
|
perl -0777 -pe "$TO_JSON" $1)) | perl -0777 -pe "$FROM_JSON"
|
2016-08-20 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2016-11-06 23:05:52 +08:00
|
|
|
# Check if apidsl generated sources are up to date.
|
2020-04-08 23:06:40 +08:00
|
|
|
set +x
|
2018-09-26 05:20:31 +08:00
|
|
|
$APIDSL toxcore/LAN_discovery.api.h > toxcore/LAN_discovery.h &
|
2018-02-20 01:03:05 +08:00
|
|
|
$APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h &
|
2018-08-02 07:02:13 +08:00
|
|
|
$APIDSL toxcore/ping.api.h > toxcore/ping.h &
|
|
|
|
$APIDSL toxcore/ping_array.api.h > toxcore/ping_array.h &
|
2018-02-20 01:03:05 +08:00
|
|
|
$APIDSL toxcore/tox.api.h > toxcore/tox.h &
|
|
|
|
$APIDSL toxav/toxav.api.h > toxav/toxav.h &
|
|
|
|
$APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h &
|
2020-04-08 23:06:40 +08:00
|
|
|
set -x
|
2018-02-20 01:03:05 +08:00
|
|
|
|
2018-09-26 05:20:31 +08:00
|
|
|
wait; wait; wait; wait; wait; wait; wait
|
2016-08-20 02:31:08 +08:00
|
|
|
|
2020-05-03 08:09:06 +08:00
|
|
|
if grep '<unresolved>' ./*/*.h; then
|
2016-12-14 17:17:19 +08:00
|
|
|
echo "error: some apidsl references were unresolved"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-05-03 08:09:06 +08:00
|
|
|
CC_SOURCES=$(find . '(' -name '*.cc' ')')
|
2018-08-27 01:58:27 +08:00
|
|
|
CC_SOURCES="$CC_SOURCES toxcore/crypto_core.c"
|
2018-08-26 17:42:08 +08:00
|
|
|
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
|
|
|
|
|
2018-02-21 22:15:57 +08:00
|
|
|
FIND="find ."
|
2018-08-26 17:42:08 +08:00
|
|
|
FIND="$FIND '(' -name '*.[ch]' ')'"
|
2018-02-21 22:15:57 +08:00
|
|
|
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*'"
|
|
|
|
|
2020-05-03 08:09:06 +08:00
|
|
|
C_SOURCES=$(eval "$FIND")
|
2016-08-20 06:36:49 +08:00
|
|
|
|
2018-08-26 17:42:08 +08:00
|
|
|
$ASTYLE -n --options=other/astyle/astylerc $C_SOURCES
|
2016-08-20 02:31:08 +08:00
|
|
|
|
|
|
|
git diff --exit-code
|