From 58b0486bcde2422c88c786e41de8912e94006b1d Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 7 Oct 2020 21:17:44 -0700 Subject: [PATCH] [clang-format] update to clang-format-10 (#5616) --- .clang-format | 3 +- .github/workflows/build.yml | 4 +- CONTRIBUTING.md | 2 +- STYLE_GUIDE.md | 2 +- examples/platforms/k32w/src/system.c | 2 +- script/bootstrap | 10 ++--- script/clang-format | 10 ++--- src/core/backbone_router/ndproxy_table.hpp | 2 +- src/core/common/settings.hpp | 2 +- src/core/thread/topology.hpp | 2 +- src/lib/spinel/radio_spinel_impl.hpp | 48 +++++++++++----------- tests/unit/test_spinel_decoder.cpp | 4 +- 12 files changed, 45 insertions(+), 46 deletions(-) diff --git a/.clang-format b/.clang-format index b5b25e775..dce55a85e 100644 --- a/.clang-format +++ b/.clang-format @@ -20,7 +20,8 @@ AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: false BinPackArguments: true BinPackParameters: false -BraceWrapping: +BraceWrapping: + AfterCaseLabel: true AfterClass: true AfterControlStatement: true AfterEnum: true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 167d5e792..f29773c3d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,9 +47,7 @@ jobs: - name: Bootstrap run: | sudo rm /etc/apt/sources.list.d/* && sudo apt-get update - sudo apt-get remove -y clang-6.0 libclang-common-6.0-dev libclang1-6.0 libllvm6.0 - sudo apt-get autoremove - sudo apt-get --no-install-recommends install -y clang-tools clang-format-6.0 shellcheck + sudo apt-get --no-install-recommends install -y clang-format-10 shellcheck python3 -m pip install yapf==0.29.0 sudo snap install shfmt - name: Check diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f37faf3af..5fca49804 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 v6.0.0](http://releases.llvm.org/download.html#6.0.0) for C/C++ and [yapf v0.29.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 v10.0.0](http://releases.llvm.org/download.html#10.0.0) for C/C++ and [yapf v0.29.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. diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md index b3c96ee09..74e9c698c 100644 --- a/STYLE_GUIDE.md +++ b/STYLE_GUIDE.md @@ -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 v6.0.0](http://releases.llvm.org/download.html#6.0.0) for C/C++ and [yapf v0.29.0](https://github.com/google/yapf) for Python. +- `script/make-pretty` requires [clang-format v10.0.0](http://releases.llvm.org/download.html#10.0.0) for C/C++ and [yapf v0.29.0](https://github.com/google/yapf) for Python. ### File Names diff --git a/examples/platforms/k32w/src/system.c b/examples/platforms/k32w/src/system.c index abf83de62..979014e00 100644 --- a/examples/platforms/k32w/src/system.c +++ b/examples/platforms/k32w/src/system.c @@ -41,7 +41,7 @@ #include "MemManager.h" -otInstance * sInstance; +otInstance * sInstance; OT_TOOL_WEAK uint32_t gInterruptDisableCount = 0; void otSysInit(int argc, char *argv[]) diff --git a/script/bootstrap b/script/bootstrap index 3e11b5be5..59de91cfc 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -59,7 +59,7 @@ install_packages_apt() echo 'Installing pretty tools useful for code contributions...' # add clang-format for pretty - sudo apt-get --no-install-recommends install -y clang-format-6.0 + sudo apt-get --no-install-recommends install -y clang-format-10 # add yapf for pretty python3 -m pip install yapf==0.29.0 || echo 'WARNING: could not install yapf, which is useful if you plan to contribute python code to the OpenThread project.' @@ -103,10 +103,10 @@ install_packages_brew() echo 'Installing pretty tools useful for code contributions...' # add clang-format for pretty - CLANG_FORMAT_VERSION="clang-format version 6.0" - command -v clang-format-6.0 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || { - brew install llvm@6 - sudo ln -s "$(brew --prefix llvm@6)/bin/clang-format" /usr/local/bin/clang-format-6.0 + CLANG_FORMAT_VERSION="clang-format version 10" + command -v clang-format-10 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || { + brew install llvm@10 + sudo ln -s "$(brew --prefix llvm@6)/bin/clang-format" /usr/local/bin/clang-format-10 } # add yapf for pretty diff --git a/script/clang-format b/script/clang-format index 2624ece51..addb7fa47 100755 --- a/script/clang-format +++ b/script/clang-format @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. # -CLANG_FORMAT_VERSION="clang-format version 6.0" +CLANG_FORMAT_VERSION="clang-format version 10.0" die() { @@ -39,18 +39,18 @@ die() # expand_aliases shell option is set using shopt. shopt -s expand_aliases -if command -v clang-format-6.0 >/dev/null; then - alias clang-format=clang-format-6.0 +if command -v clang-format-10 >/dev/null; then + alias clang-format=clang-format-10 elif command -v clang-format >/dev/null; then case "$(clang-format --version)" in "$CLANG_FORMAT_VERSION"*) ;; *) - die "$(clang-format --version); clang-format 6.0 required" + die "$(clang-format --version); clang-format 10.0 required" ;; esac else - die "clang-format 6.0 required" + die "clang-format 10.0 required" fi clang-format "$@" || die diff --git a/src/core/backbone_router/ndproxy_table.hpp b/src/core/backbone_router/ndproxy_table.hpp index 6872661fa..4e72d87cc 100644 --- a/src/core/backbone_router/ndproxy_table.hpp +++ b/src/core/backbone_router/ndproxy_table.hpp @@ -159,7 +159,7 @@ private: void Advance(void); void operator++(void) { Advance(); } void operator++(int) { Advance(); } - const NdProxy &operator*(void)const { return *mCurrent; } + const NdProxy &operator*(void) const { return *mCurrent; } bool operator==(const Iterator &aOther) const { return mCurrent == aOther.mCurrent; } bool operator!=(const Iterator &aOther) const { return !(*this == aOther); } NdProxy * operator->(void) { return mCurrent; } diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index c96ab9e8b..d08d5a55a 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -916,7 +916,7 @@ public: * @returns A reference to the `ChildInfo` entry currently pointed by the iterator. * */ - const ChildInfo &operator*(void)const { return mChildInfo; } + const ChildInfo &operator*(void) const { return mChildInfo; } /** * This method overloads operator `==` to evaluate whether or not two iterator instances are equal. diff --git a/src/core/thread/topology.hpp b/src/core/thread/topology.hpp index 06f30eafa..573ef7567 100644 --- a/src/core/thread/topology.hpp +++ b/src/core/thread/topology.hpp @@ -743,7 +743,7 @@ public: * @returns A reference to the `Ip6::Address` entry currently pointed by the iterator. * */ - const Ip6::Address &operator*(void)const { return *GetAddress(); } + const Ip6::Address &operator*(void) const { return *GetAddress(); } /** * This method overloads operator `==` to evaluate whether or not two `Iterator` instances are equal. diff --git a/src/lib/spinel/radio_spinel_impl.hpp b/src/lib/spinel/radio_spinel_impl.hpp index 8bd741b6f..ddaa2ebb4 100644 --- a/src/lib/spinel/radio_spinel_impl.hpp +++ b/src/lib/spinel/radio_spinel_impl.hpp @@ -864,12 +864,12 @@ otError RadioSpinel::ParseRadioFrame(otRadioF unpacked = spinel_datatype_unpack_in_place(aBuffer, aLength, SPINEL_DATATYPE_DATA_WLEN_S // Frame - SPINEL_DATATYPE_INT8_S // RSSI - SPINEL_DATATYPE_INT8_S // Noise Floor - SPINEL_DATATYPE_UINT16_S // Flags + SPINEL_DATATYPE_INT8_S // RSSI + SPINEL_DATATYPE_INT8_S // Noise Floor + SPINEL_DATATYPE_UINT16_S // Flags SPINEL_DATATYPE_STRUCT_S( // PHY-data SPINEL_DATATYPE_UINT8_S // 802.15.4 channel - SPINEL_DATATYPE_UINT8_S // 802.15.4 LQI + SPINEL_DATATYPE_UINT8_S // 802.15.4 LQI SPINEL_DATATYPE_UINT64_S // Timestamp (us). ) SPINEL_DATATYPE_STRUCT_S( // Vendor-data SPINEL_DATATYPE_UINT_PACKED_S // Receive error @@ -1203,22 +1203,22 @@ otError RadioSpinel::GetCoexMetrics(otRadioCo error = Get(SPINEL_PROP_RADIO_COEX_METRICS, SPINEL_DATATYPE_STRUCT_S( // Tx Coex Metrics Structure SPINEL_DATATYPE_UINT32_S // NumTxRequest - SPINEL_DATATYPE_UINT32_S // NumTxGrantImmediate - SPINEL_DATATYPE_UINT32_S // NumTxGrantWait - SPINEL_DATATYPE_UINT32_S // NumTxGrantWaitActivated - SPINEL_DATATYPE_UINT32_S // NumTxGrantWaitTimeout - SPINEL_DATATYPE_UINT32_S // NumTxGrantDeactivatedDuringRequest - SPINEL_DATATYPE_UINT32_S // NumTxDelayedGrant + SPINEL_DATATYPE_UINT32_S // NumTxGrantImmediate + SPINEL_DATATYPE_UINT32_S // NumTxGrantWait + SPINEL_DATATYPE_UINT32_S // NumTxGrantWaitActivated + SPINEL_DATATYPE_UINT32_S // NumTxGrantWaitTimeout + SPINEL_DATATYPE_UINT32_S // NumTxGrantDeactivatedDuringRequest + SPINEL_DATATYPE_UINT32_S // NumTxDelayedGrant SPINEL_DATATYPE_UINT32_S // AvgTxRequestToGrantTime ) SPINEL_DATATYPE_STRUCT_S( // Rx Coex Metrics Structure SPINEL_DATATYPE_UINT32_S // NumRxRequest - SPINEL_DATATYPE_UINT32_S // NumRxGrantImmediate - SPINEL_DATATYPE_UINT32_S // NumRxGrantWait - SPINEL_DATATYPE_UINT32_S // NumRxGrantWaitActivated - SPINEL_DATATYPE_UINT32_S // NumRxGrantWaitTimeout - SPINEL_DATATYPE_UINT32_S // NumRxGrantDeactivatedDuringRequest - SPINEL_DATATYPE_UINT32_S // NumRxDelayedGrant - SPINEL_DATATYPE_UINT32_S // AvgRxRequestToGrantTime + SPINEL_DATATYPE_UINT32_S // NumRxGrantImmediate + SPINEL_DATATYPE_UINT32_S // NumRxGrantWait + SPINEL_DATATYPE_UINT32_S // NumRxGrantWaitActivated + SPINEL_DATATYPE_UINT32_S // NumRxGrantWaitTimeout + SPINEL_DATATYPE_UINT32_S // NumRxGrantDeactivatedDuringRequest + SPINEL_DATATYPE_UINT32_S // NumRxDelayedGrant + SPINEL_DATATYPE_UINT32_S // AvgRxRequestToGrantTime SPINEL_DATATYPE_UINT32_S // NumRxGrantNone ) SPINEL_DATATYPE_BOOL_S // Stopped SPINEL_DATATYPE_UINT32_S, // NumGrantGlitch @@ -1563,13 +1563,13 @@ otError RadioSpinel::Transmit(otRadioFrame &a error = Request(true, SPINEL_CMD_PROP_VALUE_SET, SPINEL_PROP_STREAM_RAW, SPINEL_DATATYPE_DATA_WLEN_S // Frame data - SPINEL_DATATYPE_UINT8_S // Channel - SPINEL_DATATYPE_UINT8_S // MaxCsmaBackoffs - SPINEL_DATATYPE_UINT8_S // MaxFrameRetries - SPINEL_DATATYPE_BOOL_S // CsmaCaEnabled - SPINEL_DATATYPE_BOOL_S // IsARetx - SPINEL_DATATYPE_BOOL_S // SkipAes - SPINEL_DATATYPE_UINT16_S // Period + SPINEL_DATATYPE_UINT8_S // Channel + SPINEL_DATATYPE_UINT8_S // MaxCsmaBackoffs + SPINEL_DATATYPE_UINT8_S // MaxFrameRetries + SPINEL_DATATYPE_BOOL_S // CsmaCaEnabled + SPINEL_DATATYPE_BOOL_S // IsARetx + SPINEL_DATATYPE_BOOL_S // SkipAes + SPINEL_DATATYPE_UINT16_S // Period SPINEL_DATATYPE_UINT16_S, // Phase mTransmitFrame->mPsdu, mTransmitFrame->mLength, mTransmitFrame->mChannel, mTransmitFrame->mInfo.mTxInfo.mMaxCsmaBackoffs, mTransmitFrame->mInfo.mTxInfo.mMaxFrameRetries, diff --git a/tests/unit/test_spinel_decoder.cpp b/tests/unit/test_spinel_decoder.cpp index 96f340afc..968c9f102 100644 --- a/tests/unit/test_spinel_decoder.cpp +++ b/tests/unit/test_spinel_decoder.cpp @@ -112,7 +112,7 @@ void TestDecoder(void) SPINEL_DATATYPE_UINT_PACKED_S SPINEL_DATATYPE_UINT_PACKED_S SPINEL_DATATYPE_UINT_PACKED_S SPINEL_DATATYPE_IPv6ADDR_S SPINEL_DATATYPE_EUI48_S SPINEL_DATATYPE_EUI64_S SPINEL_DATATYPE_UTF8_S SPINEL_DATATYPE_UTF8_S SPINEL_DATATYPE_DATA_WLEN_S - SPINEL_DATATYPE_DATA_S), + SPINEL_DATATYPE_DATA_S), kBool_1, kBool_2, kUint8, kInt8, kUint16, kInt16, kUint32, kInt32, kUint64, kInt64, kUint_1, kUint_2, kUint_3, kUint_4, &kIp6Addr, &kEui48, &kEui64, kString_1, kString_2, kData, sizeof(kData), kData, sizeof(kData)); @@ -605,7 +605,7 @@ void TestDecoder(void) frameLen = spinel_datatype_pack(buffer, sizeof(buffer), (SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_UINT16_S // Treat this as struct length - SPINEL_DATATYPE_BOOL_S), + SPINEL_DATATYPE_BOOL_S), kUint8, 10, kBool_1); DumpBuffer("Packed Spinel Frame (incorrect format)", buffer, static_cast(frameLen));