Bug 1240134 - Re-factor UnpackFinder to contain a Finder instance it delegates to rather than inheriting from FileFinder. r=glandium draft
authorChris Manchester <cmanchester@mozilla.com>
Tue, 16 Aug 2016 15:16:47 -0700
changeset 401344 a2ed59c1266787994df41378098018935f41ee85
parent 400825 054d4856cea6150a6638e5daf7913713281af97d
child 401345 2b07820788d02f0486f68116bf40f6721e1885b4
push id26441
push usercmanchester@mozilla.com
push dateTue, 16 Aug 2016 22:27:47 +0000
reviewersglandium
bugs1240134
milestone51.0a1
Bug 1240134 - Re-factor UnpackFinder to contain a Finder instance it delegates to rather than inheriting from FileFinder. r=glandium MozReview-Commit-ID: LKYCROED06S
python/mozbuild/mozpack/packager/unpack.py
--- a/python/mozbuild/mozpack/packager/unpack.py
+++ b/python/mozbuild/mozpack/packager/unpack.py
@@ -1,16 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import
 
 import mozpack.path as mozpath
 from mozpack.files import (
+    BaseFinder,
     FileFinder,
     DeflatedFile,
     ManifestFile,
 )
 from mozpack.chrome.manifest import (
     parse_manifest,
     ManifestEntryWithRelPath,
     ManifestResource,
@@ -24,37 +25,45 @@ from mozpack.copier import (
 from mozpack.packager import SimplePackager
 from mozpack.packager.formats import (
     FlatFormatter,
     STARTUP_CACHE_PATHS,
 )
 from urlparse import urlparse
 
 
-class UnpackFinder(FileFinder):
+class UnpackFinder(BaseFinder):
     '''
-    Special FileFinder that treats the source package directory as if it were
-    in the flat chrome format, whatever chrome format it actually is in.
+    Special Finder object that treats the source package directory as if it
+    were in the flat chrome format, whatever chrome format it actually is in.
 
     This means that for example, paths like chrome/browser/content/... match
     files under jar:chrome/browser.jar!/content/... in case of jar chrome
     format.
+
+    The only argument to the constructor is a Finder instance or path.
+    The UnpackFinder is populated with files from this Finder instance,
+    or with files from a FileFinder using the given path as its root.
     '''
-    def __init__(self, *args, **kargs):
-        FileFinder.__init__(self, *args, **kargs)
+    def __init__(self, source):
+        if isinstance(source, BaseFinder):
+            self._finder = source
+        else:
+            self._finder = FileFinder(source)
+        self.base = self._finder.base
         self.files = FileRegistry()
         self.kind = 'flat'
         self.omnijar = None
         self.jarlogs = {}
         self.optimizedjars = False
         self.compressed = True
 
         jars = set()
 
-        for p, f in FileFinder.find(self, '*'):
+        for p, f in self._finder.find('*'):
             # Skip the precomplete file, which is generated at packaging time.
             if p == 'precomplete':
                 continue
             base = mozpath.dirname(p)
             # If the file is a zip/jar that is not a .xpi, and contains a
             # chrome.manifest, it is an omnijar. All the files it contains
             # go in the directory containing the omnijar. Manifests are merged
             # if there is a corresponding manifest in the directory.
@@ -111,17 +120,17 @@ class UnpackFinder(FileFinder):
         if jarpath:
             # Don't defer unpacking the jar file. If we already saw
             # it, take (and remove) it from the registry. If we
             # haven't, try to find it now.
             if self.files.contains(jarpath):
                 jar = self.files[jarpath]
                 self.files.remove(jarpath)
             else:
-                jar = [f for p, f in FileFinder.find(self, jarpath)]
+                jar = [f for p, f in self._finder.find(jarpath)]
                 assert len(jar) == 1
                 jar = jar[0]
             if not jarpath in jars:
                 base = mozpath.splitext(jarpath)[0]
                 for j in self._open_jar(jarpath, jar):
                     self.files.add(mozpath.join(base,
                                                      j.filename),
                                    DeflatedFile(j))