mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[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:
@@ -63,7 +63,8 @@ jobs:
|
||||
- name: Bootstrap
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get --no-install-recommends install -y clang-format-19 clang-tidy-19 shellcheck iwyu
|
||||
sudo apt-get --no-install-recommends install -y shellcheck iwyu
|
||||
sudo bash script/install-llvm.sh
|
||||
python3 -m pip install yapf==0.31.0
|
||||
sudo snap install shfmt
|
||||
npm install prettier@2.0.4
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ This will open up a text editor where you can specify which commits to squash.
|
||||
|
||||
#### Coding Conventions and Style
|
||||
|
||||
OpenThread uses and enforces the [OpenThread Coding Conventions and Style](STYLE_GUIDE.md) on all code, except for code located in [third_party](third_party). Use `script/make-pretty` and `script/make-pretty check` to automatically reformat code and check for code-style compliance, respectively. OpenThread currently requires [clang-format v19](https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.0) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python.
|
||||
OpenThread uses and enforces the [OpenThread Coding Conventions and Style](STYLE_GUIDE.md) on all code, except for code located in [third_party](third_party). Use `script/make-pretty` and `script/make-pretty check` to automatically reformat code and check for code-style compliance, respectively. OpenThread currently requires [clang-format v19](https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.7) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python.
|
||||
|
||||
As part of the cleanup process, you should also run `script/make-pretty check` to ensure that your code passes the baseline code style checks.
|
||||
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@
|
||||
|
||||
- OpenThread uses `script/make-pretty` to reformat code and enforce code format and style. `script/make-pretty check` build target is included in OpenThread's continuous integration and must pass before a pull request is merged.
|
||||
|
||||
- `script/make-pretty` requires [clang-format v19](https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.0) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python.
|
||||
- `script/make-pretty` requires [clang-format v19](https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.7) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python.
|
||||
|
||||
### File Names
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ FROM ubuntu:22.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV LANG=en_US.UTF-8
|
||||
|
||||
ENV INSTALL_FORMAT_TOOLS=0
|
||||
# Resolves issue with installing libc-bin
|
||||
RUN rm /var/lib/dpkg/info/libc-bin.* \
|
||||
&& apt-get clean -y \
|
||||
|
||||
+19
-14
@@ -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
@@ -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
@@ -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}"
|
||||
|
||||
|
||||
Executable
+71
@@ -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."
|
||||
@@ -795,9 +795,11 @@ void BorderAgent::EphemeralKeyManager::UpdateCountersAndRecordEvent(Deactivation
|
||||
};
|
||||
|
||||
#if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
|
||||
#define ReasonEntry(kReason, kCounter, kEvent) \
|
||||
{ \
|
||||
kReason, HistoryTracker::Local::kEvent, &Counters::kCounter, \
|
||||
#define ReasonEntry(kReason, kCounter, kEvent) \
|
||||
{ \
|
||||
kReason, \
|
||||
HistoryTracker::Local::kEvent, \
|
||||
&Counters::kCounter, \
|
||||
}
|
||||
#else
|
||||
#define ReasonEntry(kReason, kCounter, kEvent) {kReason, 0, &Counters::kCounter}
|
||||
|
||||
@@ -1019,11 +1019,9 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
|
||||
const uint8_t kPreferredSeqNum15 = 3;
|
||||
const uint8_t kPreferredVer15 = 0;
|
||||
|
||||
#define TEST_CASE(Num) \
|
||||
{ \
|
||||
kNetworkData##Num, sizeof(kNetworkData##Num), kSeqNumbers##Num, sizeof(kSeqNumbers##Num), \
|
||||
kPreferredSeqNum##Num, kPreferredVer##Num \
|
||||
}
|
||||
#define TEST_CASE(Num) \
|
||||
{kNetworkData##Num, sizeof(kNetworkData##Num), kSeqNumbers##Num, \
|
||||
sizeof(kSeqNumbers##Num), kPreferredSeqNum##Num, kPreferredVer##Num}
|
||||
|
||||
const TestInfo kTests[] = {
|
||||
TEST_CASE(1), TEST_CASE(2), TEST_CASE(3), TEST_CASE(4), TEST_CASE(5),
|
||||
|
||||
Reference in New Issue
Block a user