diff mbox series

[08/15] cpp-example: update formatting and code style

Message ID 20260909215337.89106-9-adrian.freihofer@siemens.com
State New
Headers show
Series devtool ide-sdk: support booting from NFS, VSCode clangd | expand

Commit Message

AdrianF Sept. 9, 2026, 9:53 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Just run clang-format on the source files and add the .clang-format
configuration file.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 .../recipes-test/cpp/cpp-example.inc          |  1 +
 .../recipes-test/cpp/files/.clang-format      | 42 +++++++++++++++++++
 .../recipes-test/cpp/files/cpp-example.cpp    |  4 +-
 .../recipes-test/cpp/files/daemonize.cpp      |  2 +-
 .../recipes-test/cpp/files/daemonize.hpp      |  2 +-
 .../cpp/files/test-cpp-example.cpp            | 13 +++---
 6 files changed, 54 insertions(+), 10 deletions(-)
 create mode 100644 meta-selftest/recipes-test/cpp/files/.clang-format
diff mbox series

Patch

diff --git a/meta-selftest/recipes-test/cpp/cpp-example.inc b/meta-selftest/recipes-test/cpp/cpp-example.inc
index 3934345f17..603040d123 100644
--- a/meta-selftest/recipes-test/cpp/cpp-example.inc
+++ b/meta-selftest/recipes-test/cpp/cpp-example.inc
@@ -22,6 +22,7 @@  SRC_URI = "\
     file://config.h.in \
     file://cpp-example.service \
     file://cpp-example.init \
+    file://.clang-format \
     file://run-ptest \
 "
 
diff --git a/meta-selftest/recipes-test/cpp/files/.clang-format b/meta-selftest/recipes-test/cpp/files/.clang-format
new file mode 100644
index 0000000000..e22fadaee9
--- /dev/null
+++ b/meta-selftest/recipes-test/cpp/files/.clang-format
@@ -0,0 +1,42 @@ 
+---
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+BasedOnStyle: LLVM
+Language: Cpp
+Standard: c++17
+
+IndentWidth: 4
+UseTab: Never
+ColumnLimit: 100
+
+BreakBeforeBraces: Custom
+BraceWrapping:
+  AfterFunction: true
+  AfterClass: true
+  AfterStruct: true
+  AfterEnum: true
+  AfterUnion: true
+  AfterNamespace: false
+  AfterControlStatement: Never
+  BeforeElse: false
+  BeforeCatch: false
+  SplitEmptyFunction: false
+  SplitEmptyRecord: false
+AlwaysBreakAfterReturnType: None
+IndentCaseLabels: true
+NamespaceIndentation: None
+AccessModifierOffset: -4
+
+PointerAlignment: Right
+ReferenceAlignment: Right
+SpaceAfterCStyleCast: false
+SpaceBeforeParens: ControlStatements
+
+AllowShortFunctionsOnASingleLine: Empty
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AllowShortBlocksOnASingleLine: Never
+
+SortIncludes: false
+IncludeBlocks: Preserve
diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example.cpp b/meta-selftest/recipes-test/cpp/files/cpp-example.cpp
index f18911554c..af7a8c2d73 100644
--- a/meta-selftest/recipes-test/cpp/files/cpp-example.cpp
+++ b/meta-selftest/recipes-test/cpp/files/cpp-example.cpp
@@ -28,7 +28,7 @@  bool g_use_syslog = false;
 // Prints an informational message. Under systemd, stdout is already captured
 // by the journal. Otherwise, use stdout until daemonized (stdio is then
 // redirected to /dev/null), and syslog afterwards so messages aren't lost.
-void log_info(const std::string& msg)
+void log_info(const std::string &msg)
 {
 #ifndef WITH_SYSTEMD
     if (g_use_syslog) {
@@ -41,7 +41,7 @@  void log_info(const std::string& msg)
 
 } // namespace
 
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
 {
     bool endless_mode = false;
 #ifndef WITH_SYSTEMD
diff --git a/meta-selftest/recipes-test/cpp/files/daemonize.cpp b/meta-selftest/recipes-test/cpp/files/daemonize.cpp
index 7d91259bfa..e4752124f6 100644
--- a/meta-selftest/recipes-test/cpp/files/daemonize.cpp
+++ b/meta-selftest/recipes-test/cpp/files/daemonize.cpp
@@ -38,7 +38,7 @@  void daemonize()
     }
 }
 
-void write_pidfile(const std::string& path)
+void write_pidfile(const std::string &path)
 {
     std::ofstream pidfile(path, std::ios::trunc);
     pidfile << getpid() << std::endl;
diff --git a/meta-selftest/recipes-test/cpp/files/daemonize.hpp b/meta-selftest/recipes-test/cpp/files/daemonize.hpp
index 17d85d690a..d837836e02 100644
--- a/meta-selftest/recipes-test/cpp/files/daemonize.hpp
+++ b/meta-selftest/recipes-test/cpp/files/daemonize.hpp
@@ -20,7 +20,7 @@ 
 void daemonize();
 
 // Writes the current process's pid to the given path.
-void write_pidfile(const std::string& path);
+void write_pidfile(const std::string &path);
 
 // Permanently drops from root to the given group/user. Must run gid before
 // uid: once uid is dropped, the process no longer has permission to setgid.
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 e1909c3168..d8f2547e88 100644
--- a/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp
+++ b/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp
@@ -1,8 +1,8 @@ 
 /*
-* Copyright OpenEmbedded Contributors
-*
-* SPDX-License-Identifier: MIT
-*/
+ * Copyright OpenEmbedded Contributors
+ *
+ * SPDX-License-Identifier: MIT
+ */
 
 #include "cpp-example-lib.hpp"
 
@@ -13,10 +13,11 @@ 
 #define FAIL_COMPARISON_STR ""
 #endif
 
-int main() {
+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 (0 == ret_string.compare(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;