[format] standardize clang-format to 19.1.7 (#11797)

Since llvm-19, if we use package manager to install it, the minor
versions could be different. This commit standardizes the version on
linux to 19.1.7. This version is the same as the one installed by
homebrew.
This commit is contained in:
Li Cao
2025-08-12 11:20:30 -07:00
committed by GitHub
parent 09214764ec
commit 318006e4da
10 changed files with 105 additions and 28 deletions
+19 -14
View File
@@ -33,6 +33,8 @@
set -euxo pipefail
INSTALL_FORMAT_TOOLS="${INSTALL_FORMAT_TOOLS:-1}"
LLVM_MAJOR_VERSION="19"
install_packages_pretty_format()
@@ -40,7 +42,8 @@ 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-"${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."
# To standardize the llvm version, we don't use apt to install
sudo bash "$(dirname "$0")/install-llvm.sh"
# 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.'
@@ -78,7 +81,7 @@ install_packages_apt()
&& sudo ln -s -f /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/* /usr/local/bin/.)
fi
if [ "$PLATFORM" != "Raspbian" ]; then
if [ "$PLATFORM" != "Raspbian" ] && [ "${INSTALL_FORMAT_TOOLS}" = "1" ]; then
install_packages_pretty_format
fi
}
@@ -112,20 +115,22 @@ install_packages_brew()
echo 'warning: please install Command Line Tools from https://developer.apple.com/download/more/'
fi
echo 'Installing pretty tools useful for code contributions...'
if [ "$INSTALL_FORMAT_TOOLS" = "1" ]; then
echo 'Installing pretty tools useful for code contributions...'
# add clang-format for pretty
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 clang-format for pretty
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.'
# add yapf for pretty
python3 -m pip install yapf || echo 'Failed to install python code formatter yapf. Install it manually if you need.'
fi
brew install include-what-you-use || echo 'WARNING: iwyu, which is useful to ensure applying the IWYU rules.'
}
+1 -1
View File
@@ -28,7 +28,7 @@
#
LLVM_MAJOR_NUMBER_VERSION="19"
LLVM_NUMBER_VERSION="19.1.0"
LLVM_NUMBER_VERSION="19.1.7"
CLANG_FORMAT_VERSION="clang-format version ${LLVM_NUMBER_VERSION}"
die()
+1 -1
View File
@@ -28,7 +28,7 @@
#
LLVM_MAJOR_NUMBER_VERSION="19"
LLVM_NUMBER_VERSION="19.1.0"
LLVM_NUMBER_VERSION="19.1.7"
CLANG_TIDY_VERSION="LLVM version ${LLVM_NUMBER_VERSION}"
CLANG_APPLY_REPLACEMENTS_VERSION="clang-apply-replacements version ${LLVM_NUMBER_VERSION}"
+71
View File
@@ -0,0 +1,71 @@
#!/bin/bash
#
# Copyright (c) 2025 The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# This script downloads and installs a specific version of clang-format and clang-tidy.
set -e
LLVM_VERSION="19.1.7"
ARCH=$(uname -m)
# This script is currently only used for linux with x86_64 architecture.
if [ "${ARCH}" != "x86_64" ]; then
echo "Unsupported architecture: ${ARCH}"
exit 1
fi
LLVM_PACKAGE="LLVM-${LLVM_VERSION}-Linux-X64"
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/${LLVM_PACKAGE}.tar.xz"
INSTALL_DIR="/opt/llvm-${LLVM_VERSION}"
TEMP_DIR=$(mktemp -d)
cleanup()
{
rm -rf "${TEMP_DIR}"
}
trap cleanup EXIT
cd "${TEMP_DIR}"
echo "Downloading LLVM from ${LLVM_URL}..."
wget -O llvm.tar.xz "${LLVM_URL}"
echo "Uncompressing to ${TEMP_DIR}..."
tar xf llvm.tar.xz
echo "Installing to ${INSTALL_DIR}..."
sudo mkdir -p /opt
sudo mv "${LLVM_PACKAGE}" "${INSTALL_DIR}"
echo "Creating symlinks in /usr/local/bin..."
sudo ln -sf "${INSTALL_DIR}/bin/clang-format" "/usr/local/bin/clang-format-19"
sudo ln -sf "${INSTALL_DIR}/bin/clang-tidy" "/usr/local/bin/clang-tidy-19"
sudo ln -sf "${INSTALL_DIR}/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements-19"
echo "Done."