bug 1382005, make mach command a bare minimum wrapper, r?glandium draft
authorAxel Hecht <axel@pike.org>
Mon, 18 Sep 2017 18:17:52 +0200
changeset 666994 544b70bdf850c754c45dede7e6a5cd25a4700382
parent 666993 33402ceaadc8d22a545b2eff5d7d09174ef8e476
child 666995 134f82f601064bc9c28867bd26519e6cac7bd79a
push id80582
push useraxel@mozilla.com
push dateTue, 19 Sep 2017 14:37:32 +0000
reviewersglandium
bugs1382005
milestone57.0a1
bug 1382005, make mach command a bare minimum wrapper, r?glandium The compare-locales mach command used to own a couple of defaults and opinions. Now that those opinions and defaults are in the Makefiles, this command can be much simpler. As a side effect, this should make the thunderbird port easier, where none of the mach defaults worked. MozReview-Commit-ID: DuT4FsfSyqQ
tools/compare-locales/mach_commands.py
--- a/tools/compare-locales/mach_commands.py
+++ b/tools/compare-locales/mach_commands.py
@@ -5,77 +5,51 @@
 from __future__ import absolute_import, print_function, unicode_literals
 
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
     Command,
 )
 
-from mozbuild.base import (
-    MachCommandBase,
+from mach.base import (
+    FailedCommandError,
 )
 
-import mozpack.path as mozpath
-
-
-MERGE_HELP = '''Directory to merge to. Will be removed to before running
-the comparison. Default: $(OBJDIR)/($MOZ_BUILD_APP)/locales/merge-$(AB_CD)
-'''.lstrip()
-
 
 @CommandProvider
-class CompareLocales(MachCommandBase):
+class CompareLocales(object):
     """Run compare-locales."""
 
     @Command('compare-locales', category='testing',
              description='Run source checks on a localization.')
-    @CommandArgument('--l10n-ini',
-                     help='l10n.ini describing the app. ' +
-                     'Default: $(MOZ_BUILD_APP)/locales/l10n.ini')
-    @CommandArgument('--l10n-base',
-                     help='Directory with the localizations. ' +
-                     'Default: $(L10NBASEDIR)')
-    @CommandArgument('--merge-dir',
-                     help=MERGE_HELP)
-    @CommandArgument('locales', nargs='+', metavar='ab_CD',
-                     help='Locale codes to compare')
-    def compare(self, l10n_ini=None, l10n_base=None, merge_dir=None,
-                locales=None):
-        from compare_locales.paths import EnumerateApp
-        from compare_locales.compare import compareApp
+    @CommandArgument('config_paths', metavar='l10n.toml', nargs='+',
+                     help='TOML or INI file for the project')
+    @CommandArgument('l10n_base_dir', metavar='l10n-base-dir',
+                     help='Parent directory of localizations')
+    @CommandArgument('locales', nargs='*', metavar='locale-code',
+                     help='Locale code and top-level directory of '
+                          'each localization')
+    @CommandArgument('-m', '--merge',
+                     help='''Use this directory to stage merged files''')
+    @CommandArgument('-D', action='append', metavar='var=value',
+                     default=[], dest='defines',
+                     help='Overwrite variables in TOML files')
+    @CommandArgument('--unified', action="store_true",
+                     help="Show output for all projects unified")
+    @CommandArgument('--full', action="store_true",
+                     help="Compare projects that are disabled")
+    def compare(self, **kwargs):
+        from compare_locales.commands import CompareLocales
 
-        # check if we're configured and use defaults from there
-        # otherwise, error early
-        try:
-            self.substs  # explicitly check
-            if not l10n_ini:
-                l10n_ini = mozpath.join(
-                    self.topsrcdir,
-                    self.substs['MOZ_BUILD_APP'],
-                    'locales', 'l10n.ini'
-                )
-            if not l10n_base:
-                l10n_base = mozpath.join(
-                    self.topsrcdir,
-                    self.substs['L10NBASEDIR']
-                )
-        except Exception:
-            if not l10n_ini or not l10n_base:
-                print('Specify --l10n-ini and --l10n-base or run configure.')
-                return 1
+        class ErrorHelper(object):
+            '''Dummy ArgumentParser to marshall compare-locales
+            commandline errors to mach exceptions.
+            '''
+            def error(self, msg):
+                raise FailedCommandError(msg)
 
-        if not merge_dir:
-            try:
-                # self.substs is raising an Exception if we're not configured
-                # don't merge if we're not
-                merge_dir = mozpath.join(
-                    self.topobjdir,
-                    self.substs['MOZ_BUILD_APP'],
-                    'locales', 'merge-dir-{ab_CD}'
-                )
-            except Exception:
-                pass
+            def exit(self, message=None, status=0):
+                raise FailedCommandError(message, exit_code=status)
 
-        app = EnumerateApp(l10n_ini, l10n_base, locales)
-        observer = compareApp(app, merge_stage=merge_dir,
-                              clobber=True)
-        print(observer.serialize())
+        cmd = CompareLocales()
+        cmd.parser = ErrorHelper()
+        return cmd.handle(**kwargs)