1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

Add format.sh detection of include problems

This commit is contained in:
Jason Rhinelander 2023-10-24 14:54:20 -03:00 committed by dr7ana
parent 46ad8d4058
commit c3242e4092

View file

@ -4,12 +4,28 @@
cd "$(dirname $0)/../"
sources=($(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|m(m)?)$' | grep -v '#'))
incl_pat='^(#include +)"(llarp|libntrup|oxen|oxenc|oxenmq|quic|CLI|cpr|nlohmann|ghc|fmt|spdlog|uvw?)([/.][^"]*)"'
if [ "$1" = "verify" ] ; then
if [ $($CLANG_FORMAT --output-replacements-xml $(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|m(m)?)$' | grep -v '#') | grep '</replacement>' | wc -l) -ne 0 ] ; then
if [ $($CLANG_FORMAT --output-replacements-xml "${sources[@]}" | grep '</replacement>' | wc -l) -ne 0 ] ; then
exit 2
fi
if grep --color -E "$incl_pat" "${sources[@]}"; then
exit 5
fi
else
$CLANG_FORMAT -i $(find jni daemon llarp include pybind | grep -E '\.([hc](pp)?|m(m)?)$' | grep -v '#') &> /dev/null
$CLANG_FORMAT -i "${sources[@]}" &> /dev/null
perl -pi -e "s{$incl_pat}"'{$1<$2$3>}' "${sources[@]}" &> /dev/null
fi
# Some includes just shouldn't exist anywhere, but need to be fixed manually:
if grep --color -E '^#include ([<"]external/|<bits/|<.*/impl)' "${sources[@]}"; then
echo "Format failed: bad includes detected that can't be auto-corrected"
exit 5
fi
swift_format=$(command -v swiftformat 2>/dev/null)