Bug 1147207 - Use SimplePackager code to find manifest entries and base directories during l10n repack. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 01 Apr 2015 13:32:24 +0900
changeset 236930 89e2807dbd5b2798dcaf8825264a9a3f3d6c6572
parent 236929 da6cbd725f5f14b3b26d286b72852041c2b773ba
child 236931 a8f3297ddd22069bb2d07a7439d0c5a951b61ce8
push id57819
push usermh@glandium.org
push dateWed, 01 Apr 2015 04:52:39 +0000
treeherdermozilla-inbound@89e2807dbd5b [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 - Use SimplePackager code to find manifest entries and base directories during l10n repack. r=gps 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
@@ -36,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', [