Add support for packaging .tar* binary archives
This commit is contained in:
parent
e3e2e910f7
commit
f51f8ad574
4 changed files with 119 additions and 67 deletions
12
meson.build
12
meson.build
|
@ -332,10 +332,14 @@ if host_machine.system() == 'windows'
|
|||
)
|
||||
endif
|
||||
|
||||
zip_target = run_target('zip',
|
||||
command: zip_command,
|
||||
depends : bindist_deps,
|
||||
)
|
||||
bindist_targets = ['zip', 'tar', 'txz', 'tgz', 'tbz']
|
||||
|
||||
foreach bindist_target : bindist_targets
|
||||
run_target(bindist_target,
|
||||
command : get_variable('@0@_command'.format(bindist_target)),
|
||||
depends : bindist_deps,
|
||||
)
|
||||
endforeach
|
||||
|
||||
summary = '''
|
||||
|
||||
|
|
85
scripts/gen-dist.py
Executable file
85
scripts/gen-dist.py
Executable file
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from taiseilib.tempinstall import (
|
||||
temp_install,
|
||||
)
|
||||
|
||||
from taiseilib.common import (
|
||||
add_common_args,
|
||||
run_main,
|
||||
)
|
||||
|
||||
from pathlib import (
|
||||
Path,
|
||||
PurePosixPath,
|
||||
)
|
||||
|
||||
from datetime import (
|
||||
datetime,
|
||||
)
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
def main(args):
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
parser = argparse.ArgumentParser(description='Generate a distribution archive.', prog=args[0])
|
||||
|
||||
parser.add_argument('build_dir',
|
||||
help='the build directory (defaults to CWD)',
|
||||
default=Path(os.getcwd()),
|
||||
type=Path,
|
||||
nargs='?',
|
||||
)
|
||||
|
||||
parser.add_argument('output',
|
||||
help='the output file path',
|
||||
type=Path,
|
||||
)
|
||||
|
||||
parser.add_argument('--format',
|
||||
help='the archive format',
|
||||
default='zip',
|
||||
choices=sorted(map(lambda x: x[0], shutil.get_archive_formats())),
|
||||
)
|
||||
|
||||
parser.add_argument('--prefix',
|
||||
help='add a common prefix to all files and directories in the archive',
|
||||
default=None,
|
||||
)
|
||||
|
||||
add_common_args(parser)
|
||||
args = parser.parse_args(args[1:])
|
||||
|
||||
if args.prefix is not None:
|
||||
p = PurePosixPath(args.prefix)
|
||||
|
||||
if p.is_absolute() or p.is_reserved() or '..' in p.parts:
|
||||
raise ValueError('Bad prefix: {}'.format(args.prefix))
|
||||
|
||||
args.prefix = str(p)
|
||||
|
||||
if args.prefix == '.':
|
||||
args.prefix = None
|
||||
|
||||
with temp_install(args.build_dir) as install_dir:
|
||||
if args.prefix is not None:
|
||||
os.chdir(str(install_dir.parent))
|
||||
install_dir.rename(install_dir.parent / args.prefix)
|
||||
archive = shutil.make_archive(args.output, args.format, '.', args.prefix)
|
||||
else:
|
||||
archive = shutil.make_archive(args.output, args.format, install_dir)
|
||||
|
||||
archive = Path(archive)
|
||||
archive.rename(args.output)
|
||||
|
||||
print("Generated distribution archive {}".format(str(args.output)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_main(main)
|
|
@ -1,57 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from taiseilib.tempinstall import (
|
||||
temp_install,
|
||||
)
|
||||
|
||||
from taiseilib.common import (
|
||||
add_common_args,
|
||||
run_main,
|
||||
TaiseiError,
|
||||
)
|
||||
|
||||
from pathlib import (
|
||||
Path,
|
||||
)
|
||||
|
||||
from zipfile import (
|
||||
ZipFile,
|
||||
ZIP_DEFLATED,
|
||||
)
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import shlex
|
||||
import os
|
||||
|
||||
|
||||
def main(args):
|
||||
parser = argparse.ArgumentParser(description='Generate a ZIP distribution.', prog=args[0])
|
||||
|
||||
parser.add_argument('build_dir',
|
||||
help='The build directory (defaults to CWD)',
|
||||
default=Path(os.getcwd()),
|
||||
type=Path,
|
||||
nargs='?',
|
||||
)
|
||||
|
||||
parser.add_argument('output',
|
||||
help='The output file path',
|
||||
type=Path,
|
||||
)
|
||||
|
||||
add_common_args(parser)
|
||||
args = parser.parse_args(args[1:])
|
||||
|
||||
with temp_install(args.build_dir) as install_dir, ZipFile(str(args.output), "w", ZIP_DEFLATED) as zfile:
|
||||
for path in install_dir.glob('**/*'):
|
||||
if not path.is_dir():
|
||||
rel = str(path.relative_to(install_dir))
|
||||
print("Adding file {}".format(rel))
|
||||
zfile.write(str(path), rel)
|
||||
|
||||
print("Generated package {}".format(str(args.output)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_main(main)
|
|
@ -62,8 +62,33 @@ if is_debug_build
|
|||
dist_version_string = '@0@-debug'.format(dist_version_string)
|
||||
endif
|
||||
|
||||
dist_script = files('gen-dist.py')
|
||||
dist_name = 'Taisei-@0@-@1@-@2@'.format(dist_version_string, package_system_name, host_machine.cpu_family())
|
||||
dist_command = [python_thunk, dist_script, common_taiseilib_args]
|
||||
dist_prefix_args = ['--prefix=@0@'.format(dist_name)]
|
||||
|
||||
zip_filename = '@0@.zip'.format(dist_name)
|
||||
zip_outpath = join_paths(meson.build_root(), zip_filename)
|
||||
zip_command = [dist_command, '--format=zip', meson.build_root(), zip_outpath]
|
||||
|
||||
txz_filename = '@0@.tar.xz'.format(dist_name)
|
||||
txz_outpath = join_paths(meson.build_root(), txz_filename)
|
||||
txz_command = [dist_command, '--format=xztar', dist_prefix_args, meson.build_root(), txz_outpath]
|
||||
|
||||
tgz_filename = '@0@.tar.gz'.format(dist_name)
|
||||
tgz_outpath = join_paths(meson.build_root(), tgz_filename)
|
||||
tgz_command = [dist_command, '--format=gztar', dist_prefix_args, meson.build_root(), tgz_outpath]
|
||||
|
||||
tbz_filename = '@0@.tar.bz2'.format(dist_name)
|
||||
tbz_outpath = join_paths(meson.build_root(), tbz_filename)
|
||||
tbz_command = [dist_command, '--format=bztar', dist_prefix_args, meson.build_root(), tbz_outpath]
|
||||
|
||||
tar_filename = '@0@.tar'.format(dist_name)
|
||||
tar_outpath = join_paths(meson.build_root(), tar_filename)
|
||||
tar_command = [dist_command, '--format=tar', dist_prefix_args, meson.build_root(), tar_outpath]
|
||||
|
||||
dmg_script = files('macos-gen-dmg.py')
|
||||
dmg_filename = 'Taisei-@0@-@1@-@2@.dmg'.format(dist_version_string, package_system_name, host_machine.cpu_family())
|
||||
dmg_filename = '@0@.dmg'.format(dist_name)
|
||||
dmg_command = [python_thunk, dmg_script, join_paths(meson.build_root(), dmg_filename), meson.build_root()]
|
||||
|
||||
angle_enabled = get_option('install_angle')
|
||||
|
@ -100,11 +125,6 @@ if package_system_name == 'windows'
|
|||
]
|
||||
endif
|
||||
|
||||
zip_script = files('gen-zip.py')
|
||||
zip_filename = 'Taisei-@0@-@1@-@2@.zip'.format(dist_version_string, package_system_name, host_machine.cpu_family())
|
||||
zip_outpath = join_paths(meson.build_root(), zip_filename)
|
||||
zip_command = [python_thunk, zip_script, meson.build_root(), zip_outpath]
|
||||
|
||||
gen_atlas_script = files('gen-atlas.py')
|
||||
gen_atlas_command = [python_thunk, gen_atlas_script]
|
||||
|
||||
|
|
Loading…
Reference in a new issue