diff --git a/.github/workflows/comment-command.yml b/.github/workflows/comment-command.yml index 9a12ce5036..5550850f8f 100644 --- a/.github/workflows/comment-command.yml +++ b/.github/workflows/comment-command.yml @@ -37,13 +37,14 @@ jobs: python-version: 3.8 - name: Install clang-format run: | - sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -cs)-proposed restricted main multiverse universe' >> /etc/apt/sources.list.d/proposed-repositories.list" + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo sh -c "echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main' >> /etc/apt/sources.list.d/proposed-repositories.list" sudo apt-get update -q - sudo apt-get install -y clang-format-12 + sudo apt-get install -y clang-format-14 - name: Install wpiformat run: pip3 install wpiformat - name: Run wpiformat - run: wpiformat -clang 12 + run: wpiformat -clang 14 - name: Commit run: | # Set credentials diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml index e893c58faa..5eee98c3e0 100644 --- a/.github/workflows/lint-format.yml +++ b/.github/workflows/lint-format.yml @@ -28,13 +28,14 @@ jobs: python-version: 3.8 - name: Install clang-format run: | - sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -cs)-proposed restricted main multiverse universe' >> /etc/apt/sources.list.d/proposed-repositories.list" + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo sh -c "echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main' >> /etc/apt/sources.list.d/proposed-repositories.list" sudo apt-get update -q - sudo apt-get install -y clang-format-12 + sudo apt-get install -y clang-format-14 - name: Install wpiformat run: pip3 install wpiformat - name: Run - run: wpiformat -clang 12 + run: wpiformat -clang 14 - name: Check output run: git --no-pager diff --exit-code HEAD - name: Generate diff @@ -63,9 +64,10 @@ jobs: python-version: 3.8 - name: Install clang-tidy run: | - sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -cs)-proposed restricted main multiverse universe' >> /etc/apt/sources.list.d/proposed-repositories.list" + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo sh -c "echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main' >> /etc/apt/sources.list.d/proposed-repositories.list" sudo apt-get update -q - sudo apt-get install -y clang-tidy-12 clang-format-12 + sudo apt-get install -y clang-tidy-14 clang-format-14 - name: Install wpiformat run: pip3 install wpiformat - name: Create compile_commands.json @@ -73,7 +75,7 @@ jobs: - name: List changed files run: wpiformat -list-changed-files - name: Run clang-tidy - run: wpiformat -clang 12 -no-format -tidy-changed -compile-commands=build/compile_commands/linuxx86-64 -vv + run: wpiformat -clang 14 -no-format -tidy-changed -compile-commands=build/compile_commands/linuxx86-64 -vv javaformat: name: "Java format" runs-on: ubuntu-latest diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e7b2162a81..5dd7ee5eaf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ So you want to contribute your changes back to WPILib. Great! We have a few cont ## Coding Guidelines -WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system. We currently use clang-format 12.0 with wpiformat. +WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system. We currently use clang-format 14.0 with wpiformat. While the library should be fully formatted according to the styles, additional elements of the style guide were not followed when the library was initially created. All new code should follow the guidelines. If you are looking for some easy ramp-up tasks, finding areas that don't follow the style guide and fixing them is very welcome. diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index b90fc771d8..035f451188 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -5,5 +5,5 @@ repositories { } } dependencies { - implementation "edu.wpi.first:native-utils:2023.0.7" + implementation "edu.wpi.first:native-utils:2023.0.8" } diff --git a/cscore/src/main/native/cpp/Image.h b/cscore/src/main/native/cpp/Image.h index 9a1579f281..98d86759b0 100644 --- a/cscore/src/main/native/cpp/Image.h +++ b/cscore/src/main/native/cpp/Image.h @@ -22,7 +22,9 @@ class Image { public: #ifndef __linux__ - explicit Image(size_t capacity) { m_data.reserve(capacity); } + explicit Image(size_t capacity) { + m_data.reserve(capacity); + } #else explicit Image(size_t capacity) : m_data{capacity, default_init_allocator{}} { @@ -34,20 +36,38 @@ class Image { Image& operator=(const Image&) = delete; // Getters - operator std::string_view() const { return str(); } // NOLINT - std::string_view str() const { return {data(), size()}; } - size_t capacity() const { return m_data.capacity(); } + operator std::string_view() const { // NOLINT + return str(); + } + std::string_view str() const { + return {data(), size()}; + } + size_t capacity() const { + return m_data.capacity(); + } const char* data() const { return reinterpret_cast(m_data.data()); } - char* data() { return reinterpret_cast(m_data.data()); } - size_t size() const { return m_data.size(); } + char* data() { + return reinterpret_cast(m_data.data()); + } + size_t size() const { + return m_data.size(); + } - const std::vector& vec() const { return m_data; } - std::vector& vec() { return m_data; } + const std::vector& vec() const { + return m_data; + } + std::vector& vec() { + return m_data; + } - void resize(size_t size) { m_data.resize(size); } - void SetSize(size_t size) { m_data.resize(size); } + void resize(size_t size) { + m_data.resize(size); + } + void SetSize(size_t size) { + m_data.resize(size); + } cv::Mat AsMat() { int type; @@ -68,7 +88,9 @@ class Image { return cv::Mat{height, width, type, m_data.data()}; } - cv::_InputArray AsInputArray() { return cv::_InputArray{m_data}; } + cv::_InputArray AsInputArray() { + return cv::_InputArray{m_data}; + } bool Is(int width_, int height_) { return width == width_ && height == height_; @@ -90,8 +112,12 @@ class Image { bool IsLarger(const Image& oth) { return width >= oth.width && height >= oth.height; } - bool IsSmaller(int width_, int height_) { return !IsLarger(width_, height_); } - bool IsSmaller(const Image& oth) { return !IsLarger(oth); } + bool IsSmaller(int width_, int height_) { + return !IsLarger(width_, height_); + } + bool IsSmaller(const Image& oth) { + return !IsLarger(oth); + } private: std::vector m_data; diff --git a/hal/src/main/native/athena/CTREPCM.cpp b/hal/src/main/native/athena/CTREPCM.cpp index 37faf696f4..5f42322325 100644 --- a/hal/src/main/native/athena/CTREPCM.cpp +++ b/hal/src/main/native/athena/CTREPCM.cpp @@ -394,9 +394,8 @@ void HAL_SetCTREPCMOneShotDuration(HAL_CTREPCMHandle handle, int32_t index, } std::scoped_lock lock{pcm->lock}; - pcm->oneShot.sol10MsPerUnit[index] = - (std::min)(static_cast(durMs) / 10, - static_cast(0xFF)); + pcm->oneShot.sol10MsPerUnit[index] = (std::min)( + static_cast(durMs) / 10, static_cast(0xFF)); HAL_WriteCANPacketRepeating(pcm->canHandle, pcm->oneShot.sol10MsPerUnit, 8, Control3, SendPeriod, status); } diff --git a/hal/src/main/native/include/hal/simulation/SimDataValue.h b/hal/src/main/native/include/hal/simulation/SimDataValue.h index 7e2b644c7b..0f0cde59c8 100644 --- a/hal/src/main/native/include/hal/simulation/SimDataValue.h +++ b/hal/src/main/native/include/hal/simulation/SimDataValue.h @@ -148,22 +148,24 @@ class SimDataValue final : public impl::SimDataValueBase { * @param DATA the backing data array * @param LOWERNAME the lowercase name of the backing data variable */ -#define HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, NS, CAPINAME, DATA, LOWERNAME) \ - int32_t NS##_Register##CAPINAME##Callback( \ - int32_t index, HAL_NotifyCallback callback, void* param, \ - HAL_Bool initialNotify) { \ - return DATA[index].LOWERNAME.RegisterCallback(callback, param, \ - initialNotify); \ - } \ - \ - void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) { \ - DATA[index].LOWERNAME.CancelCallback(uid); \ - } \ - \ - TYPE NS##_Get##CAPINAME(int32_t index) { return DATA[index].LOWERNAME; } \ - \ - void NS##_Set##CAPINAME(int32_t index, TYPE LOWERNAME) { \ - DATA[index].LOWERNAME = LOWERNAME; \ +#define HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, NS, CAPINAME, DATA, LOWERNAME) \ + int32_t NS##_Register##CAPINAME##Callback( \ + int32_t index, HAL_NotifyCallback callback, void* param, \ + HAL_Bool initialNotify) { \ + return DATA[index].LOWERNAME.RegisterCallback(callback, param, \ + initialNotify); \ + } \ + \ + void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) { \ + DATA[index].LOWERNAME.CancelCallback(uid); \ + } \ + \ + TYPE NS##_Get##CAPINAME(int32_t index) { \ + return DATA[index].LOWERNAME; \ + } \ + \ + void NS##_Set##CAPINAME(int32_t index, TYPE LOWERNAME) { \ + DATA[index].LOWERNAME = LOWERNAME; \ } /** @@ -232,9 +234,13 @@ class SimDataValue final : public impl::SimDataValueBase { DATA->LOWERNAME.CancelCallback(uid); \ } \ \ - TYPE NS##_Get##CAPINAME(void) { return DATA->LOWERNAME; } \ + TYPE NS##_Get##CAPINAME(void) { \ + return DATA->LOWERNAME; \ + } \ \ - void NS##_Set##CAPINAME(TYPE LOWERNAME) { DATA->LOWERNAME = LOWERNAME; } + void NS##_Set##CAPINAME(TYPE LOWERNAME) { \ + DATA->LOWERNAME = LOWERNAME; \ + } /** * Define a stub standard C API for simulation data. @@ -261,7 +267,9 @@ class SimDataValue final : public impl::SimDataValueBase { \ void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) {} \ \ - TYPE NS##_Get##CAPINAME(int32_t index) { return RETURN; } \ + TYPE NS##_Get##CAPINAME(int32_t index) { \ + return RETURN; \ + } \ \ void NS##_Set##CAPINAME(int32_t index, TYPE) {} @@ -281,18 +289,20 @@ class SimDataValue final : public impl::SimDataValueBase { * @param CAPINAME the C API name (usually first letter capitalized) * @param RETURN what to return from the Get function */ -#define HAL_SIMDATAVALUE_STUB_CAPI_CHANNEL(TYPE, NS, CAPINAME, RETURN) \ - int32_t NS##_Register##CAPINAME##Callback( \ - int32_t index, int32_t channel, HAL_NotifyCallback callback, \ - void* param, HAL_Bool initialNotify) { \ - return 0; \ - } \ - \ - void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t channel, \ - int32_t uid) {} \ - \ - TYPE NS##_Get##CAPINAME(int32_t index, int32_t channel) { return RETURN; } \ - \ +#define HAL_SIMDATAVALUE_STUB_CAPI_CHANNEL(TYPE, NS, CAPINAME, RETURN) \ + int32_t NS##_Register##CAPINAME##Callback( \ + int32_t index, int32_t channel, HAL_NotifyCallback callback, \ + void* param, HAL_Bool initialNotify) { \ + return 0; \ + } \ + \ + void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t channel, \ + int32_t uid) {} \ + \ + TYPE NS##_Get##CAPINAME(int32_t index, int32_t channel) { \ + return RETURN; \ + } \ + \ void NS##_Set##CAPINAME(int32_t index, int32_t channel, TYPE) {} /** @@ -318,7 +328,9 @@ class SimDataValue final : public impl::SimDataValueBase { \ void NS##_Cancel##CAPINAME##Callback(int32_t uid) {} \ \ - TYPE NS##_Get##CAPINAME(void) { return RETURN; } \ + TYPE NS##_Get##CAPINAME(void) { \ + return RETURN; \ + } \ \ void NS##_Set##CAPINAME(TYPE) {} diff --git a/ntcore/src/main/native/cpp/WireDecoder.h b/ntcore/src/main/native/cpp/WireDecoder.h index 972be57b1f..34bfb0fdc8 100644 --- a/ntcore/src/main/native/cpp/WireDecoder.h +++ b/ntcore/src/main/native/cpp/WireDecoder.h @@ -125,7 +125,9 @@ class WireDecoder { bool ReadDouble(double* val); /* Reads an ULEB128-encoded unsigned integer. */ - bool ReadUleb128(uint64_t* val) { return wpi::ReadUleb128(m_is, val); } + bool ReadUleb128(uint64_t* val) { + return wpi::ReadUleb128(m_is, val); + } bool ReadType(NT_Type* type); bool ReadString(std::string* str); diff --git a/wpilibc/src/main/native/include/frc/RobotBase.h b/wpilibc/src/main/native/include/frc/RobotBase.h index 3379d1f098..9a072742ed 100644 --- a/wpilibc/src/main/native/include/frc/RobotBase.h +++ b/wpilibc/src/main/native/include/frc/RobotBase.h @@ -216,7 +216,9 @@ class RobotBase { * * @return If the robot is running in simulation. */ - static constexpr bool IsSimulation() { return !IsReal(); } + static constexpr bool IsSimulation() { + return !IsReal(); + } /** * Constructor for a generic robot program. diff --git a/wpinet/src/test/native/cpp/WebSocketTest.h b/wpinet/src/test/native/cpp/WebSocketTest.h index 0e42c67c44..4fedb21238 100644 --- a/wpinet/src/test/native/cpp/WebSocketTest.h +++ b/wpinet/src/test/native/cpp/WebSocketTest.h @@ -49,7 +49,9 @@ class WebSocketTest : public ::testing::Test { failTimer->Unreference(); } - ~WebSocketTest() override { Finish(); } + ~WebSocketTest() override { + Finish(); + } void Finish() { loop->Walk([](uv::Handle& it) { it.Close(); }); diff --git a/wpiutil/src/main/native/include/wpi/MappedFileRegion.h b/wpiutil/src/main/native/include/wpi/MappedFileRegion.h index 33d3bb9df0..05e487e2a8 100644 --- a/wpiutil/src/main/native/include/wpi/MappedFileRegion.h +++ b/wpiutil/src/main/native/include/wpi/MappedFileRegion.h @@ -59,13 +59,19 @@ class MappedFileRegion { return *this; } - explicit operator bool() const { return m_mapping != nullptr; } + explicit operator bool() const { + return m_mapping != nullptr; + } void Flush(); void Unmap(); - uint64_t size() const { return m_size; } - uint8_t* data() const { return static_cast(m_mapping); } + uint64_t size() const { + return m_size; + } + uint8_t* data() const { + return static_cast(m_mapping); + } const uint8_t* const_data() const { return static_cast(m_mapping); }