From: Adrian Freihofer <[email protected]> Just run clang-tidy, fixing warnings and applying the configured checks. Add also the .clang-tidy configuration file.
Signed-off-by: Adrian Freihofer <[email protected]> cmake-example: add .clang-tidy configuration file Signed-off-by: Adrian Freihofer <[email protected]> --- .../recipes-test/cpp/cpp-example.inc | 1 + .../recipes-test/cpp/files/.clang-tidy | 33 +++++++++++++++++++ .../cpp/files/cpp-example-lib.hpp | 3 +- .../recipes-test/cpp/files/cpp-example.cpp | 1 + .../cpp/files/test-cpp-example.cpp | 2 +- meta/lib/oeqa/selftest/cases/devtool.py | 20 +++++------ 6 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 meta-selftest/recipes-test/cpp/files/.clang-tidy diff --git a/meta-selftest/recipes-test/cpp/cpp-example.inc b/meta-selftest/recipes-test/cpp/cpp-example.inc index 603040d123..5800f804e1 100644 --- a/meta-selftest/recipes-test/cpp/cpp-example.inc +++ b/meta-selftest/recipes-test/cpp/cpp-example.inc @@ -23,6 +23,7 @@ SRC_URI = "\ file://cpp-example.service \ file://cpp-example.init \ file://.clang-format \ + file://.clang-tidy \ file://run-ptest \ " diff --git a/meta-selftest/recipes-test/cpp/files/.clang-tidy b/meta-selftest/recipes-test/cpp/files/.clang-tidy new file mode 100644 index 0000000000..d1cafb1fe6 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/.clang-tidy @@ -0,0 +1,33 @@ +--- +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +Checks: > + -*, + bugprone-*, + -bugprone-easily-swappable-parameters, + clang-analyzer-*, + modernize-*, + -modernize-use-trailing-return-type, + performance-*, + -performance-avoid-endl, + readability-*, + -readability-magic-numbers, + -readability-identifier-length, + -readability-implicit-bool-conversion, + -readability-convert-member-functions-to-static, + -readability-isolate-declaration + +WarningsAsErrors: '' +HeaderFilterRegex: '.*' +FormatStyle: file + +CheckOptions: + - key: readability-identifier-naming.VariableCase + value: lower_case + - key: readability-identifier-naming.FunctionCase + value: lower_case + - key: readability-identifier-naming.StructCase + value: CamelCase + - key: readability-identifier-naming.ClassCase + value: CamelCase diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp index 5af30e2a79..7318d4db84 100644 --- a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp +++ b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp @@ -12,13 +12,14 @@ struct CppExample { + // NOLINTNEXTLINE(bugprone-throwing-static-initialization) -- exercises debugger handling of a lazy-init static member, see devtool ide-sdk tests inline static const std::string test_string = "cpp-example-lib Magic: 123456789"; /* Header-only function, to exercise breakpoint resolution against * header-only debug info. volatile prevents compiler optimization from * eliminating the function body, ensuring a concrete code location exists * for debugger breakpoints. */ - inline static int scale_number(int n) + static int scale_number(int n) { volatile int scaled = n * 7; std::cout << "scale_number(" << n << ") = " << scaled << std::endl; diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example.cpp b/meta-selftest/recipes-test/cpp/files/cpp-example.cpp index af7a8c2d73..c14def288c 100644 --- a/meta-selftest/recipes-test/cpp/files/cpp-example.cpp +++ b/meta-selftest/recipes-test/cpp/files/cpp-example.cpp @@ -113,6 +113,7 @@ int main(int argc, char *argv[]) log_info(std::string("Linking json-c version ") + cpp_example.get_json_c_version()); cpp_example.print_json(); + // NOLINTNEXTLINE(bugprone-infinite-loop) -- intentionally endless when requested; stopped externally (e.g. systemd stop/SIGTERM) do { // Read and print message from config file std::string config_message = cpp_example.read_config_message(); diff --git a/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp b/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp index d8f2547e88..69dc2fe6d5 100644 --- a/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp +++ b/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp @@ -17,7 +17,7 @@ int main() { auto cpp_example = CppExample(); auto ret_string = cpp_example.get_string(); - if (0 == ret_string.compare(CppExample::test_string + FAIL_COMPARISON_STR)) { + if (ret_string == CppExample::test_string + FAIL_COMPARISON_STR) { std::cout << "PASS: " << ret_string << " = " << CppExample::test_string << std::endl; } else { std::cout << "FAIL: " << ret_string << " != " << CppExample::test_string << std::endl; diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py index 38eb9b3905..1cc9843a72 100644 --- a/meta/lib/oeqa/selftest/cases/devtool.py +++ b/meta/lib/oeqa/selftest/cases/devtool.py @@ -3312,8 +3312,8 @@ class DevtoolIdeSdkTests(DevtoolBase): cpp_code = file.read() cpp_code = cpp_code.replace(DevtoolIdeSdkTests.MAGIC_STRING_ORIG, MAGIC_STRING_NEW) cpp_code = cpp_code.replace( - " inline static int scale_number(int n)", - extra_lines + " inline static int scale_number(int n)") + " static int scale_number(int n)", + extra_lines + " static int scale_number(int n)") with open(cpp_example_lib_hpp, 'w') as file: file.write(cpp_code) @@ -3362,8 +3362,8 @@ class DevtoolIdeSdkTests(DevtoolBase): # the first _gdb_cross_debugging_multi call above. self._gdb_cross_debugging_multi( qemu, recipe_name, example_exe, MAGIC_STRING_NEW, - exe_break_line=136 + LINE_SHIFT, exe_list_line=128 + LINE_SHIFT, - hpp_break_line=21 + LINE_SHIFT, lib_break_line=31 + LINE_SHIFT) + exe_break_line=136 + LINE_SHIFT, exe_list_line=129 + LINE_SHIFT, + hpp_break_line=24 + LINE_SHIFT, lib_break_line=31 + LINE_SHIFT) def _verify_cmake_preset(self, tempdir): """Verify the generated cmake preset works as expected @@ -3532,14 +3532,14 @@ class DevtoolIdeSdkGccTests(DevtoolIdeSdkTests): self.assertIn("GNU gdb", r.output) def _gdb_debug_cpp_example(self, magic_string, gdb_start_cmd="run", - exe_break_line=136, exe_list_line=128, hpp_break_line=21, + exe_break_line=136, exe_list_line=129, hpp_break_line=24, lib_break_line=31): """Get a series of gdb commands to debug the cpp-example-lib example""" gdb_batch_cmd = " -ex 'break main' -ex '%s'" % gdb_start_cmd gdb_batch_cmd += " -ex 'break CppExample::print_json()' -ex 'continue'" gdb_batch_cmd += " -ex 'print CppExample::test_string.compare(\"cpp-example-lib %s\")'" % magic_string gdb_batch_cmd += " -ex 'print CppExample::test_string.compare(\"cpp-example-lib %saaa\")'" % magic_string - gdb_batch_cmd += " -ex 'list cpp-example-lib.hpp:15,15'" + gdb_batch_cmd += " -ex 'list cpp-example-lib.hpp:16,16'" # Break inside the library's own .cpp file by file:line (not by # symbol), while still inside the print_json() call reached above. @@ -3578,7 +3578,7 @@ class DevtoolIdeSdkGccTests(DevtoolIdeSdkTests): gdb_batch_cmd += " -ex 'continue'" return gdb_batch_cmd - def _gdb_debug_cpp_example_check(self, gdb_output, magic_string, exe_list_line=128, lib_break_line=31): + def _gdb_debug_cpp_example_check(self, gdb_output, magic_string, exe_list_line=129, lib_break_line=31): self.assertIn("Breakpoint 1, main", gdb_output) self.assertIn("$1 = 0", gdb_output) # test.string.compare equal self.assertIn("$2 = -3", gdb_output) # test.string.compare longer @@ -3606,7 +3606,7 @@ class DevtoolIdeSdkGccTests(DevtoolIdeSdkTests): self.assertIn("exited normally", gdb_output) def _gdb_cross_debugging_multi(self, qemu, recipe_name, example_exe, magic_string, - exe_break_line=136, exe_list_line=128, hpp_break_line=21, + exe_break_line=136, exe_list_line=129, hpp_break_line=24, lib_break_line=31): """Verify gdb-cross is working @@ -4814,8 +4814,8 @@ class DevtoolIdeSdkClangTests(DevtoolIdeSdkTests): cpp_code = file.read() cpp_code = cpp_code.replace(DevtoolIdeSdkTests.MAGIC_STRING_ORIG, magic_string_new) cpp_code = cpp_code.replace( - " inline static int scale_number(int n)", - extra_lines + " inline static int scale_number(int n)") + " static int scale_number(int n)", + extra_lines + " static int scale_number(int n)") with open(cpp_example_lib_hpp, 'w') as file: file.write(cpp_code) -- 2.55.0
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#245513): https://lists.openembedded.org/g/openembedded-core/message/245513 Mute This Topic: https://lists.openembedded.org/mt/121171409/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
