[format] upgrade clang-format to 19 (#11783)

We just updated the version from 14 to 16. But very unfortunately
clang-format-16 was just deprecated recently. So this time we update
the version to the latest available one. There are newer releases than
19 (like 20) but as I tested, sudo apt-get install -y clang-format-19
can work while 20 doesn't work.

misc-include-cleaner in clang-tidy-19 exerts a very strict check which
requires to directly include all headers for every symbols in the
source file. However in our current code we intentionally use some
indirect include. So this commit disables misc-include-cleaner.
This commit is contained in:
Li Cao
2025-08-06 10:49:52 -07:00
committed by GitHub
parent 956e1a0c7d
commit 8dadae2ea1
52 changed files with 177 additions and 275 deletions
+11 -9
View File
@@ -33,12 +33,14 @@
set -euxo pipefail
LLVM_MAJOR_VERSION="19"
install_packages_pretty_format()
{
echo 'Installing pretty tools useful for code contributions...'
# add clang-format and clang-tidy for pretty
sudo apt-get --no-install-recommends install -y clang-format-16 clang-tidy-16 || echo 'WARNING: could not install clang-format-16 and clang-tidy-16, which is useful if you plan to contribute C/C++ code to the OpenThread project.'
sudo apt-get --no-install-recommends install -y clang-format-"${LLVM_MAJOR_VERSION}" clang-tidy-"${LLVM_MAJOR_VERSION}" || echo "WARNING: could not install clang-format-${LLVM_MAJOR_VERSION} and clang-tidy-${LLVM_MAJOR_VERSION}, which is useful if you plan to contribute C/C++ code to the OpenThread project."
# add yapf for pretty
python3 -m pip install yapf==0.31.0 || echo 'WARNING: could not install yapf, which is useful if you plan to contribute python code to the OpenThread project.'
@@ -113,14 +115,14 @@ install_packages_brew()
echo 'Installing pretty tools useful for code contributions...'
# add clang-format for pretty
CLANG_FORMAT_VERSION="clang-format version 16"
command -v clang-format-16 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || {
brew install llvm@16
sudo ln -s "$(brew --prefix llvm@16)/bin/clang-format" /usr/local/bin/clang-format-16
sudo ln -s "$(brew --prefix llvm@16)/bin/clang-tidy" /usr/local/bin/clang-tidy-16
sudo ln -s "$(brew --prefix llvm@16)/bin/clang-apply-replacements" /usr/local/bin/clang-apply-replacements-16
sudo ln -s "$(brew --prefix llvm@16)/bin/run-clang-tidy" /usr/local/bin/run-clang-tidy-16
} || echo 'WARNING: could not install llvm@16, which is useful if you plan to contribute C/C++ code to the OpenThread project.'
CLANG_FORMAT_VERSION="clang-format version ${LLVM_MAJOR_VERSION}"
command -v clang-format-"${LLVM_MAJOR_VERSION}" || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || {
brew install llvm@"${LLVM_MAJOR_VERSION}"
sudo ln -s "$(brew --prefix llvm@${LLVM_MAJOR_VERSION})/bin/clang-format" /usr/local/bin/clang-format-"${LLVM_MAJOR_VERSION}"
sudo ln -s "$(brew --prefix llvm@${LLVM_MAJOR_VERSION})/bin/clang-tidy" /usr/local/bin/clang-tidy-"${LLVM_MAJOR_VERSION}"
sudo ln -s "$(brew --prefix llvm@${LLVM_MAJOR_VERSION})/bin/clang-apply-replacements" /usr/local/bin/clang-apply-replacements-"${LLVM_MAJOR_VERSION}"
sudo ln -s "$(brew --prefix llvm@${LLVM_MAJOR_VERSION})/bin/run-clang-tidy" /usr/local/bin/run-clang-tidy-"${LLVM_MAJOR_VERSION}"
} || echo "WARNING: could not install llvm@${LLVM_MAJOR_VERSION}, which is useful if you plan to contribute C/C++ code to the OpenThread project."
# add yapf for pretty
python3 -m pip install yapf || echo 'Failed to install python code formatter yapf. Install it manually if you need.'
+7 -5
View File
@@ -27,7 +27,9 @@
# POSSIBILITY OF SUCH DAMAGE.
#
CLANG_FORMAT_VERSION="clang-format version 16.0"
LLVM_MAJOR_NUMBER_VERSION="19"
LLVM_NUMBER_VERSION="19.1.0"
CLANG_FORMAT_VERSION="clang-format version ${LLVM_NUMBER_VERSION}"
die()
{
@@ -39,18 +41,18 @@ die()
# expand_aliases shell option is set using shopt.
shopt -s expand_aliases
if command -v clang-format-16 >/dev/null; then
alias clang-format=clang-format-16
if command -v clang-format-"${LLVM_MAJOR_NUMBER_VERSION}" >/dev/null; then
alias clang-format=clang-format-"\${LLVM_MAJOR_NUMBER_VERSION}"
elif command -v clang-format >/dev/null; then
case "$(clang-format --version)" in
*"$CLANG_FORMAT_VERSION"*) ;;
*)
die "$(clang-format --version); clang-format 16.0 required"
die "$(clang-format --version); clang-format ${LLVM_NUMBER_VERSION} required"
;;
esac
else
die "clang-format 16.0 required"
die "clang-format ${LLVM_NUMBER_VERSION} required"
fi
clang-format "$@" || die
+18 -16
View File
@@ -27,8 +27,10 @@
# POSSIBILITY OF SUCH DAMAGE.
#
CLANG_TIDY_VERSION="LLVM version 16.0"
CLANG_APPLY_REPLACEMENTS_VERSION="clang-apply-replacements version 16.0"
LLVM_MAJOR_NUMBER_VERSION="19"
LLVM_NUMBER_VERSION="19.1.0"
CLANG_TIDY_VERSION="LLVM version ${LLVM_NUMBER_VERSION}"
CLANG_APPLY_REPLACEMENTS_VERSION="clang-apply-replacements version ${LLVM_NUMBER_VERSION}"
die()
{
@@ -36,9 +38,9 @@ die()
exit 1
}
# Search for clang-tidy-16
if command -v clang-tidy-16 >/dev/null; then
clang_tidy=$(command -v clang-tidy-16)
# Search for clang-tidy-"${LLVM_MAJOR_NUMBER_VERSION}"
if command -v clang-tidy-"${LLVM_MAJOR_NUMBER_VERSION}" >/dev/null; then
clang_tidy=$(command -v clang-tidy-"${LLVM_MAJOR_NUMBER_VERSION}")
elif command -v clang-tidy >/dev/null; then
clang_tidy=$(command -v clang-tidy)
case "$($clang_tidy --version)" in
@@ -49,12 +51,12 @@ elif command -v clang-tidy >/dev/null; then
;;
esac
else
die "clang-tidy 16.0 required"
die "clang-tidy ${LLVM_NUMBER_VERSION} required"
fi
# Search for clang-apply-replacements-16
if command -v clang-apply-replacements-16 >/dev/null; then
clang_apply_replacements=$(command -v clang-apply-replacements-16)
# Search for clang-apply-replacements-"${LLVM_MAJOR_NUMBER_VERSION}"
if command -v clang-apply-replacements-"${LLVM_MAJOR_NUMBER_VERSION}" >/dev/null; then
clang_apply_replacements=$(command -v clang-apply-replacements-"${LLVM_MAJOR_NUMBER_VERSION}")
elif command -v clang-apply-replacements >/dev/null; then
clang_apply_replacements=$(command -v clang-apply-replacements)
case "$($clang_apply_replacements --version)" in
@@ -65,20 +67,20 @@ elif command -v clang-apply-replacements >/dev/null; then
;;
esac
else
die "clang-apply-replacements 16.0 required"
die "clang-apply-replacements ${LLVM_NUMBER_VERSION} required"
fi
# Search for run-clang-tidy-16.py
if command -v run-clang-tidy-16.py >/dev/null; then
run_clang_tidy=$(command -v run-clang-tidy-16.py)
elif command -v run-clang-tidy-16 >/dev/null; then
run_clang_tidy=$(command -v run-clang-tidy-16)
# Search for run-clang-tidy-"${LLVM_MAJOR_NUMBER_VERSION}".py
if command -v run-clang-tidy-"${LLVM_MAJOR_NUMBER_VERSION}".py >/dev/null; then
run_clang_tidy=$(command -v run-clang-tidy-"${LLVM_MAJOR_NUMBER_VERSION}".py)
elif command -v run-clang-tidy-"${LLVM_MAJOR_NUMBER_VERSION}" >/dev/null; then
run_clang_tidy=$(command -v run-clang-tidy-"${LLVM_MAJOR_NUMBER_VERSION}")
elif command -v run-clang-tidy.py >/dev/null; then
run_clang_tidy=$(command -v run-clang-tidy.py)
elif command -v run-clang-tidy >/dev/null; then
run_clang_tidy=$(command -v run-clang-tidy)
else
die "run-clang-tidy.py 16.0 required"
die "run-clang-tidy.py ${LLVM_NUMBER_VERSION} required"
fi
$run_clang_tidy -clang-tidy-binary "$clang_tidy" -clang-apply-replacements-binary "$clang_apply_replacements" "$@" || die