diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2019-03-25 10:04:31 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2019-03-25 23:52:22 +0530 |
commit | 99b16ab232f379c59e3c05db69f4e18d6a418173 (patch) | |
tree | ddfb115370b6ca6b849b3699225f30307b4eba25 | |
parent | a79268a67107f609687ff2dce6a159671e6c1963 (diff) |
cerbero/package: New argument --xz to output .tar.xz
This option is only used when the package command will create
a tarball or an Android package (which inherits from DistTarball).
Uses `xz --threads=0` by default to maximize parallelism. This was
compared with `pixz` and found to be either the same or better in
tests.
-rw-r--r-- | cerbero/commands/package.py | 6 | ||||
-rw-r--r-- | cerbero/config.py | 4 | ||||
-rw-r--r-- | cerbero/packages/android.py | 8 | ||||
-rw-r--r-- | cerbero/packages/disttarball.py | 23 |
4 files changed, 29 insertions, 12 deletions
diff --git a/cerbero/commands/package.py b/cerbero/commands/package.py index 38dfc770..eedc2294 100644 --- a/cerbero/commands/package.py +++ b/cerbero/commands/package.py @@ -63,6 +63,9 @@ class Package(Command): default=False, help=_('Use only the source cache, no network')), ArgparseArgument('--dry-run', action='store_true', default=False, help=_('Only print the packages that will be built')), + ArgparseArgument('--xz', action='store_true', + default=False, help=_('Use xz instead of bzip2 for compression if ' + 'creating a tarball')), ]) def run(self, config, args): @@ -79,6 +82,9 @@ class Package(Command): if args.only_build_deps or args.dry_run: return + if args.xz: + config.package_tarball_compression = 'xz' + if p is None: raise PackageNotFoundError(args.package[0]) if args.tarball: diff --git a/cerbero/config.py b/cerbero/config.py index a763691b..0230325f 100644 --- a/cerbero/config.py +++ b/cerbero/config.py @@ -113,7 +113,8 @@ class Config (object): 'ios_min_version', 'toolchain_path', 'mingw_perl_prefix', 'msvc_version', 'msvc_toolchain_env', 'mingw_toolchain_env', 'meson_cross_properties', 'manifest', 'extra_properties', - 'qt5_qmake_path', 'qt5_pkgconfigdir', 'for_shell'] + 'qt5_qmake_path', 'qt5_pkgconfigdir', 'for_shell', + 'package_tarball_compression'] cookbook = None @@ -384,6 +385,7 @@ class Config (object): self.set_property('target_distro_version', distro_version) self.set_property('packages_prefix', None) self.set_property('packager', DEFAULT_PACKAGER) + self.set_property('package_tarball_compression', 'bz2') stdlibpath = sysconfig.get_path('stdlib', vars={'installed_base': ''})[1:] # Ensure that the path uses / as path separator and not \ self.set_property('py_prefix', PurePath(stdlibpath).as_posix()) diff --git a/cerbero/packages/android.py b/cerbero/packages/android.py index 7c388fb8..7dca5a3e 100644 --- a/cerbero/packages/android.py +++ b/cerbero/packages/android.py @@ -28,9 +28,6 @@ from cerbero.errors import UsageError class AndroidPackager(DistTarball): ''' Creates a distribution tarball for Android ''' - def __init__(self, config, package, store): - super().__init__(config, package, store) - def _create_tarball(self, output_dir, package_type, files, force, package_prefix): # Filter out some unwanted directories for the development package @@ -39,7 +36,10 @@ class AndroidPackager(DistTarball): files = [x for x in files if not x.startswith(filt)] return super()._create_tarball(output_dir, package_type, files, force, package_prefix) - def _get_name(self, package_type, ext='tar.bz2'): + def _get_name(self, package_type, ext=None): + if ext is None: + ext = 'tar.' + self.compress + if package_type == PackageType.DEVEL: package_type = '' elif package_type == PackageType.RUNTIME: diff --git a/cerbero/packages/disttarball.py b/cerbero/packages/disttarball.py index 7b55e258..3c404887 100644 --- a/cerbero/packages/disttarball.py +++ b/cerbero/packages/disttarball.py @@ -37,6 +37,9 @@ class DistTarball(PackagerBase): self.package_prefix = '' if self.config.packages_prefix is not None: self.package_prefix = '%s-' % self.config.packages_prefix + self.compress = config.package_tarball_compression + if self.compress not in ('bz2', 'xz'): + raise UsageError('Invalid compression type {!r}'.format(self.compress)) def pack(self, output_dir, devel=True, force=False, keep_temp=False, split=True, package_prefix=''): @@ -73,7 +76,10 @@ class DistTarball(PackagerBase): filenames.append(devel) return filenames - def _get_name(self, package_type, ext='tar.bz2'): + def _get_name(self, package_type, ext=None): + if ext is None: + ext = 'tar.' + self.compress + if self.config.target_platform != Platform.WINDOWS: platform = self.config.target_platform elif self.config.variants.visualstudio: @@ -100,7 +106,7 @@ class DistTarball(PackagerBase): def _write_tarfile(self, filename, package_prefix, files): try: - with tarfile.open(filename, "w:bz2") as tar: + with tarfile.open(filename, 'w:' + self.compress) as tar: for f in files: filepath = os.path.join(self.prefix, f) tar.add(filepath, os.path.join(package_prefix, f)) @@ -110,11 +116,14 @@ class DistTarball(PackagerBase): 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'] + if self.compress == 'bz2': + # Use lbzip2 when available for parallel compression + if shutil.which('lbzip2'): + tar_cmd += ['--use-compress-program=lbzip2'] + else: + tar_cmd += ['--bzip2'] + elif self.compress == 'xz': + tar_cmd += ['--use-compress-program=xz --threads=0'] try: shell.new_call(tar_cmd + files) except FatalError: |