diff options
-rw-r--r-- | coredata.py | 15 | ||||
-rwxr-xr-x | mesonconf.py | 62 |
2 files changed, 19 insertions, 58 deletions
diff --git a/coredata.py b/coredata.py index 86a64f9..fcfd745 100644 --- a/coredata.py +++ b/coredata.py @@ -57,9 +57,17 @@ class UserStringOption(UserOption): super().__init__(name, description) self.set_value(value) - def set_value(self, newvalue): - if not isinstance(newvalue, str): + def validate(self, value): + if not isinstance(value, str): raise MesonException('Value "%s" for string option "%s" is not a string.' % (str(newvalue), self.name)) + if self.name == 'prefix' and not os.path.isabs(value): + raise MesonException('Prefix option must be an absolute path.') + if self.name in ('libdir', 'bindir', 'includedir', 'datadir', 'mandir', 'localedir') \ + and os.path.isabs(value): + raise MesonException('Option %s must not be an absolute path.' % self.name) + + def set_value(self, newvalue): + self.validate(newvalue) self.value = newvalue class UserBooleanOption(UserOption): @@ -179,6 +187,9 @@ class CoreData(): else: raise RuntimeError('Tried to set unknown builtin option %s' % optname) + def is_builtin_option(self, optname): + return optname in self.builtin_options + def load(filename): obj = pickle.load(open(filename, 'rb')) if not isinstance(obj, CoreData): diff --git a/mesonconf.py b/mesonconf.py index 6fb45ae..14fd8f4 100755 --- a/mesonconf.py +++ b/mesonconf.py @@ -26,7 +26,7 @@ parser.add_argument('-D', action='append', default=[], dest='sets', help='Set an option to the given value.') parser.add_argument('directory', nargs='*') -class ConfException(Exception): +class ConfException(coredata.MesonException): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -69,58 +69,8 @@ class Conf: if '=' not in o: raise ConfException('Value "%s" not of type "a=b".' % o) (k, v) = o.split('=', 1) - if k == 'buildtype': - if v not in build_types: - raise ConfException('Invalid build type %s.' % v) - self.coredata.set_builtin_option('buildtype', v) - elif k == 'layout': - if v not in layouts: - raise ConfException('Invalid layout type %s.' % v) - self.coredata.set_builtin_option('layout', v) - elif k == 'warnlevel': - if not v in warning_levels: - raise ConfException('Invalid warning level %s.' % v) - self.coredata.set_builtin_option('warning_level', v) - elif k == 'strip': - self.coredata.set_builtin_option('strip', self.tobool(v)) - elif k == 'coverage': - self.coredata.set_builtin_option('coverage', self.tobool(v)) - elif k == 'pch': - self.coredata.set_builtin_option('use_pch', self.tobool(v)) - elif k == 'unity': - self.coredata.set_builtin_option('unity', self.tobool(v)) - elif k == 'default_library': - if v != 'shared' and v != 'static': - raise ConfException('Invalid value for default_library') - self.coredata.set_builtin_option('default_library', v) - elif k == 'prefix': - if not os.path.isabs(v): - raise ConfException('Install prefix %s is not an absolute path.' % v) - self.coredata.set_builtin_option('prefix', v) - elif k == 'libdir': - if os.path.isabs(v): - raise ConfException('Library dir %s must not be an absolute path.' % v) - self.coredata.set_builtin_option('libdir', v) - elif k == 'bindir': - if os.path.isabs(v): - raise ConfException('Binary dir %s must not be an absolute path.' % v) - self.coredata.set_builtin_option('bindir',v) - elif k == 'includedir': - if os.path.isabs(v): - raise ConfException('Include dir %s must not be an absolute path.' % v) - self.coredata.set_builtin_option('includedir', v) - elif k == 'datadir': - if os.path.isabs(v): - raise ConfException('Data dir %s must not be an absolute path.' % v) - self.coredata.set_builtin_option('datadir', v) - elif k == 'mandir': - if os.path.isabs(v): - raise ConfException('Man dir %s must not be an absolute path.' % v) - self.coredata.set_builtin_option('mandir', v) - elif k == 'localedir': - if os.path.isabs(v): - raise ConfException('Locale dir %s must not be an absolute path.' % v) - self.coredata.set_builtin_option('localedir', v) + if self.coredata.is_builtin_option(k): + self.coredata.set_builtin_option(k, v) elif k in self.coredata.user_options: tgt = self.coredata.user_options[k] tgt.set_value(v) @@ -154,10 +104,10 @@ class Conf: print('Core options\n') carr = [] carr.append(['buildtype', 'Build type', self.coredata.get_builtin_option('buildtype')]) - carr.append(['warnlevel', 'Warning level', self.coredata.get_builtin_option('warning_level')]) + carr.append(['warning_level', 'Warning level', self.coredata.get_builtin_option('warning_level')]) carr.append(['strip', 'Strip on install', self.coredata.get_builtin_option('strip')]) carr.append(['coverage', 'Coverage report', self.coredata.get_builtin_option('coverage')]) - carr.append(['pch', 'Precompiled headers', self.coredata.get_builtin_option('use_pch')]) + carr.append(['use_pch', 'Precompiled headers', self.coredata.get_builtin_option('use_pch')]) carr.append(['unity', 'Unity build', self.coredata.get_builtin_option('unity')]) carr.append(['default_library', 'Default library type', self.coredata.get_builtin_option('default_library')]) self.print_aligned(carr) @@ -222,7 +172,7 @@ if __name__ == '__main__': c.save() else: c.print_conf() - except ConfException as e: + except coredata.MesonException as e: print('Meson configurator encountered an error:\n') print(e) |