Can set compiler options with mesonconf.

pull/275/head
Jussi Pakkanen 9 years ago
parent 50663144c3
commit b197d9e279
  1. 36
      mesonconf.py
  2. 13
      mesonlib.py
  3. 18
      optinterpreter.py

@ -64,13 +64,6 @@ class Conf:
f = '%s%s %s%s' % (name, namepad, descr, descrpad)
print(f, value)
def tobool(self, thing):
if thing.lower() == 'true':
return True
if thing.lower() == 'false':
return False
raise ConfException('Value %s is not boolean (true or false).' % thing)
def set_options(self, options):
for o in options:
if '=' not in o:
@ -127,18 +120,10 @@ class Conf:
self.coredata.localedir = v
elif k in self.coredata.user_options:
tgt = self.coredata.user_options[k]
if isinstance(tgt, mesonlib.UserBooleanOption):
tgt.set_value(self.tobool(v))
elif isinstance(tgt, mesonlib.UserComboOption):
try:
tgt.set_value(v)
except coredata.MesonException:
raise ConfException('Value of %s must be one of %s.' %
(k, tgt.choices))
elif isinstance(tgt, mesonlib.UserStringOption):
tgt.set_value(v)
else:
raise ConfException('Internal error, unknown option type.')
tgt.set_value(v)
elif k in self.coredata.compiler_options:
tgt = self.coredata.compiler_options[k]
tgt.set_value(v)
elif k.endswith('linkargs'):
lang = k[:-8]
if not lang in self.coredata.external_link_args:
@ -181,6 +166,17 @@ class Conf:
for (lang, args) in self.coredata.external_link_args.items():
print(lang + 'linkargs', str(args))
print('')
okeys = sorted(self.coredata.compiler_options.keys())
if len(okeys) == 0:
print('No compiler options\n')
else:
print('Compiler options\n')
coarr = []
for k in okeys:
o = self.coredata.compiler_options[k]
coarr.append([k, o.description, o.value])
self.print_aligned(coarr)
print('')
print('Directories\n')
parr = []
parr.append(['prefix', 'Install prefix', self.coredata.prefix])
@ -193,7 +189,7 @@ class Conf:
self.print_aligned(parr)
print('')
if len(self.coredata.user_options) == 0:
print('This project does not have any options')
print('This project does not have user options')
else:
print('Project options\n')
options = self.coredata.user_options

@ -279,10 +279,17 @@ class UserBooleanOption(UserOption):
super().__init__(name, description)
self.set_value(value)
def tobool(self, thing):
if isinstance(thing, bool):
return thing
if thing.lower() == 'true':
return True
if thing.lower() == 'false':
return False
raise MesonException('Value %s is not boolean (true or false).' % thing)
def set_value(self, newvalue):
if not isinstance(newvalue, bool):
raise MesonException('Value "%s" for boolean option "%s" is not a boolean.' % (str(newvalue), self.name))
self.value = newvalue
self.value = self.tobool(newvalue)
def parse_string(self, valuestring):
if valuestring == 'false':

@ -17,6 +17,22 @@ import coredata, mesonlib
import os, re
forbidden_option_names = coredata.builtin_options
forbidden_prefixes = {'c_': True,
'cpp_': True,
'rust_': True,
'fortran_': True,
'objc_': True,
'objcpp_': True,
'vala_': True,
'csharp_': True
}
def is_invalid_name(name):
if name in forbidden_option_names:
return True
if name in forbidden_prefixes:
return True
return False
class OptionException(coredata.MesonException):
pass
@ -120,7 +136,7 @@ class OptionInterpreter:
raise OptionException('Positional argument must be a string.')
if optname_regex.search(opt_name) is not None:
raise OptionException('Option names can only contain letters, numbers or dashes.')
if opt_name in forbidden_option_names:
if is_invalid_name(opt_name):
raise OptionException('Option name %s is reserved.' % opt_name)
if self.subproject != '':
opt_name = self.subproject + ':' + opt_name

Loading…
Cancel
Save