Bug 1147207 - Allow to give extra l10n directories to l10n-repack.py. r=gps, a=sledru
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 26 Mar 2015 14:31:15 +0900
changeset 258316 7f2d41560360
parent 258315 46262c24ca5b
child 258317 0c29ab096b90
push id4643
push userryanvm@gmail.com
push date2015-04-07 14:24 +0000
treeherdermozilla-beta@0c29ab096b90 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps, sledru
bugs1147207
milestone38.0
Bug 1147207 - Allow to give extra l10n directories to l10n-repack.py. r=gps, a=sledru This allows to use separate l10n staging directories for e.g. addons.
python/mozbuild/mozpack/packager/l10n.py
toolkit/mozapps/installer/l10n-repack.py
--- a/python/mozbuild/mozpack/packager/l10n.py
+++ b/python/mozbuild/mozpack/packager/l10n.py
@@ -10,17 +10,20 @@ directory.
 import os
 import mozpack.path as mozpath
 from mozpack.packager.formats import (
     FlatFormatter,
     JarFormatter,
     OmniJarFormatter,
 )
 from mozpack.packager import SimplePackager
-from mozpack.files import ManifestFile
+from mozpack.files import (
+    ComposedFinder,
+    ManifestFile,
+)
 from mozpack.copier import (
     FileCopier,
     Jarrer,
 )
 from mozpack.chrome.manifest import (
     ManifestLocale,
     ManifestEntryWithRelPath,
     is_manifest,
@@ -160,19 +163,45 @@ def _repack(app_finder, l10n_finder, cop
                     formatter.add(p, f)
 
     # Transplant jar preloading information.
     for path, log in app_finder.jarlogs.iteritems():
         assert isinstance(copier[path], Jarrer)
         copier[path].preload([l.replace(locale, l10n_locale) for l in log])
 
 
-def repack(source, l10n, non_resources=[], non_chrome=set()):
+def repack(source, l10n, extra_l10n={}, non_resources=[], non_chrome=set()):
+    '''
+    Replace localized data from the `source` directory with localized data
+    from `l10n` and `extra_l10n`.
+
+    The `source` argument points to a directory containing a packaged
+    application (in omnijar, jar or flat form).
+    The `l10n` argument points to a directory containing the main localized
+    data (usually in the form of a language pack addon) to use to replace
+    in the packaged application.
+    The `extra_l10n` argument contains a dict associating relative paths in
+    the source to separate directories containing localized data for them.
+    This can be used to point at different language pack addons for different
+    parts of the package application.
+    The `non_resources` argument gives a list of relative paths in the source
+    that should not be added in an omnijar in case the packaged application
+    is in that format.
+    The `non_chrome` argument gives a list of file/directory patterns for
+    localized files that are not listed in a chrome.manifest.
+    '''
     app_finder = UnpackFinder(source)
     l10n_finder = UnpackFinder(l10n)
+    if extra_l10n:
+        finders = {
+            '': l10n_finder,
+        }
+        for base, path in extra_l10n.iteritems():
+            finders[base] = UnpackFinder(path)
+        l10n_finder = ComposedFinder(finders)
     copier = FileCopier()
     if app_finder.kind == 'flat':
         formatter = FlatFormatter(copier)
     elif app_finder.kind == 'jar':
         formatter = JarFormatter(copier, optimize=app_finder.optimizedjars)
     elif app_finder.kind == 'omni':
         formatter = OmniJarFormatter(copier, app_finder.omnijar,
                                      optimize=app_finder.optimizedjars,
--- a/toolkit/mozapps/installer/l10n-repack.py
+++ b/toolkit/mozapps/installer/l10n-repack.py
@@ -23,26 +23,38 @@ NON_CHROME = set([
     'update.locale',
     'updater.ini',
     'extensions/langpack-*@*',
     'distribution/extensions/langpack-*@*',
     'chrome/**/searchplugins/*.xml',
 ])
 
 
+def valid_extra_l10n(arg):
+    if '=' not in arg:
+        raise ValueError('Invalid value')
+    return tuple(arg.split('=', 1))
+
+
 def main():
     parser = ArgumentParser()
     parser.add_argument('build',
                         help='Directory containing the build to repack')
     parser.add_argument('l10n',
                         help='Directory containing the staged langpack')
+    parser.add_argument('extra_l10n', nargs='*', metavar='BASE=PATH',
+                        type=valid_extra_l10n,
+                        help='Extra directories with staged localized files '
+                             'to be considered under the given base in the '
+                             'repacked build')
     parser.add_argument('--non-resource', nargs='+', metavar='PATTERN',
                         default=[],
                         help='Extra files not to be considered as resources')
     args = parser.parse_args()
 
     buildconfig.substs['USE_ELF_HACK'] = False
     buildconfig.substs['PKG_SKIP_STRIP'] = True
-    l10n.repack(args.build, args.l10n, args.non_resource, NON_CHROME)
+    l10n.repack(args.build, args.l10n, extra_l10n=dict(args.extra_l10n),
+                non_resources=args.non_resource, non_chrome=NON_CHROME)
 
 
 if __name__ == "__main__":
     main()