summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-03-24 02:31:23 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2019-03-25 17:58:50 +0000
commita79268a67107f609687ff2dce6a159671e6c1963 (patch)
tree6ffd52ce7baa616fb557609c0f10ee8b4a315d1c
parent8b4924f45cf238271a67b7b62a874b2d012fb029 (diff)
cerbero/package: Use lbzip2 for tarballs when available
Also, always use `tar` on platforms other than Windows. The tar shipped with MSYS is very old and slow, but it's quite performant on other platforms. Speeds up packaging on my machine from 7m30s to 2m3s. The speed up is even more drastic on the GitLab runners: 2m21s to 3.7s. Closes https://gitlab.freedesktop.org/gstreamer/cerbero/issues/132
-rw-r--r--cerbero/packages/disttarball.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/cerbero/packages/disttarball.py b/cerbero/packages/disttarball.py
index e5f4bbc4..7b55e258 100644
--- a/cerbero/packages/disttarball.py
+++ b/cerbero/packages/disttarball.py
@@ -17,12 +17,13 @@
# Boston, MA 02111-1307, USA.
import os
+import shutil
import tarfile
import cerbero.utils.messages as m
-from cerbero.utils import _
+from cerbero.utils import shell, _
from cerbero.enums import Platform
-from cerbero.errors import UsageError, EmptyPackageError
+from cerbero.errors import FatalError, UsageError, EmptyPackageError
from cerbero.packages import PackagerBase, PackageType
@@ -91,7 +92,13 @@ class DistTarball(PackagerBase):
os.remove(filename)
else:
raise UsageError("File %s already exists" % filename)
+ if self.config.platform == Platform.WINDOWS:
+ self._write_tarfile(filename, package_prefix, files)
+ else:
+ self._write_tar(filename, package_prefix, files)
+ return filename
+ def _write_tarfile(self, filename, package_prefix, files):
try:
with tarfile.open(filename, "w:bz2") as tar:
for f in files:
@@ -101,7 +108,18 @@ class DistTarball(PackagerBase):
os.replace(filename, filename + '.partial')
raise
- return filename
+ def _write_tar(self, filename, package_prefix, files):
+ tar_cmd = ['tar', '-C', self.prefix, '-cf', filename]
+ # Use lbzip2 when available for parallel compression
+ if shutil.which('lbzip2'):
+ tar_cmd += ['--use-compress-program=lbzip2']
+ else:
+ tar_cmd += ['--bzip2']
+ try:
+ shell.new_call(tar_cmd + files)
+ except FatalError:
+ os.replace(filename, filename + '.partial')
+ raise
class Packager(object):