From 4f9eb450ada3ec80c62439d87e7f25451baf910f Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 24 Jan 2024 11:36:33 -0600 Subject: [PATCH] Add bztar support to meson dist Some projects, like Postgres, distribute code in this format. --- data/shell-completions/zsh/_meson | 2 +- docs/markdown/snippets/bztar_support.md | 4 ++++ mesonbuild/mdist.py | 16 ++++++++++++---- unittests/allplatformstests.py | 14 +++++++++++++- 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 docs/markdown/snippets/bztar_support.md diff --git a/data/shell-completions/zsh/_meson b/data/shell-completions/zsh/_meson index bd71a31dab21..b90caa70d55f 100644 --- a/data/shell-completions/zsh/_meson +++ b/data/shell-completions/zsh/_meson @@ -32,7 +32,7 @@ local -i ret local __meson_backends="(ninja xcode ${(j. .)${:-vs{,2010,2015,2017}}})" local __meson_build_types="(plain debug debugoptimized minsize release)" local __meson_wrap_modes="(WrapMode.{default,nofallback,nodownload,forcefallback})" -local __meson_dist_formats=("xztar" "gztar" "zip") +local __meson_dist_formats=("xztar" "gztar" "xztar" "zip") local __meson_cd='-C[change into this directory before running]:target dir:_directories' local -a __meson_common=( '--prefix=[installation prefix]: :_directories' diff --git a/docs/markdown/snippets/bztar_support.md b/docs/markdown/snippets/bztar_support.md new file mode 100644 index 000000000000..3ee4a91add30 --- /dev/null +++ b/docs/markdown/snippets/bztar_support.md @@ -0,0 +1,4 @@ +## Support for `bztar` in `meson dist` + +The `bztar` format is now supported in `meson dist`. This format is also known +as `bzip2`. diff --git a/mesonbuild/mdist.py b/mesonbuild/mdist.py index 67442885a389..6c0c17177f92 100644 --- a/mesonbuild/mdist.py +++ b/mesonbuild/mdist.py @@ -32,9 +32,10 @@ from ._typing import ImmutableListProtocol from .mesonlib import ExecutableSerialisation -archive_choices = ['gztar', 'xztar', 'zip'] +archive_choices = ['bztar', 'gztar', 'xztar', 'zip'] -archive_extension = {'gztar': '.tar.gz', +archive_extension = {'bztar': '.tar.bz2', + 'gztar': '.tar.gz', 'xztar': '.tar.xz', 'zip': '.zip'} @@ -46,7 +47,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None: parser.add_argument('--allow-dirty', action='store_true', help='Allow even when repository contains uncommitted changes.') parser.add_argument('--formats', default='xztar', - help='Comma separated list of archive types to create. Supports xztar (default), gztar, and zip.') + help='Comma separated list of archive types to create. Supports xztar (default), gztar, bztar, and zip') parser.add_argument('--include-subprojects', action='store_true', help='Include source code of subprojects that have been used for the build.') parser.add_argument('--no-tests', action='store_true', @@ -147,6 +148,7 @@ def copy_git(self, src: T.Union[str, os.PathLike], distdir: str, revision: str = if subdir is not None: cmd.extend(['--', subdir]) with tempfile.TemporaryFile() as f: + print(" ".join(cmd)) subprocess.check_call(cmd, cwd=src, stdout=f) f.seek(0) t = tarfile.open(fileobj=f) # [ignore encoding] @@ -229,6 +231,7 @@ def create_dist(self, archives: T.List[str]) -> T.List[str]: xzname = tarname + '.xz' gzname = tarname + '.gz' zipname = os.path.join(self.dist_sub, self.dist_name + '.zip') + bz2name = os.path.join(self.dist_sub, self.dist_name + '.bz2') # Note that -X interprets relative paths using the current working # directory, not the repository root, so this must be an absolute path: # https://bz.mercurial-scm.org/show_bug.cgi?id=6267 @@ -249,9 +252,14 @@ def create_dist(self, archives: T.List[str]) -> T.List[str]: with gzip.open(gzname, 'wb') as zf, open(tarname, 'rb') as tf: shutil.copyfileobj(tf, zf) output_names.append(gzname) + if 'bztar' in archives: + import bz2 + with bz2.open(bz2name, 'wb') as bf, open(tarname, 'rb') as tf: + shutil.copyfileobj(tf, bf) + output_names.append(bz2name) os.unlink(tarname) if 'zip' in archives: - subprocess.check_call(['hg', 'archive', '-R', self.src_root, '-S', '-t', 'zip', zipname]) + subprocess.check_call(['hg', 'archive', '-r', self.src_root, '-s', '-t', 'zip', zipname]) output_names.append(zipname) return output_names diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index bfd0b18561dd..f4ec87f84eb4 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -1505,6 +1505,8 @@ def dist_impl(self, vcs_init, vcs_add_all=None, include_subprojects=True): ''')) xz_distfile = os.path.join(self.distdir, 'disttest-1.4.3.tar.xz') xz_checksumfile = xz_distfile + '.sha256sum' + bz_distfile = os.path.join(self.distdir, 'disttest-1.4.3.tar.bz2') + bz_checksumfile = xz_distfile + '.sha256sum' gz_distfile = os.path.join(self.distdir, 'disttest-1.4.3.tar.gz') gz_checksumfile = gz_distfile + '.sha256sum' zip_distfile = os.path.join(self.distdir, 'disttest-1.4.3.zip') @@ -1520,10 +1522,16 @@ def dist_impl(self, vcs_init, vcs_add_all=None, include_subprojects=True): self.build('dist') self.assertPathExists(xz_distfile) self.assertPathExists(xz_checksumfile) + self.assertPathDoesNotExist(bz_distfile) + self.assertPathDoesNotExist(bz_checksumfile) self.assertPathDoesNotExist(gz_distfile) self.assertPathDoesNotExist(gz_checksumfile) self.assertPathDoesNotExist(zip_distfile) self.assertPathDoesNotExist(zip_checksumfile) + self._run(self.meson_command + ['dist', '--formats', 'bztar'], + workdir=self.builddir) + self.assertPathExists(bz_distfile) + self.assertPathExists(bz_checksumfile) self._run(self.meson_command + ['dist', '--formats', 'gztar'], workdir=self.builddir) self.assertPathExists(gz_distfile) @@ -1534,14 +1542,18 @@ def dist_impl(self, vcs_init, vcs_add_all=None, include_subprojects=True): self.assertPathExists(zip_checksumfile) os.remove(xz_distfile) os.remove(xz_checksumfile) + os.remove(bz_distfile) + os.remove(bz_checksumfile) os.remove(gz_distfile) os.remove(gz_checksumfile) os.remove(zip_distfile) os.remove(zip_checksumfile) - self._run(self.meson_command + ['dist', '--formats', 'xztar,gztar,zip'], + self._run(self.meson_command + ['dist', '--formats', 'xztar,bztar,gztar,zip'], workdir=self.builddir) self.assertPathExists(xz_distfile) self.assertPathExists(xz_checksumfile) + self.assertPathExists(bz_distfile) + self.assertPathExists(bz_checksumfile) self.assertPathExists(gz_distfile) self.assertPathExists(gz_checksumfile) self.assertPathExists(zip_distfile)