Skip to content

Commit

Permalink
[build] Fix Gradle compile_commands.json and clang-tidy warnings (wpi…
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Dec 3, 2023
1 parent 76ae090 commit ca272de
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 6 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/fix_compile_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3

import argparse
import json


def main():
parser = argparse.ArgumentParser(
description="Fix compile_commands.json generated by Gradle"
)
parser.add_argument("filename", help="compile_commands.json location")
cmd_args = parser.parse_args()

# Read JSON
with open(cmd_args.filename) as f:
data = json.load(f)

for obj in data:
out_args = []

# Filter out -isystem flags that cause false positives
iter_args = iter(obj["arguments"])
for arg in iter_args:
if arg == "-isystem":
next_arg = next(iter_args)

# /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/include/xmmintrin.h:54:1:
# error: conflicting types for '_mm_prefetch' [clang-diagnostic-error]
if not next_arg.startswith("/usr/lib/gcc/"):
out_args += ["-isystem", next_arg]
else:
out_args.append(arg)

obj["arguments"] = out_args

# Write JSON
with open(cmd_args.filename, "w") as f:
json.dump(data, f, indent=2)


if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion .github/workflows/lint-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ jobs:
- name: Install wpiformat
run: pip3 install wpiformat
- name: Create compile_commands.json
run: ./gradlew generateCompileCommands -Ptoolchain-optional-roboRio
run: |
./gradlew generateCompileCommands -Ptoolchain-optional-roboRio
./.github/workflows/fix_compile_commands.py build/TargetedCompileCommands/linuxx86-64release/compile_commands.json
./.github/workflows/fix_compile_commands.py build/TargetedCompileCommands/linuxx86-64debug/compile_commands.json
- name: List changed files
run: wpiformat -list-changed-files
- name: Run clang-tidy release
Expand Down
1 change: 1 addition & 0 deletions cscore/src/main/native/linux/NetworkListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void NetworkListener::Impl::Thread::Main() {
std::memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
// NOLINTNEXTLINE(modernize-avoid-bind)
if (bind(sd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) < 0) {
ERROR("NetworkListener: could not create socket: {}", std::strerror(errno));
::close(sd);
Expand Down
3 changes: 2 additions & 1 deletion cscore/src/main/native/windows/WindowsMessagePump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ WindowsMessagePump::WindowsMessagePump(

WindowsMessagePump::~WindowsMessagePump() {
auto res = SendMessageA(hwnd, WM_CLOSE, NULL, NULL);
if (m_mainThread.joinable())
if (m_mainThread.joinable()) {
m_mainThread.join();
}
}

void WindowsMessagePump::ThreadMain(HANDLE eventHandle) {
Expand Down
2 changes: 0 additions & 2 deletions hal/src/main/native/include/hal/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Checks:
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-virtual-near-miss,
cert-dcl58-cpp,
cert-err52-cpp,
cert-err60-cpp,
cert-mem57-cpp,
Expand All @@ -54,7 +53,6 @@ Checks:
google-readability-avoid-underscore-in-googletest-name,
google-readability-casting,
google-runtime-operator,
llvm-twine-local,
misc-definitions-in-headers,
misc-misplaced-const,
misc-new-delete-overloads,
Expand Down
69 changes: 69 additions & 0 deletions ntcore/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Checks:
'bugprone-assert-side-effect,
bugprone-bool-pointer-implicit-conversion,
bugprone-copy-constructor-init,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-incorrect-roundings,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-sizeof-container,
bugprone-sizeof-expression,
bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
bugprone-suspicious-enum-usage,
bugprone-suspicious-include,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-virtual-near-miss,
cert-err52-cpp,
cert-err60-cpp,
cert-mem57-cpp,
cert-oop57-cpp,
cert-oop58-cpp,
clang-diagnostic-*,
-clang-diagnostic-deprecated-declarations,
-clang-diagnostic-#warnings,
-clang-diagnostic-pedantic,
clang-analyzer-*,
cppcoreguidelines-slicing,
google-build-namespaces,
google-explicit-constructor,
google-global-names-in-headers,
google-readability-avoid-underscore-in-googletest-name,
google-readability-casting,
google-runtime-operator,
misc-definitions-in-headers,
misc-misplaced-const,
misc-new-delete-overloads,
misc-non-copyable-objects,
modernize-avoid-bind,
modernize-concat-nested-namespaces,
modernize-make-shared,
modernize-make-unique,
modernize-pass-by-value,
modernize-use-default-member-init,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-using,
readability-braces-around-statements'
FormatStyle: file
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ void KeyboardJoystick::EditKey(const char* label, int* key) {
void KeyboardJoystick::SettingsDisplay() {
if (s_keyEdit) {
ImGuiIO& io = ImGui::GetIO();
// NOLINTNEXTLINE(bugprone-sizeof-expression)
for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); ++i) {
if (io.KeysDown[i]) {
// remove all other uses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
using namespace frc;

void MotorController::SetVoltage(units::volt_t output) {
// NOLINTNEXTLINE(bugprone-integer-division)
Set(output / RobotController::GetBatteryVoltage());
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SlewRateLimiter {
m_negativeRateLimit{negativeRateLimit},
m_prevVal{initialValue},
m_prevTime{
units::microsecond_t(wpi::math::MathSharedStore::GetTimestamp())} {}
units::microsecond_t{wpi::math::MathSharedStore::GetTimestamp()}} {}

/**
* Creates a new SlewRateLimiter with the given positive rate limit and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void SwerveDriveKinematics<NumModules>::DesaturateWheelSpeeds(
auto k = units::math::max(translationalK, rotationalK);

auto scale = units::math::min(k * attainableMaxModuleSpeed / realMaxSpeed,
units::scalar_t(1));
units::scalar_t{1});
for (auto& module : states) {
module.speed = module.speed * scale;
}
Expand Down
1 change: 1 addition & 0 deletions wpinet/src/main/native/cpp/UDPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ int UDPClient::start(int port) {
#endif
}

// NOLINTNEXTLINE(modernize-avoid-bind)
int result = bind(m_lsd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
if (result != 0) {
WPI_ERROR(m_logger, "bind() failed: {}", SocketStrerror());
Expand Down

0 comments on commit ca272de

Please sign in to comment.