Merge pull request #3485 from xclaesse/warnlevel

--warnlevel got renamed to --warning-level
pull/3503/head
Jussi Pakkanen 7 years ago committed by GitHub
commit d52f892de9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      mesonbuild/coredata.py
  2. 2
      mesonbuild/environment.py
  3. 21
      mesonbuild/mconf.py
  4. 11
      mesonbuild/mesonmain.py
  5. 54
      run_unittests.py
  6. 3
      test cases/unit/30 command line/meson.build

@ -390,12 +390,6 @@ def get_builtin_option_action(optname):
return 'store_true' return 'store_true'
return None return None
def get_builtin_option_destination(optname):
optname = optname.replace('-', '_')
if optname == 'warnlevel':
return 'warning_level'
return optname
def get_builtin_option_default(optname, prefix='', noneIfSuppress=False): def get_builtin_option_default(optname, prefix='', noneIfSuppress=False):
if is_builtin_option(optname): if is_builtin_option(optname):
o = builtin_options[optname] o = builtin_options[optname]
@ -415,28 +409,64 @@ def get_builtin_option_default(optname, prefix='', noneIfSuppress=False):
else: else:
raise RuntimeError('Tried to get the default value for an unknown builtin option \'%s\'.' % optname) raise RuntimeError('Tried to get the default value for an unknown builtin option \'%s\'.' % optname)
def get_builtin_option_cmdline_name(name):
if name == 'warning_level':
return '--warnlevel'
else:
return '--' + name.replace('_', '-')
def add_builtin_argument(p, name): def add_builtin_argument(p, name):
kwargs = {} kwargs = {}
k = get_builtin_option_destination(name) c = get_builtin_option_choices(name)
c = get_builtin_option_choices(k) b = get_builtin_option_action(name)
b = get_builtin_option_action(k) h = get_builtin_option_description(name)
h = get_builtin_option_description(k)
if not b: if not b:
h = h.rstrip('.') + ' (default: %s).' % get_builtin_option_default(k) h = h.rstrip('.') + ' (default: %s).' % get_builtin_option_default(name)
else: else:
kwargs['action'] = b kwargs['action'] = b
if c and not b: if c and not b:
kwargs['choices'] = c kwargs['choices'] = c
default = get_builtin_option_default(k, noneIfSuppress=True) default = get_builtin_option_default(name, noneIfSuppress=True)
if default is not None: if default is not None:
kwargs['default'] = default kwargs['default'] = default
else: else:
kwargs['default'] = argparse.SUPPRESS kwargs['default'] = argparse.SUPPRESS
p.add_argument('--' + name.replace('_', '-'), help=h, **kwargs) kwargs['dest'] = name
cmdline_name = get_builtin_option_cmdline_name(name)
p.add_argument(cmdline_name, help=h, **kwargs)
def register_builtin_arguments(parser): def register_builtin_arguments(parser):
for n in builtin_options: for n in builtin_options:
add_builtin_argument(parser, n) add_builtin_argument(parser, n)
parser.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option",
help='Set the value of an option, can be used several times to set multiple options.')
def filter_builtin_options(args, original_args):
"""Filter out any builtin arguments passed as -- instead of -D.
Error if an argument is passed with -- and -D
"""
for name in builtin_options:
# Check if user passed --option. Cannot use hasattr(args, name) here
# because they are all set with default value if user didn't pass it.
cmdline_name = get_builtin_option_cmdline_name(name)
has_dashdash = any([a.startswith(cmdline_name) for a in original_args])
# Chekc if user passed -Doption=value
has_dashd = any([a.startswith('{}='.format(name)) for a in args.projectoptions])
# Passing both is ambigous, abort
if has_dashdash and has_dashd:
raise MesonException(
'Got argument {0} as both -D{0} and {1}. Pick one.'.format(name, cmdline_name))
# Pretend --option never existed
if has_dashdash:
args.projectoptions.append('{}={}'.format(name, getattr(args, name)))
if hasattr(args, name):
delattr(args, name)
builtin_options = { builtin_options = {
'buildtype': [UserComboOption, 'Build type to use.', ['plain', 'debug', 'debugoptimized', 'release', 'minsize'], 'debug'], 'buildtype': [UserComboOption, 'Build type to use.', ['plain', 'debug', 'debugoptimized', 'release', 'minsize'], 'debug'],

@ -373,7 +373,7 @@ class Environment:
return is_library(fname) return is_library(fname)
def had_argument_for(self, option): def had_argument_for(self, option):
trial1 = '--' + option trial1 = coredata.get_builtin_option_cmdline_name(option)
trial2 = '-D' + option trial2 = '-D' + option
previous_is_plaind = False previous_is_plaind = False
for i in self.original_cmd_line_args: for i in self.original_cmd_line_args:

@ -21,27 +21,12 @@ def buildparser():
parser = argparse.ArgumentParser(prog='meson configure') parser = argparse.ArgumentParser(prog='meson configure')
coredata.register_builtin_arguments(parser) coredata.register_builtin_arguments(parser)
parser.add_argument('-D', action='append', default=[], dest='sets',
help='Set an option to the given value.')
parser.add_argument('directory', nargs='*') 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)')
return parser return parser
def filter_builtin_options(args, original_args):
"""Filter out any args passed with -- instead of -D."""
for arg in original_args:
if not arg.startswith('--') or arg == '--clearcache':
continue
name = arg.lstrip('--').split('=', 1)[0]
if any([a.startswith(name + '=') for a in args.sets]):
raise mesonlib.MesonException(
'Got argument {0} as both -D{0} and --{0}. Pick one.'.format(name))
args.sets.append('{}={}'.format(name, getattr(args, name)))
delattr(args, name)
class ConfException(mesonlib.MesonException): class ConfException(mesonlib.MesonException):
pass pass
@ -243,7 +228,7 @@ def run(args):
if not args: if not args:
args = [os.getcwd()] args = [os.getcwd()]
options = buildparser().parse_args(args) options = buildparser().parse_args(args)
filter_builtin_options(options, args) coredata.filter_builtin_options(options, args)
if len(options.directory) > 1: if len(options.directory) > 1:
print('%s <build directory>' % args[0]) print('%s <build directory>' % args[0])
print('If you omit the build directory, the current directory is substituted.') print('If you omit the build directory, the current directory is substituted.')
@ -255,8 +240,8 @@ def run(args):
try: try:
c = Conf(builddir) c = Conf(builddir)
save = False save = False
if len(options.sets) > 0: if len(options.projectoptions) > 0:
c.set_options(options.sets) c.set_options(options.projectoptions)
save = True save = True
elif options.clearcache: elif options.clearcache:
c.clear_cache() c.clear_cache()

@ -32,8 +32,6 @@ def create_parser():
coredata.register_builtin_arguments(p) coredata.register_builtin_arguments(p)
p.add_argument('--cross-file', default=None, p.add_argument('--cross-file', default=None,
help='File describing cross compilation environment.') help='File describing cross compilation environment.')
p.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option",
help='Set the value of an option, can be used several times to set multiple options.')
p.add_argument('-v', '--version', action='version', p.add_argument('-v', '--version', action='version',
version=coredata.version) version=coredata.version)
# See the mesonlib.WrapMode enum for documentation # See the mesonlib.WrapMode enum for documentation
@ -63,11 +61,12 @@ def filter_builtin_options(args, original_args):
if meson_opts: if meson_opts:
for arg in meson_opts: for arg in meson_opts:
value = arguments[arg] value = arguments[arg]
if any([a.startswith('--{}'.format(arg)) for a in original_args]): cmdline_name = coredata.get_builtin_option_cmdline_name(arg)
if any([a.startswith(cmdline_name) for a in original_args]):
raise MesonException( raise MesonException(
'Argument "{0}" passed as both --{0} and -D{0}, but only ' 'Argument "{0}" passed as both {1} and -D{0}, but only '
'one is allowed'.format(arg)) 'one is allowed'.format(arg, cmdline_name))
setattr(args, coredata.get_builtin_option_destination(arg), value) setattr(args, arg, value)
# Remove the builtin option from the project args values # Remove the builtin option from the project args values
args.projectoptions.remove('{}={}'.format(arg, value)) args.projectoptions.remove('{}={}'.format(arg, value))

