1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-01 03:47:23 +03:00

Migrate from astyle to clang-format (#8464)

This commit is contained in:
Maxim Prokhorov
2022-02-20 19:23:33 +03:00
committed by Max Prokhorov
parent 46190b61f1
commit 19b7a29720
241 changed files with 15925 additions and 16197 deletions

View File

@ -1,50 +1,64 @@
#!/bin/sh
# requires clang-format, git, python3 with pyyaml
set -e
set -e -x
org=$(cd ${0%/*}; pwd)
cd ${org}/..
pwd
test -d cores/esp8266
test -d libraries
root=$(git rev-parse --show-toplevel)
test -d ${root}/cores/esp8266
test -d ${root}/libraries
# should be: all="cores/esp8266 libraries"
# allow `env CLANG_FORMAT=clang-format-13`, or some other version
# default to v13, latest stable version from https://apt.llvm.org
CLANG_FORMAT=${CLANG_FORMAT:-clang-format-13}
all="
# TODO: waiting for llvm-14 to allow --style=file:<path-to-file>
makeClangFormatStyle() {
python3 -c 'import sys,yaml; sys.stdout.write(yaml.dump(yaml.safe_load(open(sys.argv[1], "r")), default_flow_style=True)); sys.stdout.flush();' $1
}
#########################################
# 'all' variable should be "cores/esp8266 libraries"
all=${1:-"
cores/esp8266/Lwip*
libraries/ESP8266mDNS
libraries/Wire
libraries/lwIP*
cores/esp8266/Lwip*
cores/esp8266/debug*
cores/esp8266/core_esp8266_si2c.cpp
cores/esp8266/StreamString.*
cores/esp8266/StreamSend.*
libraries/Netdump
"
tests
"}
# core
#########################################
# restyling core & libraries
for d in $all; do
if [ -d "$d" ]; then
echo "-------- directory $d:"
for e in c cpp h; do
find $d -name "*.$e" -exec \
astyle \
--suffix=none \
--options=${org}/astyle_core.conf {} \;
done
cd $root
style=$(makeClangFormatStyle ${root}/tests/clang-format-core.yaml)
for target in $all; do
if [ -d "$target" ]; then
find $target \
'(' -name "*.cpp" -o -name "*.c" -o -name "*.h" ')' \
-exec $CLANG_FORMAT --verbose --style="$style" -i {} \;
else
echo "-------- file $d:"
astyle --suffix=none --options=${org}/astyle_core.conf "$d"
$CLANG_FORMAT --verbose --style="$style" -i $target
fi
done
# examples
#########################################
# restyling arduino examples
for d in libraries; do
echo "-------- examples in $d:"
find $d -name "*.ino" -exec \
astyle \
--suffix=none \
--options=${org}/astyle_examples.conf {} \;
done
# TODO should not be matched, these are formatted externally
# exclude=$(git submodule --quiet foreach git rev-parse --show-toplevel | grep libraries)
style=$(makeClangFormatStyle ${root}/tests/clang-format-arduino.yaml)
find libraries \
-path libraries/ESP8266SdFat -prune -o \
-path libraries/Ethernet -prune -o \
-path libraries/SoftwareSerial -prune -o \
-name '*.ino' -exec $CLANG_FORMAT --verbose --style="$style" -i {} \;
#########################################