Bug 1313306 - Move --help dependency checks to the linter. r=chmanchester

Missing such dependencies shouldn't impair running configure itself
after local modifications, but they are currently required for
(mostly) documentation purpose. Which means they are better done in
the linter.

--HG--
extra : rebase_source : 6bfff2342cda2ed1351f561c9eb9623f1fb4e4c4
This commit is contained in:
Mike Hommey 2016-10-27 10:02:21 +09:00
Родитель e9aa83949b
Коммит 016afea56c
5 изменённых файлов: 96 добавлений и 44 удалений

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

@ -41,6 +41,7 @@ PYTHON_UNIT_TESTS += [
'mozbuild/mozbuild/test/configure/test_checks_configure.py',
'mozbuild/mozbuild/test/configure/test_compile_checks.py',
'mozbuild/mozbuild/test/configure/test_configure.py',
'mozbuild/mozbuild/test/configure/test_lint.py',
'mozbuild/mozbuild/test/configure/test_moz_configure.py',
'mozbuild/mozbuild/test/configure/test_options.py',
'mozbuild/mozbuild/test/configure/test_toolchain_configure.py',

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

@ -410,18 +410,6 @@ class ConfigureSandbox(dict):
@memoize
def _value_for_depends(self, obj, need_help_dependency=False):
assert not inspect.isgeneratorfunction(obj.func)
with_help = self._help_option in obj.dependencies
if with_help:
for arg in obj.dependencies:
if isinstance(arg, DependsFunction):
if self._help_option not in arg.dependencies:
raise ConfigureError(
"`%s` depends on '--help' and `%s`. "
"`%s` must depend on '--help'"
% (obj.name, arg.name, arg.name))
elif self._help or need_help_dependency:
raise ConfigureError("Missing @depends for `%s`: '--help'" %
obj.name)
return obj.result
@memoize

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

@ -5,7 +5,12 @@
from __future__ import absolute_import, print_function, unicode_literals
from StringIO import StringIO
from . import ConfigureSandbox
from . import (
ConfigureError,
ConfigureSandbox,
DependsFunction,
)
from mozbuild.util import memoize
class LintSandbox(ConfigureSandbox):
@ -21,3 +26,20 @@ class LintSandbox(ConfigureSandbox):
def run(self, path=None):
if path:
self.include_file(path)
@memoize
def _value_for_depends(self, obj, need_help_dependency=False):
with_help = self._help_option in obj.dependencies
if with_help:
for arg in obj.dependencies:
if isinstance(arg, DependsFunction):
if self._help_option not in arg.dependencies:
raise ConfigureError(
"`%s` depends on '--help' and `%s`. "
"`%s` must depend on '--help'"
% (obj.name, arg.name, arg.name))
elif self._help or need_help_dependency:
raise ConfigureError("Missing @depends for `%s`: '--help'" %
obj.name)
return super(LintSandbox, self)._value_for_depends(
obj, need_help_dependency)

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

@ -1064,23 +1064,6 @@ class TestConfigure(unittest.TestCase):
self.assertEquals(e.exception.message,
"Cannot decorate generator functions with @depends")
with self.assertRaises(ConfigureError) as e:
with self.moz_configure('''
option('--foo', help='foo')
@depends('--foo')
def foo(value):
return value
@depends('--help', foo)
def bar(help, foo):
return
'''):
self.get_config()
self.assertEquals(e.exception.message,
"`bar` depends on '--help' and `foo`. "
"`foo` must depend on '--help'")
with self.assertRaises(TypeError) as e:
with self.moz_configure('''
depends('--help')(42)
@ -1090,20 +1073,6 @@ class TestConfigure(unittest.TestCase):
self.assertEquals(e.exception.message,
"Unexpected type: 'int'")
with self.assertRaises(ConfigureError) as e:
with self.moz_configure('''
option('--foo', help='foo')
@depends('--foo')
def foo(value):
return value
include(foo)
'''):
self.get_config()
self.assertEquals(e.exception.message,
"Missing @depends for `foo`: '--help'")
with self.assertRaises(ConfigureError) as e:
with self.moz_configure('''
option('--foo', help='foo')

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

@ -0,0 +1,72 @@
# 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/.
from __future__ import absolute_import, print_function, unicode_literals
from StringIO import StringIO
import os
import textwrap
import unittest
from mozunit import (
main,
MockedOpen,
)
from mozbuild.configure import ConfigureError
from mozbuild.configure.lint import LintSandbox
import mozpack.path as mozpath
test_data_path = mozpath.abspath(mozpath.dirname(__file__))
test_data_path = mozpath.join(test_data_path, 'data')
class TestLint(unittest.TestCase):
def lint_test(self, options=[], env={}):
sandbox = LintSandbox(env, ['configure'] + options)
sandbox.run(mozpath.join(test_data_path, 'moz.configure'))
def moz_configure(self, source):
return MockedOpen({
os.path.join(test_data_path,
'moz.configure'): textwrap.dedent(source)
})
def test_depends_failures(self):
with self.assertRaises(ConfigureError) as e:
with self.moz_configure('''
option('--foo', help='foo')
@depends('--foo')
def foo(value):
return value
@depends('--help', foo)
def bar(help, foo):
return
'''):
self.lint_test()
self.assertEquals(e.exception.message,
"`bar` depends on '--help' and `foo`. "
"`foo` must depend on '--help'")
with self.assertRaises(ConfigureError) as e:
with self.moz_configure('''
option('--foo', help='foo')
@depends('--foo')
def foo(value):
return value
include(foo)
'''):
self.lint_test()
self.assertEquals(e.exception.message,
"Missing @depends for `foo`: '--help'")
if __name__ == '__main__':
main()