@ -2060,10 +2060,8 @@ recommended as it can lead to undefined behaviour on some platforms''')
raise Exception('Missing {} value?'.format(arg)) raise Exception('Missing {} value?'.format(arg))
def test_same_dash_option_twice_configure(self): def test_same_dash_option_twice_configure(self):
with self.assertRaises(subprocess.CalledProcessError) as e: self._test_same_option_twice_configure(
self._test_same_option_twice_configure( 'bindir', ['--bindir=foo', '--bindir=bar'])
'bindir', ['--bindir=foo', '--bindir=bar'])
self.assertIn('Pick one.', e.stderr)
def test_same_d_option_twice_configure(self): def test_same_d_option_twice_configure(self):
self._test_same_option_twice_configure( self._test_same_option_twice_configure(
@ -2073,6 +2071,54 @@ recommended as it can lead to undefined behaviour on some platforms''')
self._test_same_option_twice_configure( self._test_same_option_twice_configure(
'one', ['-Done=foo', '-Done=bar']) 'one', ['-Done=foo', '-Done=bar'])
def test_command_line(self):
testdir = os.path.join(self.unit_test_dir, '30 command line')
# Verify default values when passing no args
self.init(testdir)
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['default_library'].value, 'static')
self.assertEqual(obj.builtins['warning_level'].value, '1')
self.wipe()
# warning_level is special, it's --warnlevel instead of --warning-level
# for historical reasons
self.init(testdir, extra_args=['--warnlevel=2'])
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '2')
self.setconf('--warnlevel=3')
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '3')
self.wipe()
# But when using -D syntax, it should be 'warning_level'
self.init(testdir, extra_args=['-Dwarning_level=2'])
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '2')
self.setconf('-Dwarning_level=3')
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '3')
self.wipe()
# Mixing --option and -Doption is forbidden
with self.assertRaises(subprocess.CalledProcessError) as e:
self.init(testdir, extra_args=['--warnlevel=1', '-Dwarning_level=3'])
self.assertNotEqual(0, e.returncode)
self.assertIn('passed as both', e.stderr)
with self.assertRaises(subprocess.CalledProcessError) as e:
self.setconf('--warnlevel=1', '-Dwarning_level=3')
self.assertNotEqual(0, e.returncode)
self.assertIn('passed as both', e.stderr)
self.wipe()
# --default-library should override default value from project()
self.init(testdir, extra_args=['--default-library=both'])
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['default_library'].value, 'both')
self.setconf('--default-library=shared')
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['default_library'].value, 'shared')
self.wipe()
class FailureTests(BasePlatformTests): class FailureTests(BasePlatformTests):

@ -0,0 +1,3 @@
project('command line test', 'c',
default_options : ['default_library=static']
)
Loading…
Cancel
Save