From 8aecc897d7bbdf6c6f92725f346a81af592c70af Mon Sep 17 00:00:00 2001 From: Ivan-lis Date: Fri, 18 Oct 2024 07:44:15 +0000 Subject: [PATCH] Added Cland/GCC builds and Analyzers tasks for vscode --- .vscode/launch.json | 2 +- .vscode/tasks.json | 273 +++++++++++++++++++++++++++++++++++++++----- CMakeLists.txt | 2 +- 3 files changed, 244 insertions(+), 33 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1ee66a5..2a94c2f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "program": "${workspaceFolder}/build/examples/output/connect", "args": [], "cwd": "${workspaceFolder}", - "preLaunchTask": "Build Debug GCC" + "preLaunchTask": "GCC: Build" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 55a74f4..970b6dd 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -3,6 +3,33 @@ // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ + // + // Checkers/Analyzers tasks + // + { + "label": "Checker: clang-format dry-run", + "type": "shell", + "command": "for FILE in $(find . -type f \\( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \\) ! -path '*build*'); do clang-format -i $FILE --dry-run --Werror; done" + }, + { + "label": "Checker: clang-format fix errors", + "type": "shell", + "command": "for FILE in $(find . -type f \\( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \\) ! -path '*build*'); do clang-format -i $FILE --Werror; done" + }, + { + // https://clang.llvm.org/extra/clang-tidy/ + "label": "Checker: clang-tidy dry-run", + "type": "shell", + "command": [ + "python /home/tools/run-clang-tidy.py -exclude-header-filter .*build.* -use-color -header-filter .hpp -p ${workspaceFolder}/build_clang/ -config-file ${workspaceFolder}/.clang-tidy ", + " ${workspaceFolder}/examples ", + " ${workspaceFolder}/library/ ", + " ${workspaceFolder}/src/" + ] + }, + // + // Ejabberd tasks + // { "label": "Ejabberd: show logs", "type": "shell", @@ -11,54 +38,238 @@ ] }, { - "label": "Ejabberd: open shell", + "label": "Ejabberd: show localhost registered users", "type": "shell", "command": [ - "sudo docker exec -it ejabberd sh" + "sudo docker exec -it ejabberd ejabberdctl registered_users localhost" ] }, { - "label": "Build Debug GCC", + "label": "Ejabberd: open shell", + "type": "shell", + "command": [ + "printf 'Example cmd: ejabberdctl registered_users localhost\n\n';", + "sudo docker exec -it ejabberd sh" + ] + }, + // + // GCC build related tasks + // + { + "label": "GCC: Clean build folder", + "type": "shell", + "command": "if [ -n \"$(ls -A ${workspaceFolder}/build)\" ]; then rm -rf ${workspaceFolder}/build/*; fi", + "hide": true + }, + { + "label": "GCC: Configure Debug", "type": "shell", "command": [ "cd ${workspaceFolder} &&", "mkdir -p build && cd build &&", - "cmake -Wno-dev -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON .. &&", - "cmake --build . --parallel `nproc`", - "|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )" - ], - "options": { - "env": {} - }, - "presentation": { - "clear": true - }, - "problemMatcher": [], - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "label": "Build Debug Clang", - "type": "shell", - "command": [ - "cd ${workspaceFolder} &&", - "mkdir -p build_clang && cd build_clang &&", - "cmake -Wno-dev -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON .. &&", - "cmake --build . --parallel `nproc`", - "|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )" + "cmake -Wno-dev ", + " -DCMAKE_CXX_FLAGS=\"-Wno-non-template-friend\"", + " -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON .." ], "options": { "env": { - "CC": "/usr/sbin/clang", - "CXX": "/usr/sbin/clang++" + "CC": "/usr/sbin/gcc", + "CXX": "/usr/sbin/g++" } }, "presentation": { "clear": true }, - "problemMatcher": [] + "hide": true + }, + { + "label": "GCC: Build", + "type": "shell", + "command": [ + "cd ${workspaceFolder}/build &&", + "cmake --build . --parallel `nproc`", + "|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )" + ], + "presentation": { + "clear": true + }, + "hide": true, + "group": { + "kind": "build" + } + }, + { + "label": "GCC: Configure and build Debug", + "type": "shell", + "command": "echo Finished!", + "presentation": { + "clear": true + }, + "dependsOrder": "sequence", + "dependsOn":[ + "GCC: Clean build folder", + "GCC: Configure Debug", + "GCC: Build" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, + // + // Clang build related tasks + // + { + "label": "Clang: Configure Debug", + "type": "shell", + "command": [ + "cd ${workspaceFolder} &&", + "mkdir -p build_clang && cd build_clang &&", + "cmake -Wno-dev ", + " -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON ", + " -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++\"", + " -DCMAKE_EXE_LINKER_FLAGS=\"-L/usr/lib/x86_64-linux-gnu -lstdc++\" .." + ], + "options": { + "env": { + "CC": "/home/LLVM-19.1.0/bin/clang", + "CXX": "/home/LLVM-19.1.0/bin/clang++" + } + }, + "presentation": { + "clear": true + }, + "hide": true + }, + { + "label": "Clang: Configure Debug with -fsanitize=address", + "type": "shell", + "command": [ + "cd ${workspaceFolder} &&", + "mkdir -p build_clang && cd build_clang &&", + "cmake -Wno-dev ", + " -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON ", + " -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++ -fno-omit-frame-pointer -g -fsanitize=address,undefined,leak,function,nullability,vptr\"", + " -DCMAKE_EXE_LINKER_FLAGS=\"-L/usr/lib/x86_64-linux-gnu -lstdc++ -fno-omit-frame-pointer -g -fsanitize=address,undefined,leak,function,nullability,vptr\" ..", + ], + "options": { + "env": { + "CC": "/home/LLVM-19.1.0/bin/clang", + "CXX": "/home/LLVM-19.1.0/bin/clang++" + } + }, + "presentation": { + "clear": true + }, + "hide": true + }, + { + // + // Useful links: + // - https://github.com/google/sanitizers/wiki/addresssanitizerflags + // - https://clang.llvm.org/docs/AddressSanitizer.html + // + "label": "Clang: Exec gtest with -fsanitize=address", + "type": "shell", + "command": [ + "cd ${workspaceFolder} &&", + "mkdir -p build_clang && cd build_clang &&", + "ASAN_SYMBOLIZER_PATH=/home/LLVM-19.1.0/bin/llvm-symbolizer ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:detect_leaks=1:atexit=1:abort_on_error=1 ./larra_xmpp_tests ; echo \"exit code: $?\"", + ], + "presentation": { + "clear": true + }, + "dependsOrder": "sequence", + "dependsOn":[ + "Clang: Clean build folder", + "Clang: Configure Debug with -fsanitize=address", + "Clang: Build" + ] + }, + { + "label": "Clang: Configure Debug with -fsanitize=memory", + "type": "shell", + "command": [ + "cd ${workspaceFolder} &&", + "mkdir -p build_clang && cd build_clang &&", + "cmake -Wno-dev ", + " -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON ", + " -DCMAKE_CXX_FLAGS=\"-stdlib=libstdc++ -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fsanitize=memory\"", + " -DCMAKE_EXE_LINKER_FLAGS=\"-L/usr/lib/x86_64-linux-gnu -lstdc++ -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fsanitize=memory\" ..", + ], + "options": { + "env": { + "CC": "/home/LLVM-19.1.0/bin/clang", + "CXX": "/home/LLVM-19.1.0/bin/clang++" + } + }, + "presentation": { + "clear": true + }, + "hide": true + }, + { + // + // Useful links: + // - https://github.com/google/sanitizers/wiki/MemorySanitizer + // - https://clang.llvm.org/docs/MemorySanitizer.html + // + "label": "Clang: Exec gtest with -fsanitize=memory", + "type": "shell", + "command": [ + "cd ${workspaceFolder} &&", + "mkdir -p build_clang && cd build_clang &&", + "MSAN_SYMBOLIZER_PATH=/home/LLVM-19.1.0/bin/llvm-symbolizer MSAN_OPTIONS=abort_on_error=1 ./larra_xmpp_tests ; echo \"exit code: $?\"", + ], + "presentation": { + "clear": true + }, + "dependsOrder": "sequence", + "dependsOn":[ + "Clang: Clean build folder", + "Clang: Configure Debug with -fsanitize=memory", + "Clang: Build" + ] + }, + { + "label": "Clang: Build", + "type": "shell", + "command": [ + "cd ${workspaceFolder}/build_clang &&", + "cmake --build . --parallel `nproc`", + "|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )" + ], + "presentation": { + "clear": true + }, + "group": { + "kind": "build" + }, + "hide": true + }, + { + "label": "Clang: Configure and build Debug", + "type": "shell", + "command": [ + "cd ${workspaceFolder} &&", + "mkdir -p build_clang && cd build_clang &&", + "MSAN_SYMBOLIZER_PATH=/home/LLVM-19.1.0/bin/llvm-symbolizer MSAN_OPTIONS=abort_on_error=1 ./larra_xmpp_tests ; echo \"exit code: $?\"", + ], + "presentation": { + "clear": true + }, + "dependsOrder": "sequence", + "dependsOn":[ + "Clang: Clean build folder", + "Clang: Configure Debug", + "Clang: Build" + ] + }, + { + "label": "Clang: Clean build folder", + "type": "shell", + "command": "if [ -n \"$(ls -A ${workspaceFolder}/build_clang)\" ]; then rm -rf ${workspaceFolder}/build_clang/*; fi", + "hide": true } ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c4cf7e..9ed1307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,7 +164,7 @@ add_library(larra::larra_xmpp ALIAS larra_xmpp) target_compile_features(larra_xmpp PUBLIC cxx_std_23) -target_compile_options(larra_xmpp PUBLIC -Wno-changes-meaning) +target_compile_options(larra_xmpp PUBLIC "$<$:-Wno-changes-meaning>") target_include_directories(larra_xmpp PUBLIC $