Merge pull request #3177 from infirit/consistant_config_outpu

mconf: re-implement print_aligned fixes #3149
pull/3180/head
Jussi Pakkanen 7 years ago committed by GitHub
commit 7e52ba05ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 147
      mesonbuild/mconf.py

@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import sys, os import os
import sys
import argparse import argparse
from . import coredata, mesonlib, build from . import (coredata, mesonlib, build)
parser = argparse.ArgumentParser(prog='meson configure') parser = argparse.ArgumentParser(prog='meson configure')
@ -24,9 +25,11 @@ parser.add_argument('directory', nargs='*')
parser.add_argument('--clearcache', action='store_true', default=False, parser.add_argument('--clearcache', action='store_true', default=False,
help='Clear cached state (e.g. found dependencies)') help='Clear cached state (e.g. found dependencies)')
class ConfException(mesonlib.MesonException): class ConfException(mesonlib.MesonException):
pass pass
class Conf: class Conf:
def __init__(self, build_dir): def __init__(self, build_dir):
self.build_dir = build_dir self.build_dir = build_dir
@ -45,66 +48,50 @@ class Conf:
# are erased when Meson is executed the next time, i.e. when # are erased when Meson is executed the next time, i.e. when
# Ninja is run. # Ninja is run.
def print_aligned(self, arr): @staticmethod
def print_aligned(arr):
def make_lower_case(val):
if isinstance(val, bool):
return str(val).lower()
elif isinstance(val, list):
return [make_lower_case(i) for i in val]
else:
return str(val)
if not arr: if not arr:
return return
titles = {'name': 'Option', 'descr': 'Description', 'value': 'Current Value', 'choices': 'Possible Values'}
len_name = longest_name = len(titles['name'])
len_descr = longest_descr = len(titles['descr'])
len_value = longest_value = len(titles['value'])
longest_choices = 0 # not printed if we don't get any optional values
# calculate the max length of each
for x in arr:
name = x['name']
descr = x['descr']
value = x['value'] if isinstance(x['value'], str) else str(x['value']).lower()
choices = ''
if isinstance(x['choices'], list):
if x['choices']:
x['choices'] = [s if isinstance(s, str) else str(s).lower() for s in x['choices']]
choices = '[%s]' % ', '.join(map(str, x['choices']))
elif x['choices']:
choices = x['choices'] if isinstance(x['choices'], str) else str(x['choices']).lower()
longest_name = max(longest_name, len(name)) titles = {'name': 'Option', 'descr': 'Description', 'value': 'Current Value', 'choices': 'Possible Values'}
longest_descr = max(longest_descr, len(descr))
longest_value = max(longest_value, len(value))
longest_choices = max(longest_choices, len(choices))
# update possible non strings name_col = [titles['name'], '-' * len(titles['name'])]
x['value'] = value value_col = [titles['value'], '-' * len(titles['value'])]
x['choices'] = choices choices_col = [titles['choices'], '-' * len(titles['choices'])]
descr_col = [titles['descr'], '-' * len(titles['descr'])]
# prints header choices_found = False
namepad = ' ' * (longest_name - len_name) for opt in arr:
valuepad = ' ' * (longest_value - len_value) name_col.append(opt['name'])
if longest_choices: descr_col.append(opt['descr'])
len_choices = len(titles['choices']) if isinstance(opt['value'], list):
longest_choices = max(longest_choices, len_choices) value_col.append('[{0}]'.format(', '.join(make_lower_case(opt['value']))))
choicepad = ' ' * (longest_choices - len_choices) else:
print(' %s%s %s%s %s%s %s' % (titles['name'], namepad, titles['value'], valuepad, titles['choices'], choicepad, titles['descr'])) value_col.append(make_lower_case(opt['value']))
print(' %s%s %s%s %s%s %s' % ('-' * len_name, namepad, '-' * len_value, valuepad, '-' * len_choices, choicepad, '-' * len_descr)) if opt['choices']:
else: choices_found = True
print(' %s%s %s%s %s' % (titles['name'], namepad, titles['value'], valuepad, titles['descr'])) choices_col.append('[{0}]'.format(', '.join(make_lower_case(opt['choices']))))
print(' %s%s %s%s %s' % ('-' * len_name, namepad, '-' * len_value, valuepad, '-' * len_descr)) else:
choices_col.append('')
# print values col_widths = (max([len(i) for i in name_col], default=0),
for i in arr: max([len(i) for i in value_col], default=0),
name = i['name'] max([len(i) for i in choices_col], default=0),
descr = i['descr'] max([len(i) for i in descr_col], default=0))
value = i['value']
choices = i['choices']
namepad = ' ' * (longest_name - len(name)) for line in zip(name_col, value_col, choices_col, descr_col):
valuepad = ' ' * (longest_value - len(value)) if choices_found:
if longest_choices: print(' {0:{width[0]}} {1:{width[1]}} {2:{width[2]}} {3:{width[3]}}'.format(*line, width=col_widths))
choicespad = ' ' * (longest_choices - len(choices))
f = ' %s%s %s%s %s%s %s' % (name, namepad, value, valuepad, choices, choicespad, descr)
else: else:
f = ' %s%s %s%s %s' % (name, namepad, value, valuepad, descr) print(' {0:{width[0]}} {1:{width[1]}} {3:{width[3]}}'.format(*line, width=col_widths))
print(f)
def set_options(self, options): def set_options(self, options):
for o in options: for o in options:
@ -147,8 +134,7 @@ class Conf:
print('Core properties:') print('Core properties:')
print(' Source dir', self.build.environment.source_dir) print(' Source dir', self.build.environment.source_dir)
print(' Build dir ', self.build.environment.build_dir) print(' Build dir ', self.build.environment.build_dir)
print('') print('\nCore options:\n')
print('Core options:')
carr = [] carr = []
for key in ['buildtype', 'warning_level', 'werror', 'strip', 'unity', 'default_library']: for key in ['buildtype', 'warning_level', 'werror', 'strip', 'unity', 'default_library']:
carr.append({'name': key, carr.append({'name': key,
@ -156,48 +142,39 @@ class Conf:
'value': self.coredata.get_builtin_option(key), 'value': self.coredata.get_builtin_option(key),
'choices': coredata.get_builtin_option_choices(key)}) 'choices': coredata.get_builtin_option_choices(key)})
self.print_aligned(carr) self.print_aligned(carr)
print('') if not self.coredata.backend_options:
bekeys = sorted(self.coredata.backend_options.keys())
if not bekeys:
print(' No backend options\n') print(' No backend options\n')
else: else:
bearr = [] bearr = []
for k in bekeys: for k in sorted(self.coredata.backend_options):
o = self.coredata.backend_options[k] o = self.coredata.backend_options[k]
bearr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': ''}) bearr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': ''})
self.print_aligned(bearr) self.print_aligned(bearr)
print('') print('\nBase options:')
print('Base options:') if not self.coredata.base_options:
okeys = sorted(self.coredata.base_options.keys())
if not okeys:
print(' No base options\n') print(' No base options\n')
else: else:
coarr = [] coarr = []
for k in okeys: for k in sorted(self.coredata.base_options):
o = self.coredata.base_options[k] o = self.coredata.base_options[k]
coarr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': o.choices}) coarr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': o.choices})
self.print_aligned(coarr) self.print_aligned(coarr)
print('') print('\nCompiler arguments:')
print('Compiler arguments:')
for (lang, args) in self.coredata.external_args.items(): for (lang, args) in self.coredata.external_args.items():
print(' ' + lang + '_args', str(args)) print(' ' + lang + '_args', str(args))
print('') print('\nLinker args:')
print('Linker args:')
for (lang, args) in self.coredata.external_link_args.items(): for (lang, args) in self.coredata.external_link_args.items():
print(' ' + lang + '_link_args', str(args)) print(' ' + lang + '_link_args', str(args))
print('') print('\nCompiler options:')
print('Compiler options:') if not self.coredata.compiler_options:
okeys = sorted(self.coredata.compiler_options.keys())
if not okeys:
print(' No compiler options\n') print(' No compiler options\n')
else: else:
coarr = [] coarr = []
for k in okeys: for k in self.coredata.compiler_options:
o = self.coredata.compiler_options[k] o = self.coredata.compiler_options[k]
coarr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': ''}) coarr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': ''})
self.print_aligned(coarr) self.print_aligned(coarr)
print('') print('\nDirectories:')
print('Directories:')
parr = [] parr = []
for key in ['prefix', for key in ['prefix',
'libdir', 'libdir',
@ -218,30 +195,24 @@ class Conf:
'value': self.coredata.get_builtin_option(key), 'value': self.coredata.get_builtin_option(key),
'choices': coredata.get_builtin_option_choices(key)}) 'choices': coredata.get_builtin_option_choices(key)})
self.print_aligned(parr) self.print_aligned(parr)
print('') print('\nProject options:')
print('Project options:')
if not self.coredata.user_options: if not self.coredata.user_options:
print(' This project does not have any options') print(' This project does not have any options')
else: else:
options = self.coredata.user_options
keys = list(options.keys())
keys.sort()
optarr = [] optarr = []
for key in keys: for key in sorted(self.coredata.user_options):
opt = options[key] opt = self.coredata.user_options[key]
if (opt.choices is None) or (not opt.choices): if (opt.choices is None) or (not opt.choices):
# Zero length list or string # Zero length list or string
choices = '' choices = ''
else: else:
# A non zero length list or string, convert to string choices = opt.choices
choices = str(opt.choices)
optarr.append({'name': key, optarr.append({'name': key,
'descr': opt.description, 'descr': opt.description,
'value': opt.value, 'value': opt.value,
'choices': choices}) 'choices': choices})
self.print_aligned(optarr) self.print_aligned(optarr)
print('') print('\nTesting options:')
print('Testing options:')
tarr = [] tarr = []
for key in ['stdsplit', 'errorlogs']: for key in ['stdsplit', 'errorlogs']:
tarr.append({'name': key, tarr.append({'name': key,
@ -250,6 +221,7 @@ class Conf:
'choices': coredata.get_builtin_option_choices(key)}) 'choices': coredata.get_builtin_option_choices(key)})
self.print_aligned(tarr) self.print_aligned(tarr)
def run(args): def run(args):
args = mesonlib.expand_arguments(args) args = mesonlib.expand_arguments(args)
if not args: if not args:
@ -282,5 +254,6 @@ def run(args):
return 1 return 1
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(run(sys.argv[1:])) sys.exit(run(sys.argv[1:]))

Loading…
Cancel
Save