Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No functional changes. add clang-format #49

Merged
merged 7 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/clang_format_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Run clang-tidy
name: Clang-tidy

on:
push:

jobs:

validate_codestyle_clang_format:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Dependencies
run: |
sudo apt install clang-format

- name: Validate
run: |
./run_clang_format.sh
33 changes: 17 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
cmake_minimum_required(VERSION 3.16.3)
project(Wifibroadcast)

set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.16.3)
set(CMAKE_CXX_STANDARD 20)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-address-use-after-scope -fsanitize=address")

# Get spdlog from package manager for those tests
set(WB_USE_SPDLOG_EXTERNALLY OFF)
include(WBLib.cmake)
include(wifibroadcast/WBLib.cmake)

add_executable(wfb_keygen executables/wfb_keygen.cpp)
add_executable(wfb_keygen wifibroadcast/executables/wfb_keygen.cpp)
target_link_libraries(wfb_keygen PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(benchmark executables/benchmark.cpp)
add_executable(benchmark wifibroadcast/executables/benchmark.cpp)
target_link_libraries(benchmark PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(udp_generator_validator executables/udp_generator_validator.cpp)
add_executable(udp_generator_validator wifibroadcast/executables/udp_generator_validator.cpp)
target_link_libraries(udp_generator_validator PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(unit_test executables/unit_test.cpp)
add_executable(unit_test wifibroadcast/executables/unit_test.cpp)
target_link_libraries(unit_test PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(socket_helper_test executables/socket_helper_test.cpp)
add_executable(socket_helper_test wifibroadcast/executables/socket_helper_test.cpp)
target_link_libraries(socket_helper_test PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(udp_packet_drop_util executables/udp_packet_drop_util.cpp)
add_executable(udp_packet_drop_util wifibroadcast/executables/udp_packet_drop_util.cpp)
target_link_libraries(udp_packet_drop_util PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(test_txrx executables/test_txrx.cpp)
add_executable(test_txrx wifibroadcast/executables/test_txrx.cpp)
target_link_libraries(test_txrx PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(example_hello executables/example_hello.cpp)
add_executable(example_hello wifibroadcast/executables/example_hello.cpp)
target_link_libraries(example_hello PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(example_udp executables/example_udp.cpp)
add_executable(example_udp wifibroadcast/executables/example_udp.cpp)
target_link_libraries(example_udp PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(injection_rate_test executables/injection_rate_test.cpp)
add_executable(injection_rate_test wifibroadcast/executables/injection_rate_test.cpp)
target_link_libraries(injection_rate_test PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(example_pollute executables/example_pollute.cpp)
add_executable(example_pollute wifibroadcast/executables/example_pollute.cpp)
target_link_libraries(example_pollute PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(test_listen executables/test_listen.cpp)
add_executable(test_listen wifibroadcast/executables/test_listen.cpp)
target_link_libraries(test_listen PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(test_dummy_link executables/test_dummy_link.cpp)
add_executable(test_dummy_link wifibroadcast/executables/test_dummy_link.cpp)
target_link_libraries(test_dummy_link PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(test_queue executables/test_queue.cpp)
add_executable(test_queue wifibroadcast/executables/test_queue.cpp)
target_link_libraries(test_queue PRIVATE ${WB_TARGET_LINK_LIBRARIES})

# When it is a static library, we don't need to install it.
Expand Down
47 changes: 33 additions & 14 deletions run_clang_format.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
#!/bin/bash

# From https://stackoverflow.com/a/65988393
# OpenHD clang-format checking.
# Step1: Generate list of all .cpp / .h / .hpp files of this project
# (excluding subdirectories)
# Step 2: Run clang-format


function append_all_sources_headers() {
# We use .h, .cpp and .hpp in OpenHD
TMP_FILE_LIST="$(find "$1" | grep -E ".*(\.cpp|\.h|\.hpp)$")"
#TMP_FILE_LIST+='\n'
FILE_LIST+=$'\n'
FILE_LIST+=$TMP_FILE_LIST
}

THIS_PATH="$(realpath "$0")"
THIS_DIR="$(dirname "$THIS_PATH")"

EXCLUDED_DIRECTORIES="external"
append_all_sources_headers "$THIS_DIR/wifibroadcast/src"
append_all_sources_headers "$THIS_DIR/wifibroadcast/executables"

echo "Files found to format = \n\"\"\"\n$FILE_LIST\n\"\"\""

# Find all files in THIS_DIR which end in .ino, .cpp, etc., as specified
# in the regular expression just below
FILE_LIST="$(find "$THIS_DIR/src" -not -path "$THIS_DIR/src/external/*" | grep -E ".*(\.ino|\.cpp|\.c|\.h|\.hpp|\.hh)$")"
# Checks for clang-format issues and returns error if they exist
function check_warning(){
clang-format --dry-run --Werror --verbose -i --style=file $FILE_LIST

echo -e "Files found to format = \n\"\"\"\n$FILE_LIST\n\"\"\""
if [ "$?" -eq "0" ]; then
echo "Everything formatted correctly"
else
echo "There are formatting errors ! Please fix first."
exit 1
fi
}

# Format each file.
# - NB: do NOT put quotes around `$FILE_LIST` below or else the `clang-format` command will
# mistakenly see the entire blob of newline-separated file names as a SINGLE file name instead
# of as a new-line separated list of *many* file names!
#clang-format --verbose -i --style=file $FILE_LIST
# fixes any issues (re-formats everything)
function fix_warnings() {
clang-format --verbose -i --style=file $FILE_LIST
}

# Create a directory where we can build with ninja & generate the list of files for clang tidy
cmake -G Ninja -S . -B build_clang_format -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
#clang-tidy -format-style=file -p build_clang_format $FILE_LIST
#fix_warnings
check_warning
100 changes: 0 additions & 100 deletions wifibroadcast/HelperSources/BlockSizeHelper.hpp

This file was deleted.

80 changes: 0 additions & 80 deletions wifibroadcast/HelperSources/DummyStreamGenerator.hpp

This file was deleted.

55 changes: 0 additions & 55 deletions wifibroadcast/HelperSources/EmulatedPacketDrop.hpp

This file was deleted.

Loading
Loading