Bug 1539355 - Force callers of *Formatter.add_base to order their bases. r=nalexander
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 27 Mar 2019 22:19:32 +0000
changeset 466493 0f96b37a1e3476769fb00c9bf2a153019777f234
parent 466492 1463643557fcfdad3102f81c94edcf281c70d706
child 466494 2ba58db65271c9be85179a049e15e4535661580a
push id35768
push useropoprus@mozilla.com
push dateThu, 28 Mar 2019 09:55:54 +0000
treeherdermozilla-central@c045dd97faf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 1539355 - Force callers of *Formatter.add_base to order their bases. r=nalexander Practically speaking, it makes no difference, as only the calls to add_base from tests weren't already ordered. This allows a simpler approach for next change. Differential Revision: https://phabricator.services.mozilla.com/D25036
--- a/python/mozbuild/mozpack/packager/formats.py
+++ b/python/mozbuild/mozpack/packager/formats.py
@@ -38,16 +38,18 @@ formats:
 The base interface provides the following methods:
     - add_base(path [, addon])
         Register a base directory for an application or GRE, or an addon.
         Base directories usually contain a root manifest (manifests not
         included in any other manifest) named chrome.manifest.
         The optional addon argument tells whether the base directory
         is that of a packed addon (True), unpacked addon ('unpacked') or
         otherwise (False).
+        The method may only be called in sorted order of `path` (alphanumeric
+        order, parents before children).
     - add(path, content)
         Add the given content (BaseFile instance) at the given virtual path
     - add_interfaces(path, content)
         Add the given content (BaseFile instance) as an interface. Equivalent
         to add(path, content) with the right add_manifest().
     - add_manifest(entry)
         Add a ManifestEntry.
     - contains(path)
@@ -72,16 +74,17 @@ class PiecemealFormatter(object):
         self.copier = copier
         self._sub_formatter = {}
         self._frozen_bases = False
     def add_base(self, base, addon=False):
         # Only allow to add a base directory before calls to _get_base()
         assert not self._frozen_bases
         assert base not in self._sub_formatter
+        assert all(base > b for b in self._sub_formatter)
         self._add_base(base, addon)
     def _get_base(self, path):
         Return the deepest base directory containing the given path.
         self._frozen_bases = True
         base = mozpath.basedir(path, self._sub_formatter.keys())
--- a/python/mozbuild/mozpack/test/test_packager_formats.py
+++ b/python/mozbuild/mozpack/test/test_packager_formats.py
@@ -289,17 +289,17 @@ def result_with_base(results):
 RESULT_JAR_WITH_BASE = result_with_base(RESULT_JAR)
 def fill_formatter(formatter, contents):
-    for base, is_addon in contents['bases'].items():
+    for base, is_addon in sorted(contents['bases'].items()):
         formatter.add_base(base, is_addon)
     for manifest in contents['manifests']:
     for k, v in sorted(contents['files'].iteritems()):
         if k.endswith('.xpt'):
             formatter.add_interfaces(k, v)
@@ -320,18 +320,18 @@ def get_contents(registry, read_all=Fals
 class TestFormatters(TestErrors, unittest.TestCase):
     maxDiff = None
     def test_bases(self):
         formatter = FlatFormatter(FileRegistry())
+        formatter.add_base('addon0', addon=True)
-        formatter.add_base('addon0', addon=True)
                          ('', 'platform.ini'))
                          ('browser', 'application.ini'))
                          ('addon0', 'install.rdf'))
     def do_test_contents(self, formatter, contents):