Bug 1346025 - Merge 'compare-locales' mach command with python/mach_commands.py, r?ted
While compare-locales is a vendored module, the mach_commands.py that lives there isn't.
There isn't really a great place for an l10n related mach command, so just sticking it in
/python/mach_commands.py for now.
MozReview-Commit-ID: CKU0zz7QePP
--- a/build/mach_bootstrap.py
+++ b/build/mach_bootstrap.py
@@ -38,17 +38,16 @@ MACH_MODULES = [
'build/valgrind/mach_commands.py',
'devtools/shared/css/generated/mach_commands.py',
'dom/bindings/mach_commands.py',
'dom/media/test/external/mach_commands.py',
'layout/tools/reftest/mach_commands.py',
'python/mach_commands.py',
'python/mach/mach/commands/commandinfo.py',
'python/mach/mach/commands/settings.py',
- 'python/compare-locales/mach_commands.py',
'python/mozboot/mozboot/mach_commands.py',
'python/mozbuild/mozbuild/mach_commands.py',
'python/mozbuild/mozbuild/backend/mach_commands.py',
'python/mozbuild/mozbuild/compilation/codecomplete.py',
'python/mozbuild/mozbuild/frontend/mach_commands.py',
'services/common/tests/mach_commands.py',
'taskcluster/mach_commands.py',
'testing/awsy/mach_commands.py',
deleted file mode 100644
--- a/python/compare-locales/mach_commands.py
+++ /dev/null
@@ -1,81 +0,0 @@
-# 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 mach.decorators import (
- CommandArgument,
- CommandProvider,
- Command,
-)
-
-from mozbuild.base import (
- MachCommandBase,
-)
-
-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):
- """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
-
- # 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
-
- 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
-
- app = EnumerateApp(l10n_ini, l10n_base, locales)
- observer = compareApp(app, merge_stage=merge_dir,
- clobber=True)
- print(observer.serialize())
--- a/python/mach_commands.py
+++ b/python/mach_commands.py
@@ -198,8 +198,72 @@ class MachCommands(MachCommandBase):
if self.verbose:
if return_code != 0:
_log('Test failed: {}'.format(test_path))
else:
_log('Test passed: {}'.format(test_path))
return output, return_code, test_path
+
+
+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):
+ """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
+
+ # 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
+
+ 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
+
+ app = EnumerateApp(l10n_ini, l10n_base, locales)
+ observer = compareApp(app, merge_stage=merge_dir,
+ clobber=True)
+ print(observer.serialize())