Skip to content

Commit

Permalink
Add bztar support to meson dist
Browse files Browse the repository at this point in the history
Some projects, like Postgres, distribute code in this format.
  • Loading branch information
tristan957 committed Jan 24, 2024
1 parent 760d8d5 commit 4f9eb45
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/shell-completions/zsh/_meson
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions docs/markdown/snippets/bztar_support.md
Original file line number Diff line number Diff line change
@@ -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`.
16 changes: 12 additions & 4 deletions mesonbuild/mdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand All @@ -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',
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
14 changes: 13 additions & 1 deletion unittests/allplatformstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 4f9eb45

Please sign in to comment.