git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] meson: add rule to run 'git clang-format'

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jun 25, 2025, 16:43 UTC
Message-ID
<20250625-525-make-clang-format-more-robust-v1-4-67a49ecc2fd5@gmail.com>
In-Reply-To
<20250625-525-make-clang-format-more-robust-v1-0-67a49ecc2fd5@gmail.com>

The Makefile has a 'style' rule to run 'git clang-format'. While Meson intrinsically supports a 'clang-format' target, which can be run when using the ninja backend by running 'ninja clang-format', this runs the formatting on all existing files.

Our Meson build doesn't yet support a way to run 'git clang-format', which runs the formatter between the working directory and commit provided. Add a new 'style' target to Meson to mimic the target in the Makefile.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 meson.build | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/meson.build b/meson.build
index 7fea4a34d6..578db26df2 100644
--- a/meson.build
+++ b/meson.build
@@ -2144,6 +2144,18 @@ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc'
   alias_target('check-headers', hdr_check)
 endif
 
+clang_format = find_program('clang-format', required: false)
+if clang_format.found()
+  run_target('style',
+    command: [
+      'git', 'clang-format',
+      '--style', 'file',
+      '--diff',
+      '--extensions', 'c,h'
+    ]
+  )
+endif
+
 foreach key, value : {
   'DIFF': diff.full_path(),
   'GIT_SOURCE_DIR': meson.project_source_root(),
-- 
2.49.0
Previous: Karthik NayakNext: Justin Tobler
Message 13 of 36 in “clang-format: modify rules to reduce false-positives”
  1. 0/4 clang-format: modify rules to reduce false-positivesKarthik Nayak, Jun 25, 2025
  2. 1/4 editorconfig: set maximum line length to 120 charactersKarthik Nayak, Jun 25, 2025
  3. Junio C HamanoJun 25, 2025
  4. Karthik NayakJun 26, 2025
  5. Junio C HamanoJun 26, 2025
  6. Karthik NayakJun 27, 2025
  7. Justin ToblerJun 26, 2025
  8. Karthik NayakJun 27, 2025
  9. Justin ToblerJun 27, 2025
  10. Karthik NayakJun 30, 2025
  11. 2/4 clang-format: set 'ColumnLimit' to 0Karthik Nayak, Jun 25, 2025
  12. 3/4 clang-format: add 'RemoveBracesLLVM' to the main configKarthik Nayak, Jun 25, 2025
  13. 4/4 meson: add rule to run 'git clang-format'Karthik Nayak, Jun 25, 2025
  14. Justin ToblerJun 26, 2025
  15. Karthik NayakJun 27, 2025
  16. Junio C HamanoJun 27, 2025
  17. Karthik NayakJun 30, 2025
  18. Junio C HamanoJun 30, 2025
  19. 0/3 clang-format: modify rules to reduce false-positivesKarthik Nayak, Jun 30, 2025
  20. 1/3 clang-format: set 'ColumnLimit' to 0Karthik Nayak, Jun 30, 2025
  21. 2/3 clang-format: add 'RemoveBracesLLVM' to the main configKarthik Nayak, Jun 30, 2025
  22. 3/3 meson: add rule to run 'git clang-format'Karthik Nayak, Jun 30, 2025
  23. Patrick SteinhardtJul 1, 2025
  24. Karthik NayakJul 1, 2025
  25. Junio C HamanoJul 1, 2025
  26. Toon ClaesJul 1, 2025
  27. Karthik NayakJul 1, 2025
  28. Patrick SteinhardtJul 2, 2025
  29. Junio C HamanoJun 30, 2025
  30. Toon ClaesJul 1, 2025
  31. Karthik NayakJul 1, 2025
  32. Junio C HamanoJul 1, 2025
  33. 0/3 clang-format: modify rules to reduce false-positivesKarthik Nayak, Jul 2, 2025
  34. 1/3 clang-format: set 'ColumnLimit' to 0Karthik Nayak, Jul 2, 2025
  35. 2/3 clang-format: add 'RemoveBracesLLVM' to the main configKarthik Nayak, Jul 2, 2025
  36. 3/3 meson: add rule to run 'git clang-format'Karthik Nayak, Jul 2, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.