Bug 1313306 - Add a placeholder python configure linter. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 27 Oct 2016 09:36:33 +0900
changeset 430142 f71785cdb341f241e1683bf54a780d188dc70579
parent 429987 aeea9c860544abf89640fa2cf88d765c53bbc7ab
child 430143 d3f548b9453b9c15ae854d0511a2a48521eefde0
push id33750
push userbmo:mh+mozilla@glandium.org
push dateThu, 27 Oct 2016 07:43:21 +0000
reviewerschmanchester
bugs1313306
milestone52.0a1
Bug 1313306 - Add a placeholder python configure linter. r?chmanchester
python/moz.build
python/mozbuild/mozbuild/configure/lint.py
python/mozbuild/mozbuild/test/configure/lint.py
--- a/python/moz.build
+++ b/python/moz.build
@@ -32,16 +32,17 @@ PYTHON_UNIT_TESTS += [
     'mozbuild/mozbuild/test/action/test_generate_browsersearch.py',
     'mozbuild/mozbuild/test/action/test_package_fennec_apk.py',
     'mozbuild/mozbuild/test/backend/test_android_eclipse.py',
     'mozbuild/mozbuild/test/backend/test_build.py',
     'mozbuild/mozbuild/test/backend/test_configenvironment.py',
     'mozbuild/mozbuild/test/backend/test_recursivemake.py',
     'mozbuild/mozbuild/test/backend/test_visualstudio.py',
     'mozbuild/mozbuild/test/compilation/test_warnings.py',
+    'mozbuild/mozbuild/test/configure/lint.py',
     '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_moz_configure.py',
     'mozbuild/mozbuild/test/configure/test_options.py',
     'mozbuild/mozbuild/test/configure/test_toolchain_configure.py',
     'mozbuild/mozbuild/test/configure/test_toolchain_helpers.py',
     'mozbuild/mozbuild/test/configure/test_toolkit_moz_configure.py',
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/configure/lint.py
@@ -0,0 +1,28 @@
+# 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
+
+import inspect
+from StringIO import StringIO
+from collections import defaultdict
+from contextlib import contextmanager
+from . import ConfigureSandbox
+
+
+class LintSandbox(ConfigureSandbox):
+    def __init__(self, environ=None, argv=None):
+        out = StringIO()
+        environ = environ or {}
+        argv = argv or []
+        super(LintSandbox, self).__init__({}, environ=environ, argv=argv,
+                                          stdout=out, stderr=out)
+
+    def run(self, path=None):
+        if path:
+            self.include_file(path)
+
+    @contextmanager
+    def only_when_impl(self, when):
+        yield
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/configure/lint.py
@@ -0,0 +1,66 @@
+# 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
+
+import os
+import unittest
+from StringIO import StringIO
+from mozunit import main
+from buildconfig import topobjdir
+
+from mozbuild.configure.lint import LintSandbox
+
+
+test_path = os.path.abspath(__file__)
+
+
+class LintMeta(type):
+    def __new__(mcs, name, bases, attrs):
+        def create_test(project, func):
+            def test(self):
+                return func(self, project)
+            return test
+
+        for project in (
+            'b2g',
+            'b2g/dev',
+            'b2g/graphene',
+            'browser',
+            'embedding/ios',
+            'extensions',
+            'js',
+            'mobile/android',
+        ):
+            attrs['test_%s' % project.replace('/', '_')] = create_test(
+                project, attrs['lint'])
+
+        return type.__new__(mcs, name, bases, attrs)
+
+
+class Lint(unittest.TestCase):
+    __metaclass__ = LintMeta
+
+    def setUp(self):
+        self._curdir = os.getcwd()
+        os.chdir(topobjdir)
+
+    def tearDown(self):
+        os.chdir(self._curdir)
+
+    def lint(self, project):
+        path = test_path
+        for i in range(6):
+            path = os.path.dirname(path)
+
+        sandbox = LintSandbox({
+            'OLD_CONFIGURE': os.path.join(path, 'old-configure'),
+            'MOZCONFIG': os.path.join(os.path.dirname(test_path), 'data',
+                                      'empty_mozconfig'),
+        }, ['--enable-project=%s' % project])
+        sandbox.run(os.path.join(path, 'moz.configure'))
+
+
+if __name__ == '__main__':
+    main()