Bug 1257326 - Provide reasons for implied options when the caller provides an immediate value. r=glandium

MozReview-Commit-ID: A8IDPuwPqiP
This commit is contained in:
Chris Manchester 2016-05-12 11:55:58 -07:00
Родитель 4f42fe999c
Коммит 2f6600bc7f
3 изменённых файлов: 70 добавлений и 2 удалений

Просмотреть файл

@ -345,8 +345,9 @@ class ConfigureSandbox(dict):
value, option_string = self._helper.handle(option)
except ConflictingOptionError as e:
reason = implied[e.arg].reason
reason = self._raw_options.get(reason) or reason.option
reason = reason.split('=', 1)[0]
if isinstance(reason, Option):
reason = self._raw_options.get(reason) or reason.option
reason = reason.split('=', 1)[0]
raise InvalidOptionError(
"'%s' implied by '%s' conflicts with '%s' from the %s"
% (e.arg, reason, e.old_arg, e.old_origin))
@ -674,6 +675,12 @@ class ConfigureSandbox(dict):
if len(possible_reasons) == 1:
if isinstance(possible_reasons[0], Option):
reason = possible_reasons[0]
if not reason and (isinstance(value, (bool, tuple)) or
isinstance(value, types.StringTypes)):
# A reason can be provided automatically when imply_option
# is called with an immediate value.
_, filename, line, _, _, _ = inspect.stack()[1]
reason = "imply_option at %s:%s" % (filename, line)
if not reason:
raise ConfigureError(

Просмотреть файл

@ -0,0 +1,32 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
imply_option('--enable-foo', True)
option('--enable-foo', help='enable foo')
@depends('--enable-foo', '--help')
def foo(value, help):
if value:
return True
imply_option('--enable-bar', ('foo', 'bar'))
option('--enable-bar', nargs='*', help='enable bar')
@depends('--enable-bar')
def bar(value):
if value:
return value
imply_option('--enable-baz', 'BAZ')
option('--enable-baz', nargs=1, help='enable baz')
@depends('--enable-baz')
def bar(value):
if value:
return value

Просмотреть файл

@ -580,6 +580,35 @@ class TestConfigure(unittest.TestCase):
"Cannot infer what implies '--enable-bar'. Please add a `reason` "
"to the `imply_option` call.")
def test_imply_option_immediate_value(self):
def get_config(*args):
return self.get_config(
*args, configure='imply_option/imm.configure')
config = get_config(['--help'])
self.assertEquals(config, {})
config = get_config([])
self.assertEquals(config, {})
config_path = mozpath.abspath(
mozpath.join(test_data_path, 'imply_option', 'imm.configure'))
with self.assertRaisesRegexp(InvalidOptionError,
"--enable-foo' implied by 'imply_option at %s:7' conflicts with "
"'--disable-foo' from the command-line" % config_path):
get_config(['--disable-foo'])
with self.assertRaisesRegexp(InvalidOptionError,
"--enable-bar=foo,bar' implied by 'imply_option at %s:16' conflicts"
" with '--enable-bar=a,b,c' from the command-line" % config_path):
get_config(['--enable-bar=a,b,c'])
with self.assertRaisesRegexp(InvalidOptionError,
"--enable-baz=BAZ' implied by 'imply_option at %s:25' conflicts"
" with '--enable-baz=QUUX' from the command-line" % config_path):
get_config(['--enable-baz=QUUX'])
def test_imply_option_failures(self):
with self.assertRaises(ConfigureError) as e:
with self.moz_configure('''