Bug 1457321: Part 4 - Update built-in add-ons manifst during l10n repack. r?gandalf draft
authorKris Maglione <maglione.k@gmail.com>
Tue, 08 May 2018 01:04:01 -0700
changeset 792313 4be5425862006411c64997f7a9bc8061cad74b85
parent 789285 07d42e3f8ab6b558115c9fc3032ed49091ceb9c2
push id109082
push usermaglione.k@gmail.com
push dateTue, 08 May 2018 08:06:16 +0000
reviewersgandalf
bugs1457321
milestone61.0a1
Bug 1457321: Part 4 - Update built-in add-ons manifst during l10n repack. r?gandalf This is slightly ugly, but is unfortunately necessary due to do the nature of l10n repacks. Hopefully this can go away once we move to bundling lancpack add-ons rather than repacking in the future. MozReview-Commit-ID: JZUblVsEbZI
python/mozbuild/mozpack/packager/l10n.py
--- a/python/mozbuild/mozpack/packager/l10n.py
+++ b/python/mozbuild/mozpack/packager/l10n.py
@@ -4,30 +4,32 @@
 
 from __future__ import absolute_import
 
 '''
 Replace localized parts of a packaged directory with data from a langpack
 directory.
 '''
 
+import json
 import os
 import mozpack.path as mozpath
 from mozpack.packager.formats import (
     FlatFormatter,
     JarFormatter,
     OmniJarFormatter,
 )
 from mozpack.packager import (
     Component,
     SimplePackager,
     SimpleManifestSink,
 )
 from mozpack.files import (
     ComposedFinder,
+    GeneratedFile,
     ManifestFile,
 )
 from mozpack.copier import (
     FileCopier,
     Jarrer,
 )
 from mozpack.chrome.manifest import (
     ManifestLocale,
@@ -155,16 +157,17 @@ def _repack(app_finder, l10n_finder, cop
             for p in right:
                 paths[p] = p
             for p in left - right:
                 paths[p] = None
 
     # Create a new package, with non localized bits coming from the original
     # package, and localized bits coming from the langpack.
     packager = SimplePackager(formatter)
+    built_in_addons = None
     for p, f in app_finder:
         if is_manifest(p):
             # Remove localized manifest entries.
             for e in [e for e in f if e.localized]:
                 f.remove(e)
         # If the path is one that needs a locale replacement, use the
         # corresponding file from the langpack.
         path = None
@@ -172,28 +175,31 @@ def _repack(app_finder, l10n_finder, cop
             path = paths[p]
             if not path:
                 continue
         else:
             base = mozpath.basedir(p, paths.keys())
             if base:
                 subpath = mozpath.relpath(p, base)
                 path = mozpath.normpath(mozpath.join(paths[base],
-                                                               subpath))
+                                                     subpath))
+
         if path:
             files = [f for p, f in l10n_finder.find(path)]
             if not len(files):
                 if base not in non_chrome:
                     finderBase = ""
                     if hasattr(l10n_finder, 'base'):
                         finderBase = l10n_finder.base
                     errors.error("Missing file: %s" %
                                  os.path.join(finderBase, path))
             else:
                 packager.add(path, files[0])
+        elif p.endswith('built_in_addons.json'):
+            built_in_addons = (p, f)
         else:
             packager.add(p, f)
 
     # Add localized manifest entries from the langpack.
     l10n_manifests = []
     for base in set(e.base for e in l10n.entries):
         m = ManifestFile(base, [e for e in l10n.entries if e.base == base])
         path = mozpath.join(base, 'chrome.%s.manifest' % l10n_locale)
@@ -204,23 +210,35 @@ def _repack(app_finder, l10n_finder, cop
         packager.add(path, m)
         # Add a "manifest $path" entry in the top manifest under that base.
         m = ManifestFile(base)
         m.add(Manifest(base, mozpath.relpath(path, base)))
         packager.add(mozpath.join(base, 'chrome.manifest'), m)
 
     packager.close()
 
+    dictionaries = {}
     # Add any remaining non chrome files.
     for pattern in non_chrome:
         for base in bases:
             for p, f in l10n_finder.find(mozpath.join(base, pattern)):
                 if not formatter.contains(p):
+                    if p.startswith('dictionaries/') and p.endswith('.dic'):
+                        base, ext = os.path.splitext(os.path.basename(p))
+                        dictionaries[base] = p
+
                     formatter.add(p, f)
 
+    # Update the built-in add-ons manifest with the new list of dictionaries
+    # from the langpack.
+    if built_in_addons:
+        data = json.load(built_in_addons[1].open())
+        data['dictionaries'] = dictionaries
+        formatter.add(built_in_addons[0], GeneratedFile(json.dumps(data)))
+
     # Resources in `localization` directories are packaged from the source and then
     # if localized versions are present in the l10n dir, we package them as well
     # keeping the source dir resources as a runtime fallback.
     for p, f in l10n_finder.find('**/localization'):
         if not formatter.contains(p):
             formatter.add(p, f)
 
     # Transplant jar preloading information.