Bug 1147207 - Allow to give extra l10n directories to l10n-repack.py. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 26 Mar 2015 14:31:15 +0900
changeset 236718 9e2723115b096d81e5b08cd8e9cd23cb2102519a
parent 236717 5ad1c9b5c44d49f024bda55ec98bcec2116750dd
child 236719 64934914c29de85b66458a12e2a49894838a49c1
push id28514
push usercbook@mozilla.com
push dateTue, 31 Mar 2015 12:46:33 +0000
treeherdermozilla-central@c20f8549d631 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1147207
milestone40.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 1147207 - Allow to give extra l10n directories to l10n-repack.py. r=gps 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
@@ -14,17 +14,20 @@ from mozpack.packager.formats import (
     JarFormatter,
     OmniJarFormatter,
 )
 from mozpack.packager import (
     Component,
     SimplePackager,
     SimpleManifestSink,
 )
-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,
@@ -172,19 +175,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()