]> git.ipfire.org Git - thirdparty/git.git/commitdiff
meson: ensure correct "clar-decls.h" header is used
authorPatrick Steinhardt <ps@pks.im>
Tue, 29 Jul 2025 14:10:11 +0000 (16:10 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Jul 2025 15:50:35 +0000 (08:50 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/meson.build
t/unit-tests/unit-test.h

index d052fc3e23d2ec78199d987d21394148ff0f890b..181b5ec1e97dd9ef4e3329dae49e915e2657cf9b 100644 (file)
@@ -49,6 +49,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)
index 85e5d6a948acf9b3fffd90459f5e832238372a5f..39a0b72a05dec3c42b9842fcf84e5f94688de956 100644 (file)
@@ -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__); \