]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
meson: Add support for generating code coverage data in clang format
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 20 May 2025 07:28:40 +0000 (09:28 +0200)
committerromeroalx <alexis.romero@open-xchange.com>
Thu, 5 Jun 2025 13:25:37 +0000 (15:25 +0200)
meson/code-coverage/meson.build
meson_options.txt
pdns/dnsdistdist/meson_options.txt
pdns/recursordist/meson_options.txt
tasks.py

index 221b3072776b91b9fbf7b8086c2306896f3f2220..367a4d9d62372424f01afa6d84a19e82828afd79 100644 (file)
@@ -1,6 +1,7 @@
 coverage = get_option('b_coverage')
+clang_coverage = get_option('clang-coverage-format')
 
-if coverage
+if coverage or clang_coverage
   add_project_arguments('-DCOVERAGE', language: ['c', 'cpp'])
 
   if get_option('buildtype') != 'debug'
@@ -10,6 +11,21 @@ if coverage
   if cxx.has_argument('-U_FORTIFY_SOURCE')
     add_project_arguments('-U_FORTIFY_SOURCE', language: ['c', 'cpp'])
   endif
+
 endif
 
-summary('Code Coverage', coverage, bool_yn: true, section: 'Configuration')
+if coverage
+  if get_option('clang-coverage-format')
+    error('b_coverage and clang-coverage-format cannot be enabled at the same time')
+  endif
+  summary('Code Coverage', coverage, bool_yn: true, section: 'Configuration')
+else
+  if get_option('clang-coverage-format')
+    # let's see if the clang++ specific format is supported,
+    # as it has a much lower overhead and is more accurate,
+    # see https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
+    add_project_arguments('-DCLANG_COVERAGE', '-fprofile-instr-generate', '-fcoverage-mapping', language: ['c', 'cpp'])
+    add_project_link_arguments('-fprofile-instr-generate', '-fcoverage-mapping', language: ['c', 'cpp'])
+    summary('Code Coverage (clang format)', true, bool_yn: true, section: 'Configuration')
+  endif
+endif
index afcf7a7a666b6363d75bffbb6dc45d6dc0b10911..e9b61ae147298b5d2738118bad4e31d64c47e673 100644 (file)
@@ -42,3 +42,4 @@ option('systemd-service-user', type: 'string', value: 'pdns', description: 'Syst
 option('systemd-service-group', type: 'string', value: 'pdns', description: 'Systemd service group (setgid and unit file; group is not created)')
 option('auto-var-init', type: 'combo', value: 'disabled', choices: ['zero', 'pattern', 'disabled'], description: 'Enable initialization of automatic variables')
 option('malloc-trace', type: 'boolean', value: false, description: 'Enable malloc-trace')
+option('clang-coverage-format', type: 'boolean', value: false, description: 'Whether to generate coverage data in clang format')
index 5635782b2c014d810859646ff62469841cf16555..3c95c5d8af489092d991f7feb0c94523ef6ddd63 100644 (file)
@@ -39,3 +39,4 @@ option('ebpf', type: 'feature', value: 'auto', description: 'Enable eBPF support
 option('fuzzer_ldflags', type: 'string', value: '', description: 'Linker flags used for the fuzzing targets (a path to the libFuzzer static library, for example)')
 option('yaml', type: 'feature', value: 'disabled', description: 'Enable YAML configuration')
 option('man-pages', type: 'boolean', value: true, description: 'Generate man pages')
+option('clang-coverage-format', type: 'boolean', value: false, description: 'Whether to generate coverage data in clang format')
index 2a88e555f564b007d35ada79390b70232a88f794..e1f6d7545e17600884a2378d9e3eb26e3b12befc 100644 (file)
@@ -23,3 +23,4 @@ option('dnstap', type: 'feature', value: 'auto', description: 'Enable DNSTAP sup
 option('libcurl', type: 'feature', value: 'auto', description: 'Enable Curl support')
 option('nod', type: 'feature', value: 'enabled', description: 'Enable Newly Observed Domains')
 option('libcap', type: 'feature', value: 'auto', description: 'Enable libcap for capabilities handling')
+option('clang-coverage-format', type: 'boolean', value: false, description: 'Whether to generate coverage data in clang format')
index 5346c07c24273a27e92facfebcda39079ce1a228..6347e91050853d75632b20054a5454179039233a 100644 (file)
--- a/tasks.py
+++ b/tasks.py
@@ -222,7 +222,7 @@ def is_coverage_enabled():
 
 def get_coverage(meson=False):
     if meson:
-        return '-D b_coverage=true' if is_coverage_enabled() else ''
+        return '-Dclang-coverage-format=true' if is_coverage_enabled() else ''
     return '--enable-coverage=clang' if is_coverage_enabled() else ''
 
 @task