[ci] Upgrade to clang-format and clang-tidy 14 (NFC) (#4347)

This commit is contained in:
Tyler Veness
2022-08-16 15:25:04 -07:00
committed by GitHub
parent d45bcddd15
commit 340465c929
11 changed files with 117 additions and 65 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -5,5 +5,5 @@ repositories {
}
}
dependencies {
implementation "edu.wpi.first:native-utils:2023.0.7"
implementation "edu.wpi.first:native-utils:2023.0.8"
}

View File

@@ -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<uchar>{}} {
@@ -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<const char*>(m_data.data());
}
char* data() { return reinterpret_cast<char*>(m_data.data()); }
size_t size() const { return m_data.size(); }
char* data() {
return reinterpret_cast<char*>(m_data.data());
}
size_t size() const {
return m_data.size();
}
const std::vector<uchar>& vec() const { return m_data; }
std::vector<uchar>& vec() { return m_data; }
const std::vector<uchar>& vec() const {
return m_data;
}
std::vector<uchar>& 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<uchar> m_data;

View File

@@ -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<uint32_t>(durMs) / 10,
static_cast<uint32_t>(0xFF));
pcm->oneShot.sol10MsPerUnit[index] = (std::min)(
static_cast<uint32_t>(durMs) / 10, static_cast<uint32_t>(0xFF));
HAL_WriteCANPacketRepeating(pcm->canHandle, pcm->oneShot.sol10MsPerUnit, 8,
Control3, SendPeriod, status);
}

View File

@@ -148,22 +148,24 @@ class SimDataValue final : public impl::SimDataValueBase<T, MakeValue> {
* @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<T, MakeValue> {
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<T, MakeValue> {
\
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<T, MakeValue> {
* @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<T, MakeValue> {
\
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) {}

View File

@@ -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);

View File

@@ -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.

View File

@@ -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(); });

View File

@@ -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<uint8_t*>(m_mapping); }
uint64_t size() const {
return m_size;
}
uint8_t* data() const {
return static_cast<uint8_t*>(m_mapping);
}
const uint8_t* const_data() const {
return static_cast<const uint8_t*>(m_mapping);
}