scripts/unit-test: Autodetect meson option types
This will allow us to use booleans or feature type values for examples
and tests.
Change-Id: Ib2a51ef5491db8be5fdc26ad1afca687b4fc68cb
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/scripts/unit-test.py b/scripts/unit-test.py
index 8895d11..71948d8 100755
--- a/scripts/unit-test.py
+++ b/scripts/unit-test.py
@@ -8,7 +8,7 @@
"""
from git import Repo
-from mesonbuild import optinterpreter
+from mesonbuild import coredata, optinterpreter
from urllib.parse import urljoin
from subprocess import check_call, call, CalledProcessError
import os
@@ -775,6 +775,23 @@
oi.process(options_file)
return oi.options
+ def _configure_boolean(self, val):
+ """
+ Returns the meson flag which signifies the value
+
+ True is true which requires the boolean.
+ False is false which disables the boolean.
+
+ Parameters:
+ val The value being converted
+ """
+ if val is True:
+ return 'true'
+ elif val is False:
+ return 'false'
+ else:
+ raise Exception("Bad meson boolean value")
+
def _configure_feature(self, val):
"""
Returns the meson flag which signifies the value
@@ -795,6 +812,23 @@
else:
raise Exception("Bad meson feature value")
+ def _configure_option(self, opts, key, val):
+ """
+ Returns the meson flag which signifies the value
+ based on the type of the opt
+
+ Parameters:
+ opt The meson option which we are setting
+ val The value being converted
+ """
+ if isinstance(opts[key], coredata.UserBooleanOption):
+ str_val = self._configure_boolean(val)
+ elif isinstance(opts[key], coredata.UserFeatureOption):
+ str_val = self._configure_feature(val)
+ else:
+ raise Exception('Unknown meson option type')
+ return "-D{}={}".format(key, str_val)
+
def configure(self, build_for_testing):
self.build_for_testing = build_for_testing
meson_options = {}
@@ -810,10 +844,9 @@
else:
meson_flags.append('--buildtype=debugoptimized')
if 'tests' in meson_options:
- flag_args = self._configure_feature(build_for_testing)
- meson_flags.append('-Dtests=' + flag_args)
+ meson_flags.append(self._configure_option(meson_options, 'tests', build_for_testing))
if 'examples' in meson_options:
- meson_flags.append('-Dexamples=' + str(build_for_testing).lower())
+ meson_flags.append(self._configure_option(meson_options, 'examples', build_for_testing))
if MESON_FLAGS.get(self.package) is not None:
meson_flags.extend(MESON_FLAGS.get(self.package))
try: