Skip to content

Commit

Permalink
Bug 1313306 - Move --help dependency checks to the linter. r=chmanche…
Browse files Browse the repository at this point in the history
…ster

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
  • Loading branch information
glandium committed Oct 27, 2016
1 parent e9aa839 commit 016afea
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 44 deletions.
1 change: 1 addition & 0 deletions python/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 0 additions & 12 deletions python/mozbuild/mozbuild/configure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,6 @@ def _value_for(self, obj, need_help_dependency=False):
@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
Expand Down
24 changes: 23 additions & 1 deletion python/mozbuild/mozbuild/configure/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -21,3 +26,20 @@ def __init__(self, environ=None, argv=None, stdout=None, stderr=None):
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)
31 changes: 0 additions & 31 deletions python/mozbuild/mozbuild/test/configure/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,23 +1064,6 @@ def foo(value):
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)
Expand All @@ -1090,20 +1073,6 @@ def bar(help, foo):
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')
Expand Down
72 changes: 72 additions & 0 deletions python/mozbuild/mozbuild/test/configure/test_lint.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 016afea

Please sign in to comment.