qbreak/scripts/build_qbreak.py

105 lines
3.0 KiB
Python
Raw Normal View History

2022-04-17 15:37:04 +03:00
#!/usr/bin/python3
import typing
import platform
import os
import shutil
import glob
2022-11-13 21:04:43 +03:00
import sys
2022-04-17 15:37:04 +03:00
from pathlib import Path
import multiprocessing
import build_utils
EXIT_OK = 0
EXIT_ERROR = 1
# Check if Qt is specified
2022-05-07 21:59:47 +03:00
if not 'QT_HOME' in os.environ:
print('Qt location must be set in QT_HOME environment variable.')
2022-04-17 15:37:04 +03:00
exit(1)
# Prepare build directory
build_dir = Path('build')
if build_dir.exists():
shutil.rmtree(build_dir)
os.mkdir(build_dir)
app_source = Path('../app').resolve()
version_suffix = build_utils.get_version(app_source / 'config.h', 'QBREAK_VERSION_SUFFIX')
version_minor = build_utils.get_version(app_source / 'config.h', 'QBREAK_VERSION_MINOR')
version_major = build_utils.get_version(app_source / 'config.h', 'QBREAK_VERSION_MAJOR')
2022-05-07 21:59:47 +03:00
if version_major is None or version_minor is None or version_suffix is None:
print('App version is not found, exiting.')
exit(EXIT_OK)
2022-04-17 15:37:04 +03:00
app_version = f'{version_major}.{version_minor}.{version_suffix}'
print (f'Found QBreak version: {app_version}')
# Go to build directory
os.chdir(build_dir)
if platform.system() == 'Linux':
print('Linux detected')
print('Configure...')
2022-05-07 21:59:47 +03:00
qmake_path = Path(os.environ['QT_HOME']) / 'bin' / 'qmake'
retcode = os.system(f'{qmake_path} ../../app')
2022-04-17 15:37:04 +03:00
if retcode != 0:
print(f'qmake call failed with code {retcode}')
exit(retcode)
2022-11-13 21:04:43 +03:00
# Check the requested type of build - debug or release
build_type = 'release'
if len(sys.argv) == 2:
build_type = sys.argv[1]
2022-04-17 15:37:04 +03:00
print('Build...')
2022-11-13 21:04:43 +03:00
retcode = os.system(f'make {build_type} -j4')
2022-04-17 15:37:04 +03:00
if retcode != 0:
print(f'make call failed with code {retcode}')
exit(retcode)
# Build appimage
print('Assembling app...')
os.chdir('..')
# Remove possible old image
if os.path.exists('appimage_dir'):
shutil.rmtree('appimage_dir')
# Expand image template
retcode = os.system('tar -xvzf appimage_dir.tar.gz')
if retcode != 0:
print(f'Failed to expand template directory, code {retcode}')
exit(retcode)
# Copy binary file
shutil.copy('build/qbreak', 'appimage_dir/usr/bin')
deploy_options = [
'-always-overwrite',
'-verbose=2',
'-appimage',
2022-05-07 21:59:47 +03:00
'-qmake=' + os.environ['QT_HOME'] + '/bin/qmake',
2022-04-17 15:37:04 +03:00
'-unsupported-allow-new-glibc',
#'-no-translations',
'-extra-plugins=iconengines,platformthemes/libqgtk3.so,platforms/libqxcb.so'
2022-04-17 15:37:04 +03:00
]
desktop_path = 'appimage_dir/usr/share/applications/qbreak.desktop'
cmd_deploy = f'./linuxdeployqt {desktop_path} {" ".join(deploy_options)}'
retcode = os.system(cmd_deploy)
if retcode != 0:
print(f'linuxdeployqt failed with code {retcode}')
print(cmd_deploy)
exit(retcode)
releases_dir = Path('releases')
if not releases_dir.exists():
os.mkdir(releases_dir)
for f in os.listdir():
if f.endswith('x86_64.AppImage') and f.startswith('QBreak'):
shutil.move(f, releases_dir / f'qbreak-{app_version}-x86_64.AppImage')
exit(0)