Bug 1147207 - Use SimplePackager code to find manifest entries and base directories during l10n repack. r=gps, a=sledru
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 25 Mar 2015 14:37:17 +0900
changeset 258317 0c29ab096b90
parent 258316 7f2d41560360
child 258318 484a6aef6a4f
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 - Use SimplePackager code to find manifest entries and base directories during l10n repack. r=gps, a=sledru This avoids duplicating the logic from SimplePackager to find base directories, and fixes some cases where the l10n repack code wouldn't find them properly.
python/mozbuild/mozpack/packager/l10n.py
python/mozbuild/mozpack/test/test_packager_l10n.py
--- a/python/mozbuild/mozpack/packager/l10n.py
+++ b/python/mozbuild/mozpack/packager/l10n.py
@@ -9,17 +9,21 @@ directory.
 
 import os
 import mozpack.path as mozpath
 from mozpack.packager.formats import (
     FlatFormatter,
     JarFormatter,
     OmniJarFormatter,
 )
-from mozpack.packager import SimplePackager
+from mozpack.packager import (
+    Component,
+    SimplePackager,
+    SimpleManifestSink,
+)
 from mozpack.files import (
     ComposedFinder,
     ManifestFile,
 )
 from mozpack.copier import (
     FileCopier,
     Jarrer,
 )
@@ -32,32 +36,62 @@ from mozpack.chrome.manifest import (
 )
 from mozpack.errors import errors
 from mozpack.packager.unpack import UnpackFinder
 from createprecomplete import generate_precomplete
 
 
 class LocaleManifestFinder(object):
     def __init__(self, finder):
-        # Read all manifest entries
-        manifests = dict((p, m) for p, m in finder.find('**/*.manifest')
-                         if is_manifest(p))
-        assert all(isinstance(m, ManifestFile)
-                   for m in manifests.itervalues())
-        self.entries = [e for m in manifests.itervalues()
-                        for e in m if e.localized]
+        entries = self.entries = []
+        bases = self.bases = ['']
+
+        class MockFormatter(object):
+            def add_interfaces(self, path, content):
+                pass
+
+            def add(self, path, content):
+                pass
+
+            def add_manifest(self, entry):
+                if entry.localized:
+                    entries.append(entry)
+
+            def add_base(self, base, addon=False):
+                bases.append(base)
+
+        # SimplePackager rejects "manifest foo.manifest" entries with
+        # additional flags (such as "manifest foo.manifest application=bar").
+        # Those type of entries are used by language packs to work as addons,
+        # but are not necessary for the purpose of l10n repacking. So we wrap
+        # the finder in order to remove those entries.
+        class WrapFinder(object):
+            def __init__(self, finder):
+                self._finder = finder
+
+            def find(self, pattern):
+                for p, f in self._finder.find(pattern):
+                    if isinstance(f, ManifestFile):
+                        unwanted = [
+                            e for e in f._entries
+                            if isinstance(e, Manifest) and e.flags
+                        ]
+                        if unwanted:
+                            f = ManifestFile(
+                                f._base,
+                                [e for e in f._entries if e not in unwanted])
+                    yield p, f
+
+        sink = SimpleManifestSink(WrapFinder(finder), MockFormatter())
+        sink.add(Component(''), '*')
+        sink.close(False)
+
         # Find unique locales used in these manifest entries.
         self.locales = list(set(e.id for e in self.entries
                                 if isinstance(e, ManifestLocale)))
-        # Find all paths whose manifest are included by no other manifest.
-        includes = set(mozpath.join(e.base, e.relpath)
-                       for m in manifests.itervalues()
-                       for e in m if isinstance(e, Manifest))
-        self.bases = [mozpath.dirname(p)
-                      for p in set(manifests.keys()) - includes]
 
 
 def _repack(app_finder, l10n_finder, copier, formatter, non_chrome=set()):
     app = LocaleManifestFinder(app_finder)
     l10n = LocaleManifestFinder(l10n_finder)
 
     # The code further below assumes there's only one locale replaced with
     # another one.
--- a/python/mozbuild/mozpack/test/test_packager_l10n.py
+++ b/python/mozbuild/mozpack/test/test_packager_l10n.py
@@ -60,17 +60,17 @@ class TestL10NRepack(unittest.TestCase):
         foo_l10n = GeneratedFile('foo_l10n')
         qux_l10n = GeneratedFile('qux_l10n')
         baz_l10n = GeneratedFile('baz_l10n')
         barbaz_l10n = GeneratedFile('barbaz_l10n')
         lst_l10n = GeneratedFile('foo\nqux')
         l10n_finder = MockFinder({
             'chrome/qux-l10n/qux.properties': qux_l10n,
             'chrome/qux-l10n/baz/baz.properties': baz_l10n,
-            'chrome/chrome.manifest': ManifestFile(' chrome', [
+            'chrome/chrome.manifest': ManifestFile('chrome', [
                 ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'),
             ]),
             'chrome.manifest':
             ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),
             'dict/bb': dict_bb,
             'dict/cc': dict_cc,
             'app/chrome/bar-l10n/barbaz.dtd': barbaz_l10n,
             'app/chrome/chrome.manifest': ManifestFile('app/chrome', [