Bug 1132771 - Implement file-info mach command; r=glandium
☠☠ backed out by ce21e7a57cf8 ☠ ☠
authorGregory Szorc <gps@mozilla.com>
Fri, 27 Feb 2015 13:58:01 -0800
changeset 261582 b7ec05265c3319720ffd13ed1a93a25cab9acd05
parent 261581 4cc39c54099d3eb7a40cb114e22da2a0da9e419a
child 261583 264f97c4355288ecf9c85a43e2e0f67234c40687
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1132771
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1132771 - Implement file-info mach command; r=glandium Now that we have a mechanism for defining file-based metadata, let's add a mach command to interface with it. Currently, we limit ourselves to simple Bugzilla data dumping. Features will be added over time.
python/mozbuild/mozbuild/frontend/mach_commands.py
--- a/python/mozbuild/mozbuild/frontend/mach_commands.py
+++ b/python/mozbuild/mozbuild/frontend/mach_commands.py
@@ -1,21 +1,25 @@
 # 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 print_function, unicode_literals
 
+from collections import defaultdict
+
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
-    Command
+    Command,
+    SubCommand,
 )
 
 from mozbuild.base import MachCommandBase
+import mozpack.path as mozpath
 
 
 @CommandProvider
 class MozbuildFileCommands(MachCommandBase):
     @Command('mozbuild-reference', category='build-dev',
         description='View reference documentation on mozbuild files.')
     @CommandArgument('symbol', default=None, nargs='*',
         help='Symbol to view help on. If not specified, all will be shown.')
@@ -67,8 +71,54 @@ class MozbuildFileCommands(MachCommandBa
                 return 1
 
             return 0
 
         for line in format_module(m):
             print(line)
 
         return 0
+
+    @Command('file-info', category='build-dev',
+             description='Query for metadata about files.')
+    def file_info(self):
+        pass
+
+    @SubCommand('file-info', 'bugzilla-component',
+                'Show Bugzilla component info for files listed.')
+    @CommandArgument('paths', nargs='+',
+                     help='Paths whose data to query')
+    def file_info_bugzilla(self, paths):
+        components = defaultdict(set)
+        for p, m in self._get_files_info(paths).items():
+            components[m.get('BUG_COMPONENT')].add(p)
+
+        for component, files in sorted(components.items(), key=lambda x: (x is None, x)):
+            print('%s :: %s' % (component.product, component.component) if component else 'UNKNOWN')
+            for f in sorted(files):
+                print('  %s' % f)
+
+    @SubCommand('file-info', 'missing-bugzilla',
+                'Show files missing Bugzilla component info')
+    @CommandArgument('paths', nargs='+',
+                     help='Paths whose data to query')
+    def file_info_missing_bugzilla(self, paths):
+        for p, m in sorted(self._get_files_info(paths).items()):
+            if 'BUG_COMPONENT' not in m:
+                print(p)
+
+    def _get_reader(self):
+        from mozbuild.frontend.reader import BuildReader
+        config = self.config_environment
+        return BuildReader(config)
+
+    def _get_files_info(self, paths):
+        relpaths = []
+        for p in paths:
+            a = mozpath.abspath(p)
+            if not mozpath.basedir(a, [self.topsrcdir]):
+                print('path is not inside topsrcdir: %s' % p)
+                return 1
+
+            relpaths.append(mozpath.relpath(a, self.topsrcdir))
+
+        reader = self._get_reader()
+        return reader.files_info(relpaths)