Bug 1539355 - Don't package addons in resource directories as XPI in OmnijarFormatter. r=nalexander
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 27 Mar 2019 22:33:10 +0000
changeset 466494 2ba58db65271c9be85179a049e15e4535661580a
parent 466493 0f96b37a1e3476769fb00c9bf2a153019777f234
child 466495 483189a652e1418ddcac2d0ed3c3697789754ff7
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)
reviewersnalexander
bugs1539355
milestone68.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 1539355 - Don't package addons in resource directories as XPI in OmnijarFormatter. r=nalexander The addons manager is going to support this usecase. Depends on D25036 Differential Revision: https://phabricator.services.mozilla.com/D25037
python/mozbuild/mozpack/packager/formats.py
python/mozbuild/mozpack/test/test_packager_formats.py
--- a/python/mozbuild/mozpack/packager/formats.py
+++ b/python/mozbuild/mozpack/packager/formats.py
@@ -262,16 +262,31 @@ class OmniJarFormatter(JarFormatter):
 
     def __init__(self, copier, omnijar_name, compress=True, non_resources=()):
         JarFormatter.__init__(self, copier, compress)
         self._omnijar_name = omnijar_name
         self._non_resources = non_resources
 
     def _add_base(self, base, addon=False):
         if addon:
+            # Because add_base is always called with parents before children,
+            # all the possible ancestry of `base` is already present in
+            # `_sub_formatter`.
+            parent_base = mozpath.basedir(base, self._sub_formatter.keys())
+            if parent_base:
+                rel_base = mozpath.relpath(base, parent_base)
+                # If the addon is under a resource directory, package it in the
+                # omnijar.
+                parent_sub_formatter = self._sub_formatter[parent_base]
+                if parent_sub_formatter.is_resource(rel_base):
+                    omnijar_sub_formatter = \
+                        parent_sub_formatter._sub_formatter[self._omnijar_name]
+                    self._sub_formatter[base] = FlatSubFormatter(
+                        FileRegistrySubtree(rel_base, omnijar_sub_formatter.copier))
+                    return
             JarFormatter._add_base(self, base, addon)
         else:
             # Initialize a chrome.manifest next to the omnijar file so that
             # there's always a chrome.manifest file, even an empty one.
             path = mozpath.normpath(mozpath.join(base, 'chrome.manifest'))
             if not self.copier.contains(path):
                 self.copier.add(path, ManifestFile(''))
             self._sub_formatter[base] = OmniJarSubFormatter(
--- a/python/mozbuild/mozpack/test/test_packager_formats.py
+++ b/python/mozbuild/mozpack/test/test_packager_formats.py
@@ -26,16 +26,17 @@ from mozpack.errors import (
     ErrorMessage,
 )
 from mozpack.test.test_files import (
     foo_xpt,
     foo2_xpt,
     bar_xpt,
 )
 import mozpack.path as mozpath
+from itertools import chain
 from test_errors import TestErrors
 
 
 CONTENTS = {
     'bases': {
         # base_path: is_addon?
         '': False,
         'app': False,
@@ -217,30 +218,29 @@ RESULT_OMNIJAR.update({
     'chrome.manifest': [
         'manifest components/components.manifest',
     ],
     'components/components.manifest': [
         'binary-component foo.so',
     ],
     'app/omni.foo': {
         p: RESULT_FLAT['app/' + p]
-        for p in (
+        for p in chain((
             'chrome.manifest',
             'chrome/chrome.manifest',
             'chrome/foo/foo',
             'components/components.manifest',
             'components/foo.js',
-        )
+        ), (
+            mozpath.relpath(p, 'app')
+            for p in RESULT_FLAT.iterkeys()
+            if p.startswith('app/chrome/addons/addon2/')
+        ))
     },
     'app/chrome.manifest': [],
-    'app/chrome/addons/addon2.xpi': {
-        mozpath.relpath(p, 'app/chrome/addons/addon2'): f
-        for p, f in RESULT_FLAT.iteritems()
-        if p.startswith('app/chrome/addons/addon2/')
-    },
 })
 
 RESULT_OMNIJAR['omni.foo'].update({
     p: RESULT_FLAT[p]
     for p in (
         'chrome.manifest',
         'chrome/chrome.manifest',
         'chrome/f/f.manifest',