[igt-dev] [PATCH i-g-t v3 6/9] meson: Don't allow building with NDEBUG, ever

Lyude lyude at redhat.com
Wed Apr 24 20:20:30 UTC 2019


From: Lyude Paul <lyude at redhat.com>

Following some discussion and confusion around whether or not assert()
should be used, it seems the decision has come to "yes, sometimes". To
quote Petri Latvala on the appropriate points to use assert() in lib/:

  However, it's the thought that matters, and this is slightly going off
  on a tangent. Those uses of assert in lib/ are for places where

  1) something is fatally wrong and we need to drop everything and stop
     executing

  2) cannot use igt_assert for it. That's for places where we can say
     "you tried testing your kernel but it has a bug". The lib/ asserts
     are for "IGT has a bug", or in a couple of cases, "your IGT setup
     has a bug".

While we did come to the conclusion that we should possibly consider
introducing a new API to check for bugs with igt (and prevent further
testing if any are found), until then let's at least make sure that
assert() always works where we expect it.

So, accomplsih this by raising an error if b_ndebug isn't set to
'false'. Additionally, run the compile check in lib/check-ndebug.h to
make sure that the user does not have -DNDEBUG set in their CFLAGS,
c_args options, etc.

Signed-off-by: Lyude Paul <lyude at redhat.com>
---
 meson.build | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/meson.build b/meson.build
index e73275dd..bdf02e45 100644
--- a/meson.build
+++ b/meson.build
@@ -3,12 +3,22 @@ project('igt-gpu-tools', 'c',
         default_options: [
           'warning_level=2',
           'c_std=gnu11',
+	  'b_ndebug=false',
         ],
 	license : 'MIT',
 	meson_version : '>=0.46.0')
 
+if get_option('b_ndebug') != 'false'
+	error('Building without -Db_ndebug=false is not supported')
+endif
+
 cc = meson.get_compiler('c')
 
+# Also make sure that the user doesn't have -DNDEBUG defined in their config
+if not cc.compiles(files('lib/check-ndebug.h'), args: get_option('c_args'))
+	error('Building with NDEBUG defined is not supported')
+endif
+
 cc_args = [
 	'-Wbad-function-cast',
 	'-Wdeclaration-after-statement',
-- 
2.20.1



More information about the igt-dev mailing list