зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1313306 - Allow @depends(when=something) without additional dependencies. r=chmanchester
Also allow when=True/False to avoid the chicken-egg problem of using a generic `when` to use in replacement of @depends('--help') for things like @dependable. --HG-- extra : rebase_source : f1571a5b904efb66a361b90f3b7e1edbaa75772e
This commit is contained in:
Родитель
18c9034b4a
Коммит
c35a6888f9
|
@ -284,6 +284,10 @@ class ConfigureSandbox(dict):
|
|||
self._help_option = self.option_impl('--help',
|
||||
help='print this message')
|
||||
self._seen.add(self._help_option)
|
||||
|
||||
self._always = DependsFunction(self, lambda: True, [])
|
||||
self._never = DependsFunction(self, lambda: False, [])
|
||||
|
||||
if self._value_for(self._help_option):
|
||||
self._help = HelpFormatter(argv[0])
|
||||
self._help.add(self._help_option)
|
||||
|
@ -494,7 +498,11 @@ class ConfigureSandbox(dict):
|
|||
return arg
|
||||
|
||||
def _normalize_when(self, when, callee_name):
|
||||
if when is not None:
|
||||
if when is True:
|
||||
when = self._always
|
||||
elif when is False:
|
||||
when = self._never
|
||||
elif when is not None:
|
||||
when = self._dependency(when, callee_name, 'when')
|
||||
|
||||
if self._default_conditions:
|
||||
|
@ -571,9 +579,6 @@ class ConfigureSandbox(dict):
|
|||
for its execution. This different global namespace exposes a limited
|
||||
set of functions from os.path.
|
||||
'''
|
||||
if not args:
|
||||
raise ConfigureError('@depends needs at least one argument')
|
||||
|
||||
for k in kwargs:
|
||||
if k != 'when':
|
||||
raise TypeError(
|
||||
|
@ -582,6 +587,9 @@ class ConfigureSandbox(dict):
|
|||
|
||||
when = self._normalize_when(kwargs.get('when'), '@depends')
|
||||
|
||||
if not when and not args:
|
||||
raise ConfigureError('@depends needs at least one argument')
|
||||
|
||||
dependencies = tuple(self._dependency(arg, '@depends') for arg in args)
|
||||
|
||||
conditions = [
|
||||
|
|
|
@ -34,7 +34,8 @@ class LintSandbox(ConfigureSandbox):
|
|||
if isinstance(obj, CombinedDependsFunction):
|
||||
return False
|
||||
if isinstance(obj, DependsFunction):
|
||||
if self._help_option in obj.dependencies:
|
||||
if (self._help_option in obj.dependencies or
|
||||
obj in (self._always, self._never)):
|
||||
return False
|
||||
func = self._wrapped[obj.func]
|
||||
# We allow missing --help dependencies for functions that:
|
||||
|
|
|
@ -405,7 +405,7 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
|
||||
with self.assertRaises(ConfigureError) as e:
|
||||
self.get_result(
|
||||
'foo = depends("--help")(lambda h: ("a", "b"))\n'
|
||||
'foo = depends(when=True)(lambda: ("a", "b"))\n'
|
||||
'check_prog("FOO", ("known-a",), input=foo)'
|
||||
)
|
||||
|
||||
|
@ -415,7 +415,7 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
|
||||
with self.assertRaises(ConfigureError) as e:
|
||||
self.get_result(
|
||||
'foo = depends("--help")(lambda h: {"a": "b"})\n'
|
||||
'foo = depends(when=True)(lambda: {"a": "b"})\n'
|
||||
'check_prog("FOO", ("known-a",), input=foo)'
|
||||
)
|
||||
|
||||
|
|
|
@ -47,15 +47,15 @@ class BaseCompileChecks(unittest.TestCase):
|
|||
base_dir = os.path.join(topsrcdir, 'build', 'moz.configure')
|
||||
|
||||
mock_compiler_defs = textwrap.dedent('''\
|
||||
@depends('--help')
|
||||
def extra_toolchain_flags(_):
|
||||
@depends(when=True)
|
||||
def extra_toolchain_flags():
|
||||
return []
|
||||
|
||||
include('%s/compilers-util.configure')
|
||||
|
||||
@compiler_class
|
||||
@depends('--help')
|
||||
def c_compiler(_):
|
||||
@depends(when=True)
|
||||
def c_compiler():
|
||||
return namespace(
|
||||
flags=[],
|
||||
type='gcc',
|
||||
|
@ -65,8 +65,8 @@ class BaseCompileChecks(unittest.TestCase):
|
|||
)
|
||||
|
||||
@compiler_class
|
||||
@depends('--help')
|
||||
def cxx_compiler(_):
|
||||
@depends(when=True)
|
||||
def cxx_compiler():
|
||||
return namespace(
|
||||
flags=[],
|
||||
type='gcc',
|
||||
|
@ -310,8 +310,8 @@ class TestWarningChecks(BaseCompileChecks):
|
|||
|
||||
def test_check_and_add_gcc_warning_when(self):
|
||||
cmd = textwrap.dedent('''\
|
||||
@depends('--help')
|
||||
def never(_):
|
||||
@depends(when=True)
|
||||
def never():
|
||||
return False
|
||||
check_and_add_gcc_warning('-Wfoo', cxx_compiler, when=never)
|
||||
''') + self.get_warnings()
|
||||
|
@ -325,8 +325,8 @@ class TestWarningChecks(BaseCompileChecks):
|
|||
self.assertEqual(out, '')
|
||||
|
||||
cmd = textwrap.dedent('''\
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
@depends(when=True)
|
||||
def always():
|
||||
return True
|
||||
check_and_add_gcc_warning('-Wfoo', cxx_compiler, when=always)
|
||||
''') + self.get_warnings()
|
||||
|
@ -369,8 +369,8 @@ class TestWarningChecks(BaseCompileChecks):
|
|||
|
||||
def test_add_gcc_warning_when(self):
|
||||
cmd = textwrap.dedent('''\
|
||||
@depends('--help')
|
||||
def never(_):
|
||||
@depends(when=True)
|
||||
def never():
|
||||
return False
|
||||
add_gcc_warning('-Wfoo', c_compiler, when=never)
|
||||
''') + self.get_warnings()
|
||||
|
@ -384,8 +384,8 @@ class TestWarningChecks(BaseCompileChecks):
|
|||
self.assertEqual(out, '')
|
||||
|
||||
cmd = textwrap.dedent('''\
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
@depends(when=True)
|
||||
def always():
|
||||
return True
|
||||
add_gcc_warning('-Wfoo', c_compiler, when=always)
|
||||
''') + self.get_warnings()
|
||||
|
|
|
@ -430,15 +430,9 @@ class TestConfigure(unittest.TestCase):
|
|||
|
||||
def test_set_config_when(self):
|
||||
with self.moz_configure('''
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
return True
|
||||
@depends('--help')
|
||||
def never(_):
|
||||
return False
|
||||
option('--with-qux', help='qux')
|
||||
set_config('FOO', 'foo', when=always)
|
||||
set_config('BAR', 'bar', when=never)
|
||||
set_config('FOO', 'foo', when=True)
|
||||
set_config('BAR', 'bar', when=False)
|
||||
set_config('QUX', 'qux', when='--with-qux')
|
||||
'''):
|
||||
config = self.get_config()
|
||||
|
@ -485,15 +479,9 @@ class TestConfigure(unittest.TestCase):
|
|||
|
||||
def test_set_define_when(self):
|
||||
with self.moz_configure('''
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
return True
|
||||
@depends('--help')
|
||||
def never(_):
|
||||
return False
|
||||
option('--with-qux', help='qux')
|
||||
set_define('FOO', 'foo', when=always)
|
||||
set_define('BAR', 'bar', when=never)
|
||||
set_define('FOO', 'foo', when=True)
|
||||
set_define('BAR', 'bar', when=False)
|
||||
set_define('QUX', 'qux', when='--with-qux')
|
||||
'''):
|
||||
config = self.get_config()
|
||||
|
@ -761,18 +749,12 @@ class TestConfigure(unittest.TestCase):
|
|||
|
||||
def test_option_when(self):
|
||||
with self.moz_configure('''
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
return True
|
||||
@depends('--help')
|
||||
def never(_):
|
||||
return False
|
||||
option('--with-foo', help='foo', when=always)
|
||||
option('--with-bar', help='bar', when=never)
|
||||
option('--with-foo', help='foo', when=True)
|
||||
option('--with-bar', help='bar', when=False)
|
||||
option('--with-qux', env="QUX", help='qux', when='--with-foo')
|
||||
|
||||
set_config('FOO', depends('--with-foo', when=always)(lambda x: x))
|
||||
set_config('BAR', depends('--with-bar', when=never)(lambda x: x))
|
||||
set_config('FOO', depends('--with-foo', when=True)(lambda x: x))
|
||||
set_config('BAR', depends('--with-bar', when=False)(lambda x: x))
|
||||
set_config('QUX', depends('--with-qux', when='--with-foo')(lambda x: x))
|
||||
'''):
|
||||
config = self.get_config()
|
||||
|
@ -845,10 +827,7 @@ class TestConfigure(unittest.TestCase):
|
|||
'''))
|
||||
|
||||
with self.moz_configure('''
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
return True
|
||||
option('--with-foo', help='foo', when=always)
|
||||
option('--with-foo', help='foo', when=True)
|
||||
set_config('FOO', depends('--with-foo')(lambda x: x))
|
||||
'''):
|
||||
with self.assertRaises(ConfigureError) as e:
|
||||
|
@ -859,11 +838,11 @@ class TestConfigure(unittest.TestCase):
|
|||
'options it depends on')
|
||||
|
||||
with self.moz_configure('''
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
@depends(when=True)
|
||||
def always():
|
||||
return True
|
||||
@depends('--help')
|
||||
def always2(_):
|
||||
@depends(when=True)
|
||||
def always2():
|
||||
return True
|
||||
option('--with-foo', help='foo', when=always)
|
||||
set_config('FOO', depends('--with-foo', when=always2)(lambda x: x))
|
||||
|
@ -913,17 +892,10 @@ class TestConfigure(unittest.TestCase):
|
|||
def test_include_when(self):
|
||||
with MockedOpen({
|
||||
os.path.join(test_data_path, 'moz.configure'): textwrap.dedent('''
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
return True
|
||||
@depends('--help')
|
||||
def never(_):
|
||||
return False
|
||||
|
||||
option('--with-foo', help='foo')
|
||||
|
||||
include('always.configure', when=always)
|
||||
include('never.configure', when=never)
|
||||
include('always.configure', when=True)
|
||||
include('never.configure', when=False)
|
||||
include('foo.configure', when='--with-foo')
|
||||
|
||||
set_config('FOO', foo)
|
||||
|
@ -1095,28 +1067,21 @@ class TestConfigure(unittest.TestCase):
|
|||
|
||||
def test_depends_when(self):
|
||||
with self.moz_configure('''
|
||||
@depends('--help')
|
||||
def always(_):
|
||||
return True
|
||||
@depends('--help')
|
||||
def never(_):
|
||||
return False
|
||||
|
||||
@depends('--help', when=always)
|
||||
def foo(_):
|
||||
@depends(when=True)
|
||||
def foo():
|
||||
return 'foo'
|
||||
|
||||
set_config('FOO', foo)
|
||||
|
||||
@depends('--help', when=never)
|
||||
def bar(_):
|
||||
@depends(when=False)
|
||||
def bar():
|
||||
return 'bar'
|
||||
|
||||
set_config('BAR', bar)
|
||||
|
||||
option('--with-qux', help='qux')
|
||||
@depends('--help', when='--with-qux')
|
||||
def qux(_):
|
||||
@depends(when='--with-qux')
|
||||
def qux():
|
||||
return 'qux'
|
||||
|
||||
set_config('QUX', qux)
|
||||
|
|
Загрузка…
Ссылка в новой задаче