|
|
|
|
@ -46,13 +46,35 @@ _DEPS_NOT_VENDORED_BY_DEFAULT = ['sdl2', 'sdl_image',
|
|
|
|
|
_ROOT_DIR = pathlib.Path(__file__).resolve().parent.parent |
|
|
|
|
_BUILD_DIR = _ROOT_DIR.joinpath('build-src-dist') |
|
|
|
|
_ARCHIVE_DIR = _BUILD_DIR.joinpath('archive') |
|
|
|
|
_DIST_DIR = _ARCHIVE_DIR.joinpath('dist') |
|
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger() |
|
|
|
|
_LOGGER.setLevel(logging.INFO) |
|
|
|
|
_LOGGER.addHandler(logging.StreamHandler(sys.stderr)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Version(): |
|
|
|
|
def __init__(self, num: bytes, suffix: bytes): |
|
|
|
|
self.num = num |
|
|
|
|
self.suffix = suffix |
|
|
|
|
self.str = f'{num.decode()}' |
|
|
|
|
if suffix: |
|
|
|
|
self.str += f'-{suffix.decode()}' |
|
|
|
|
|
|
|
|
|
def __str__(self) -> str: |
|
|
|
|
return self.str |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Paths(): |
|
|
|
|
def __init__(self, version: Version, fully_vendored: bool): |
|
|
|
|
self.archive_top_level_dir_name = 'devilutionx-src' |
|
|
|
|
if fully_vendored: |
|
|
|
|
self.archive_top_level_dir_name += '-full' |
|
|
|
|
self.archive_top_level_dir_name += f'-{version}' |
|
|
|
|
self.archive_top_level_dir = _ARCHIVE_DIR.joinpath( |
|
|
|
|
self.archive_top_level_dir_name) |
|
|
|
|
self.dist_dir = self.archive_top_level_dir.joinpath('dist') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
|
parser.add_argument('--fully_vendored', default=False, action='store_true') |
|
|
|
|
@ -69,29 +91,31 @@ def main():
|
|
|
|
|
if _ARCHIVE_DIR.exists(): |
|
|
|
|
shutil.rmtree(_ARCHIVE_DIR) |
|
|
|
|
|
|
|
|
|
version = get_version() |
|
|
|
|
paths = Paths(version, args.fully_vendored) |
|
|
|
|
|
|
|
|
|
_LOGGER.info(f'Copying repo files...') |
|
|
|
|
for src_bytes in git('ls-files', '-z').rstrip(b'\0').split(b'\0'): |
|
|
|
|
src = src_bytes.decode() |
|
|
|
|
dst_path = _ARCHIVE_DIR.joinpath(src) |
|
|
|
|
dst_path = paths.archive_top_level_dir.joinpath(src) |
|
|
|
|
dst_path.parent.mkdir(parents=True, exist_ok=True) |
|
|
|
|
if re.search('(^|/)\.gitkeep$', src): |
|
|
|
|
continue |
|
|
|
|
shutil.copy2(_ROOT_DIR.joinpath(src), dst_path, follow_symlinks=False) |
|
|
|
|
|
|
|
|
|
_LOGGER.info(f'Copying devilutionx.mpq...') |
|
|
|
|
_DIST_DIR.mkdir(parents=True) |
|
|
|
|
shutil.copy(_BUILD_DIR.joinpath('devilutionx.mpq'), _DIST_DIR) |
|
|
|
|
paths.dist_dir.mkdir(parents=True) |
|
|
|
|
shutil.copy(_BUILD_DIR.joinpath('devilutionx.mpq'), paths.dist_dir) |
|
|
|
|
|
|
|
|
|
for dep in _DEPS + (_DEPS_NOT_VENDORED_BY_DEFAULT if args.fully_vendored else []): |
|
|
|
|
_LOGGER.info(f'Copying {dep}...') |
|
|
|
|
shutil.copytree( |
|
|
|
|
src=_BUILD_DIR.joinpath('_deps', f'{dep}-src'), |
|
|
|
|
dst=_DIST_DIR.joinpath(f'{dep}-src'), |
|
|
|
|
dst=paths.dist_dir.joinpath(f'{dep}-src'), |
|
|
|
|
ignore=ignore_dep_src) |
|
|
|
|
|
|
|
|
|
version_num, version_suffix = get_version() |
|
|
|
|
write_dist_cmakelists(version_num, version_suffix, args.fully_vendored) |
|
|
|
|
print(make_archive(version_num, version_suffix, args.fully_vendored)) |
|
|
|
|
write_dist_cmakelists(paths, version, args.fully_vendored) |
|
|
|
|
print(make_archive(paths, args.fully_vendored)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cmake(*cmd_args): |
|
|
|
|
@ -134,20 +158,19 @@ def ignore_dep_src(src, names):
|
|
|
|
|
return filter(ignore_name, names) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_version(): |
|
|
|
|
def get_version() -> Version: |
|
|
|
|
git_tag = git('describe', '--abbrev=0', '--tags').rstrip() |
|
|
|
|
git_commit_sha = git('rev-parse', '--short', 'HEAD').rstrip() |
|
|
|
|
git_tag_sha = git('rev-parse', '--short', git_tag).rstrip() |
|
|
|
|
return git_tag, (git_commit_sha if git_tag_sha != git_commit_sha else None) |
|
|
|
|
return Version(git_tag, (git_commit_sha if git_tag_sha != git_commit_sha else None)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_dist_cmakelists(version_num, version_suffix, fully_vendored): |
|
|
|
|
version_num, version_suffix = get_version() |
|
|
|
|
with open(_DIST_DIR.joinpath('CMakeLists.txt'), 'wb') as f: |
|
|
|
|
def write_dist_cmakelists(paths: Paths, version: Version, fully_vendored: bool): |
|
|
|
|
with open(paths.dist_dir.joinpath('CMakeLists.txt'), 'wb') as f: |
|
|
|
|
f.write(b'# Generated by tools/make_src_dist.py\n') |
|
|
|
|
f.write(b'set(VERSION_NUM "%s" PARENT_SCOPE)\n' % version_num) |
|
|
|
|
if version_suffix: |
|
|
|
|
f.write(b'set(VERSION_SUFFIX "%s" PARENT_SCOPE)\n' % version_suffix) |
|
|
|
|
f.write(b'set(VERSION_NUM "%s" PARENT_SCOPE)\n' % version.num) |
|
|
|
|
if version.suffix: |
|
|
|
|
f.write(b'set(VERSION_SUFFIX "%s" PARENT_SCOPE)\n' % version.suffix) |
|
|
|
|
|
|
|
|
|
f.write(b''' |
|
|
|
|
# Pre-generated `devilutionx.mpq` is provided so that distributions do not have to depend on smpq. |
|
|
|
|
@ -174,19 +197,14 @@ endif()
|
|
|
|
|
''' % (dep.upper().encode(), dep.upper().encode())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_archive(version_num, version_suffix, fully_vendored): |
|
|
|
|
archive_base_name = f'devilutionx-{version_num.decode()}' |
|
|
|
|
if version_suffix: |
|
|
|
|
archive_base_name += f'-{version_suffix.decode()}' |
|
|
|
|
if fully_vendored: |
|
|
|
|
archive_base_name += '-full' |
|
|
|
|
def make_archive(paths: Paths, fully_vendored: bool): |
|
|
|
|
_LOGGER.info(f'Compressing {_ARCHIVE_DIR}') |
|
|
|
|
return shutil.make_archive( |
|
|
|
|
format='xztar', |
|
|
|
|
logger=_LOGGER, |
|
|
|
|
base_name=_BUILD_DIR.joinpath(archive_base_name), |
|
|
|
|
base_name=_BUILD_DIR.joinpath(paths.archive_top_level_dir_name), |
|
|
|
|
root_dir=_ARCHIVE_DIR, |
|
|
|
|
base_dir='.') |
|
|
|
|
base_dir=paths.archive_top_level_dir_name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main() |
|
|
|
|
|