Bug 1563158 - Properly handle imply_option dependency loops when `when` is involved. r=chmanchester

This is an extension of the relaxation added in bug 1529799.

Differential Revision: https://phabricator.services.mozilla.com/D36716

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Hommey 2019-07-09 22:04:01 +00:00
Родитель 89f408ffff
Коммит 20ee1b2284
2 изменённых файлов: 53 добавлений и 0 удалений

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

@ -468,6 +468,9 @@ class ConfigureSandbox(dict):
implied_option.caller[2]))
# If the option is known, check that the implied value doesn't
# conflict with what value was attributed to the option.
if (implied_option.when and
not self._value_for(implied_option.when)):
continue
option_value = self._value_for_option(option)
if value != option_value:
reason = implied_option.reason

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

@ -789,6 +789,56 @@ class TestConfigure(unittest.TestCase):
'QUX': NegativeOptionValue(),
})
config_path = mozpath.abspath(
mozpath.join(test_data_path, 'moz.configure'))
# Same test as above, but using `when` in the `imply_option`.
with self.moz_configure('''
option('--with-foo', help='foo')
@depends('--with-foo')
def qux_default(foo):
return bool(foo)
option('--with-qux', default=qux_default, help='qux')
imply_option('--with-foo', True, when='--with-qux')
set_config('FOO', depends('--with-foo')(lambda x: x))
set_config('QUX', depends('--with-qux')(lambda x: x))
'''):
config = self.get_config()
self.assertEquals(config, {
'FOO': NegativeOptionValue(),
'QUX': NegativeOptionValue(),
})
config = self.get_config(['--with-foo'])
self.assertEquals(config, {
'FOO': PositiveOptionValue(),
'QUX': PositiveOptionValue(),
})
with self.assertRaises(InvalidOptionError) as e:
config = self.get_config(['--with-qux'])
self.assertEquals(e.exception.message,
"'--with-foo' implied by 'imply_option at %s:10' conflicts "
"with '--without-foo' from the default" % config_path)
with self.assertRaises(InvalidOptionError) as e:
config = self.get_config(['--without-foo', '--with-qux'])
self.assertEquals(e.exception.message,
"'--with-foo' implied by 'imply_option at %s:10' conflicts "
"with '--without-foo' from the command-line" % config_path)
config = self.get_config(['--without-qux'])
self.assertEquals(config, {
'FOO': NegativeOptionValue(),
'QUX': NegativeOptionValue(),
})
def test_imply_option_recursion(self):
config_path = mozpath.abspath(
mozpath.join(test_data_path, 'moz.configure'))