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

[PATCH] meson: ensure correct "clar-decls.h" header is used

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 29, 2025, 14:10 UTC
Message-ID
<20250729-b4-pks-meson-unit-tests-stale-decls-v1-1-4a7770c84307@pks.im>

The "clar-decls.h" header gets generated by us to extract prototypes of unit test functions from our clar-based tests. This generated file is then written into "t/unit-tests/" and included via "unit-test.h". The intent of all this is that we can keep "-Wmissing-prototype" warnings enabled. If we had that warning disabled, it would be easy to miss in case any of the non-static functions had a typo in its name and thus wasn't picked up by our test case extractor.

Including the file directly has a big downside though: if a source tree was built both with our Makefile and with Meson, then the Meson build would include the "clar-decls.h" file from our Makefile. And if those are out of sync we get compiler errors.

We already fixed a similar issue in 4771501c0a (meson: ensure correct version-def.h is used, 2025-01-14). Let's do the same and pass the absolute path to "clar-decls.h" via a preprocessor define.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/meson.build            | 3 +++
 t/unit-tests/unit-test.h | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/t/meson.build b/t/meson.build
index 660d780dcc6..9d476011347 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -50,6 +50,9 @@ clar_sources += custom_target(
 
 clar_unit_tests = executable('unit-tests',
   sources: clar_sources + clar_test_suites,
+  c_args: [
+    '-DGIT_CLAR_DECLS_H="' + clar_decls_h.full_path() + '"',
+  ],
   dependencies: [libgit_commonmain],
 )
 test('unit-tests', clar_unit_tests, kwargs: test_kwargs)
diff --git a/t/unit-tests/unit-test.h b/t/unit-tests/unit-test.h
index 85e5d6a948a..39a0b72a05d 100644
--- a/t/unit-tests/unit-test.h
+++ b/t/unit-tests/unit-test.h
@@ -1,8 +1,13 @@
 #include "git-compat-util.h"
 #include "clar/clar.h"
-#include "clar-decls.h"
 #include "strbuf.h"
 
+#ifndef GIT_CLAR_DECLS_H
+# include "clar-decls.h"
+#else
+# include GIT_CLAR_DECLS_H
+#endif
+
 #define cl_failf(fmt, ...) do { \
 	char desc[4096]; \
 	snprintf(desc, sizeof(desc), fmt, __VA_ARGS__); \

---
base-commit: e813a0200a7121b97fec535f0d0b460b0a33356c
change-id: 20250729-b4-pks-meson-unit-tests-stale-decls-50bb4743eac1
Message 1 of 1 in “meson: ensure correct "clar-decls.h" header is used”
  1. meson: ensure correct "clar-decls.h" header is usedPatrick Steinhardt, Jul 29, 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.