Bug 1442378 - part 3 - factor out common code for zipfiles vs. tarfiles; r=jmaher
authorNathan Froyd <froydnj@mozilla.com>
Fri, 02 Mar 2018 08:34:39 -0500
changeset 406276 a66af1896deac72a3d1153f261ef3443f66e2db2
parent 406275 dbd20be50fa777779ffbc8e9e5c2527d7843f4b0
child 406277 0cf8762fe6d9c8b6eeb9a855a592bba32710b0b9
push id100396
push usernfroyd@mozilla.com
push dateFri, 02 Mar 2018 13:34:58 +0000
treeherdermozilla-inbound@387dadb05328 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1442378
milestone60.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 1442378 - part 3 - factor out common code for zipfiles vs. tarfiles; r=jmaher The zipfile and tarfiles paths for finding interesting files in the installer have duplicated code. We can eliminate this duplicated code by factoring out a function to just get the paths and sizes for files contained in the installer. If we need to make changes to how paths are processed, we now only have to make the change in a single place, and we can add other kinds of installers easily in the future.
testing/mozharness/mozharness/mozilla/building/buildbase.py
--- a/testing/mozharness/mozharness/mozilla/building/buildbase.py
+++ b/testing/mozharness/mozharness/mozilla/building/buildbase.py
@@ -1581,45 +1581,40 @@ or run without that action (ie: --no-{ac
         else:
             self.fatal("could not determine packageName")
 
         interests = ['libxul.so', 'classes.dex', 'omni.ja', 'xul.dll']
         installer = os.path.join(dist_dir, packageName)
         installer_size = 0
         size_measurements = []
 
+        def paths_with_sizes(installer):
+            if zipfile.is_zipfile(installer):
+                with zipfile.ZipFile(installer, 'r') as zf:
+                    for zi in zf.infolist():
+                        yield zi.filename, zi.file_size
+            elif tarfile.is_tarfile(installer):
+                with tarfile.open(installer, 'r:*') as tf:
+                    for ti in tf:
+                        yield ti.name, ti.size
+
         if os.path.exists(installer):
             installer_size = self.query_filesize(installer)
             self.info('Size of %s: %s bytes' % (packageName, installer_size))
             try:
                 subtests = {}
-                if zipfile.is_zipfile(installer):
-                    with zipfile.ZipFile(installer, 'r') as zf:
-                        for zi in zf.infolist():
-                            name = os.path.basename(zi.filename)
-                            size = zi.file_size
-                            if name in interests:
-                                if name in subtests:
-                                    # File seen twice in same archive;
-                                    # ignore to avoid confusion.
-                                    subtests[name] = None
-                                else:
-                                    subtests[name] = size
-                elif tarfile.is_tarfile(installer):
-                    with tarfile.open(installer, 'r:*') as tf:
-                        for ti in tf:
-                            name = os.path.basename(ti.name)
-                            size = ti.size
-                            if name in interests:
-                                if name in subtests:
-                                    # File seen twice in same archive;
-                                    # ignore to avoid confusion.
-                                    subtests[name] = None
-                                else:
-                                    subtests[name] = size
+                for path, size in paths_with_sizes(installer):
+                    name = os.path.basename(path)
+                    if name in interests:
+                        if name in subtests:
+                            # File seen twice in same archive;
+                            # ignore to avoid confusion.
+                            subtests[name] = None
+                        else:
+                            subtests[name] = size
                 for name in subtests:
                     if subtests[name] is not None:
                         self.info('Size of %s: %s bytes' % (name,
                                                             subtests[name]))
                         size_measurements.append(
                             {'name': name, 'value': subtests[name]})
             except:
                 self.info('Unable to search %s for component sizes.' % installer)