Skip to content
Snippets Groups Projects
PL1

prebuild.py — small fixes

Merged Imported Juan Font Alonso requested to merge dengof_fix_prebuildpy into master
1 file
+ 129
91
Compare changes
  • Side-by-side
  • Inline
+ 129
91
@@ -11,7 +11,6 @@ import shutil
from utils import join_dir, print_cmd, ensure_dir, check_cmake_version, copy_content_of_dir_to_other_dir, copy_file_pattern_to_dir
from git import Git
from git.repo import Repo
'''
This script prepares a build environment in a given folder for SpaceCreator. SpaceCreator is a plugin for QtCreator
and the following is needed to compile it:
@@ -32,6 +31,19 @@ python3 ./scripts/prebuild.py --output_dir ~/opt/spacecreatorenv6 --qt_version=6
'''
def __notify_satus(message: str):
me = os.path.basename(__file__)
print(f"{me}: {message}")
def __notify_action_started(action: str, arg_from, arg_to):
__notify_satus(f"{action} '{arg_from}' to '{arg_to}'")
def __notify_download_started(url, destination):
__notify_action_started("Downloading", url, destination)
def build_path_object(project_dir: str, env_path: str, qt_version: str):
"""
Builds an object with named paths for files and folders.
@@ -48,6 +60,7 @@ def build_path_object(project_dir: str, env_path: str, qt_version: str):
env_qt_libexec_dir = join_dir(env_qt_dir, 'libexec')
env_qt_bin_dir = join_dir(env_qt_dir, 'bin')
install_dir = join_dir(project_dir, 'install')
_paths = Paths()
return _paths
@@ -58,17 +71,25 @@ def download_qt(env_qt_path: str, env_qt_version: str) -> None:
Extra modules installed: qtwebsockets, qt5compat
"""
build_with_qt6 = env_qt_version.split('.')[0] == '6'
print("Downloading Qt {} to {}".format(env_qt_version, env_qt_path))
download_qt_command = ['aqt', 'install-qt', '--outputdir', env_qt_path,
'--base', 'https://download.qt.io/',
'linux', 'desktop', env_qt_version]
__notify_download_started(env_qt_version, env_qt_path)
download_qt_command = [
'aqt',
'install-qt',
'--outputdir',
env_qt_path,
'--base',
'https://download.qt.io/',
'linux',
'desktop',
env_qt_version,
]
if build_with_qt6:
download_qt_command += ['--modules', 'qtwebsockets', 'qt5compat']
print_cmd(download_qt_command)
completed_process = subprocess.run(download_qt_command)
if not completed_process.returncode == 0:
print("Downloading Qt {} failed".format(env_qt_version))
__notify_satus(f"Downloading Qt {env_qt_version} failed")
exit(1)
@@ -84,16 +105,15 @@ def download_qtcreator(env_path: str, env_qtc_version: str, env_app_dir) -> None
version_list = env_qtc_version.split('.')
version_short = '.'.join(version_list[:2]) # version_short is now in the format X.Y
base_url = 'https://download.qt.io/official_releases/qtcreator/' + \
version_short + '/' + env_qtc_version + '/installer_source/linux_x64/'
base_url = f"https://download.qt.io/official_releases/qtcreator/{version_short}/{env_qtc_version}/installer_source/linux_x64/"
bin_url = base_url + 'qtcreator.7z'
qtcreator7z = join_dir(env_path, 'qtcreator.7z')
print("Downloading {} to {}".format(bin_url, qtcreator7z))
__notify_download_started(bin_url, qtcreator7z)
try:
urllib.request.urlretrieve(bin_url, qtcreator7z) # download qtcreator.7z to the root of the env folder
except:
print("Could not download QtCreator 7z file {}".format(bin_url))
except: # noqa E722
__notify_satus(f"Could not download QtCreator 7z file '{bin_url}'")
exit(2)
with py7zr.SevenZipFile(qtcreator7z, mode='r') as z:
@@ -102,11 +122,11 @@ def download_qtcreator(env_path: str, env_qtc_version: str, env_app_dir) -> None
# Download the header files for building plugins for QtCreator and extract them to where qtcreator is
dev_url = base_url + 'qtcreator_dev.7z'
qtcreatordev7z = join_dir(env_path, 'qtcreator_dev.7z')
print("Downloading {} to {}".format(dev_url, qtcreatordev7z))
__notify_download_started(dev_url, qtcreatordev7z)
try:
urllib.request.urlretrieve(dev_url, qtcreatordev7z) # download qtcreator.7z to the root of the env folder
except:
print('Could not download QtCreator dev {}'.format(dev_url))
except: # noqa E722
__notify_satus(f"Could not download QtCreator dev '{dev_url}'")
exit(3)
with py7zr.SevenZipFile(qtcreatordev7z, mode='r') as zdev:
zdev.extractall(env_app_dir) # uncompress qtcreator into AppDir because qtcreator IS the app
@@ -119,7 +139,7 @@ def download_grantlee(env_dir: str) -> None:
gitlab_url = "https://gitrepos.estec.esa.int/taste/grantlee.git"
target_dir = join_dir(env_dir, 'grantlee')
grantlee_tag = "v5.3.1"
print('Cloning grantlee from {} the tag {}'.format(gitlab_url, grantlee_tag))
__notify_satus(f"Cloning grantlee from '{gitlab_url}' the tag '{grantlee_tag}'")
Repo.clone_from(gitlab_url, target_dir)
repo = Git(target_dir)
repo.checkout(grantlee_tag)
@@ -131,33 +151,39 @@ def build_grantlee(env_dir: str, env_qt_dir: str) -> None:
cmake_source_dir = join_dir(env_dir, 'grantlee')
qmake_dir = join_dir(env_qt_dir, 'bin', 'qmake')
print('Building grantlee')
__notify_satus("Building grantlee")
# Make ninja.build
ninja_cmd = ['cmake',
'-GNinja',
'-DCMAKE_PREFIX_PATH:STRING=' + env_qt_dir,
'-DQT_QMAKE_EXECUTABLE:STRING=' + qmake_dir,
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_INSTALL_PREFIX=' + env_qt_dir,
'-B', cmake_build_dir,
'-S', cmake_source_dir,
'-DGRANTLEE_BUILD_WITH_QT6=ON',
'-Wmaybe-uninitialized']
ninja_cmd = [
'cmake',
'-GNinja',
'-DCMAKE_PREFIX_PATH:STRING=' + env_qt_dir,
'-DQT_QMAKE_EXECUTABLE:STRING=' + qmake_dir,
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_INSTALL_PREFIX=' + env_qt_dir,
'-B',
cmake_build_dir,
'-S',
cmake_source_dir,
'-DGRANTLEE_BUILD_WITH_QT6=ON',
'-Wmaybe-uninitialized',
]
print_cmd(ninja_cmd)
completed_process = subprocess.run(ninja_cmd)
if not completed_process.returncode == 0:
print("Could not make ninja.build for grantlee")
__notify_satus("Could not make ninja.build for grantlee")
exit(4)
# Build Grantlee using ninja
build_cmd = ['cmake',
'--build',
cmake_build_dir]
build_cmd = [
'cmake',
'--build',
cmake_build_dir,
]
print_cmd(build_cmd)
completed_process = subprocess.run(build_cmd)
if not completed_process.returncode == 0:
print("Could not build grantlee")
__notify_satus("Could not build grantlee")
exit(4)
@@ -173,15 +199,17 @@ def install_grantlee(env_dir: str, app_dir: str) -> None:
:param env_dir: path to the build environment (i.e ~/opt/spacecreatorenv6)
"""
cmake_build_dir = join_dir(env_dir, 'build')
install_cmd = ['cmake',
'--build',
cmake_build_dir,
'--target',
'install']
install_cmd = [
'cmake',
'--build',
cmake_build_dir,
'--target',
'install',
]
print_cmd(install_cmd)
completed_process = subprocess.run(install_cmd)
if not completed_process.returncode == 0:
print("Could not install grantlee in {}".format(cmake_build_dir))
__notify_satus(f"Could not install grantlee in '{cmake_build_dir}'")
exit(5)
# Install grantlee in spacecreator.AppDir
@@ -207,13 +235,13 @@ def download_asn1scc(env_dir: str) -> None:
"""
asn_url = "https://github.com/maxime-esa/asn1scc/releases/download/4.2.4.7f/asn1scc-bin-4.2.4.7f.tar.bz2"
asn_tarbz2 = join_dir(env_dir, 'asn1scc-bin-4.2.4.7f.tar.bz2')
print('prebuild.py: Downloading {} to {}'.format(asn_url, asn_tarbz2))
__notify_download_started(asn_url, asn_tarbz2)
try:
urllib.request.urlretrieve(asn_url, asn_tarbz2) # download qtcreator.7z to the root of the env folder
except:
print("prebuild.py: Could not download asn1scc from {}".format(asn_url))
except: # noqa E722
__notify_satus(f"Could not download asn1scc from '{asn_url}'")
exit(4)
print('prebuild.py: Extracting {} to {}'.format(asn_tarbz2, env_dir))
__notify_action_started("Extracting", asn_tarbz2, env_dir)
with tarfile.open(asn_tarbz2, 'r:bz2') as asn_tarbz2_file:
asn_tarbz2_file.extractall(env_dir)
@@ -224,14 +252,14 @@ def download_asn_fuzzer(env_dir: str, app_dir: str) -> None:
"""
fuzzer_url = "https://github.com/n7space/asn1scc.Fuzzer/releases/download/0.9/asn1scc-Fuzzer-0.9-linux-x64.tar.gz"
fuzzer_targz = join_dir(env_dir, 'asn1scc-Fuzzer-0.9-linux-x64.tar.gz')
print('prebuild.py: Downloading {} to {}'.format(fuzzer_url, fuzzer_targz))
__notify_download_started(fuzzer_url, fuzzer_targz)
try:
urllib.request.urlretrieve(fuzzer_url, fuzzer_targz)
except:
print("prebuild.py: Could not download asn fuzzer from {}".format(fuzzer_url))
except: # noqa E722
__notify_satus(f"Could not download asn fuzzer from '{fuzzer_url}'")
exit(4)
fuzzer_target = join_dir(app_dir, "libexec", "qtcreator")
print('prebuild.py: Extracting {} to {}'.format(fuzzer_targz, fuzzer_target))
__notify_action_started("Extracting", fuzzer_targz, fuzzer_target)
with tarfile.open(fuzzer_targz, 'r:gz') as fuzzer_targz_file:
fuzzer_targz_file.extractall(fuzzer_target)
@@ -242,15 +270,16 @@ def download_pus_c(env_dir: str, app_dir: str) -> None:
"""
pusc_url = "https://github.com/n7space/asn1-pusc-lib/releases/download/1.1.0/Asn1Acn-PusC-Library-1.1.0.7z"
pusc_7z = join_dir(env_dir, 'Asn1Acn-PusC-Library-1.1.0.7z')
print('prebuild.py: Downloading {} to {}'.format(pusc_url, pusc_7z))
__notify_download_started(pusc_url, pusc_7z)
try:
urllib.request.urlretrieve(pusc_url, pusc_7z)
except:
print("prebuild.py: Could not download asn fuzzer from {}".format(pusc_url))
except: # noqa E722
__notify_satus(f"Could not download asn fuzzer from '{pusc_url}'")
exit(4)
pusc_target = join_dir(app_dir, "share", "qtcreator", "asn1acn", "libs", "PUS-C")
ensure_dir(pusc_target)
print('prebuild.py: Extracting {} to {}'.format(pusc_7z, pusc_target))
__notify_action_started("Extracting", pusc_7z, pusc_target)
with py7zr.SevenZipFile(pusc_7z, mode='r') as z:
z.extractall(pusc_target)
@@ -258,91 +287,85 @@ def download_pus_c(env_dir: str, app_dir: str) -> None:
def build_asn1scc_language_server(env_dir: str) -> None:
makefile = join_dir(env_dir, 'Makefile.debian')
if not os.path.exists(makefile):
print("prebuild.py: No Makefile.debian found in {}".format(makefile))
__notify_satus(f"No Makefile.debian found in '{makefile}'")
exit(5)
make_cmd = ['make', '-f', makefile]
print('prebuild.py: Building Language Server')
__notify_satus("Building Language Server")
print_cmd(make_cmd)
completed_process = subprocess.run(make_cmd)
if not completed_process.returncode == 0:
print("prebuild.py: Could build asn1scc")
__notify_satus("Could not build asn1scc")
exit(6)
server = join_dir(env_dir, 'asn1scc', 'lsp', 'Server', 'Server', 'bin', 'Release', 'net6.0', 'Server')
if os.path.exists(server):
print("prebuild.py: Successfully build {}".format(server))
__notify_satus(f"Successfully build '{server}'")
else:
print("prebuild.py: Failed building language server. File not build: {}", server)
__notify_satus(f"Failed building language server. File not build: '{server}'")
exit(7)
def download_asn1scc_language_server(env_dir: str) -> None:
url = "https://github.com/maxime-esa/asn1scc/releases/download/4.3.1.1/asn1scc_lsp_linux-x64-4.3.1.1.tar.bz2"
asn1cc_lsp_tarbz2 = join_dir(env_dir, 'asn1scc-lsp.tar.bz2')
print('prebuild.py: Downloading {} to {}'.format(url, asn1cc_lsp_tarbz2))
__notify_download_started(url, asn1cc_lsp_tarbz2)
try:
urllib.request.urlretrieve(url, asn1cc_lsp_tarbz2) # download qtcreator.7z to the root of the env folder
except:
print("prebuild.py: Could not download asn1scc language server from {}".format(url))
except: # noqa E722
__notify_satus(f"Could not download asn1scc language server from '{url}'")
exit(4)
print('prebuild.py: Extracting {} to {}'.format(asn1cc_lsp_tarbz2, env_dir))
__notify_action_started("Extracting", asn1cc_lsp_tarbz2, env_dir)
with tarfile.open(asn1cc_lsp_tarbz2, 'r:bz2') as ans_lsp_tarbz2_file:
ans_lsp_tarbz2_file.extractall(env_dir)
def copy_additional_qt_modules(env_qt_dir: str, app_dir: str) -> None:
if not os.path.exists(env_qt_dir):
print("prebuild.py: Could not find env qt dir: {}". format(env_qt_dir))
__notify_satus(f"Could not find env qt dir: '{env_qt_dir}'")
exit(1)
if not os.path.exists(app_dir):
print("prebuild.py: Could not find env app dir: {}".format(app_dir))
__notify_satus(f"Could not find env app dir: '{app_dir}'")
exit(2)
env_qt_lib_dir = join_dir(env_qt_dir, 'lib')
app_lib_dir = join_dir(app_dir, 'lib', 'Qt', 'lib')
print("prebuild.py: Copying additional qt modules from {} to {}".format(env_qt_lib_dir, app_lib_dir))
__notify_action_started("Copying additional qt modules", env_qt_lib_dir, app_lib_dir)
pattern = join_dir(env_qt_lib_dir, 'libQt*WebSockets*')
copy_file_pattern_to_dir(pattern, app_lib_dir)
def extract_extraLibraries(install_dir: str, lib_dir: str) -> None:
libzxb_util_gz = join_dir(install_dir, 'libzxb-util.tar.gz')
print('Extracting {} to {}'.format(libzxb_util_gz, lib_dir))
with utilTarfile.open(libzxb_util_gz, 'r:gz') as utilArchive:
utilArchive.extractall(lib_dir)
libxcb_cursor_gz = join_dir(install_dir, 'libxcb_cursor.tar.gz')
print('Extracting {} to {}'.format(libxcb_cursor_gz, lib_dir))
with cursorTarfile.open(libxcb_cursor_gz, 'r:gz') as cursorArchive:
cursorArchive.extractall(lib_dir)
libssl3_gz = join_dir(install_dir, 'libssl3.tar.gz')
print('Extracting {} to {}'.format(libssl3_gz, lib_dir))
with sslTarfile.open(libssl3_gz, 'r:gz') as sslArchive:
sslArchive.extractall(lib_dir)
extra_libs = ['libzxb-util.tar.gz', 'libxcb-cursor.tar.gz', 'libssl3.tar.gz']
for extra_lib_name in extra_libs:
extra_lib = join_dir(install_dir, extra_lib_name)
__notify_action_started("Extracting", extra_lib, lib_dir)
with tarfile.open(extra_lib, 'r:gz') as archive:
archive.extractall(lib_dir)
def copy_highlighter_files(generic_highlighter_dir: str, generic_highlighter_install_dir: str) -> None:
if not os.path.exists(generic_highlighter_dir):
print("prebuild.py: Could not find wizards dir: {}".format(generic_highlighter_dir))
__notify_satus(f"Could not find wizards dir: '{generic_highlighter_dir}'")
exit(1)
print("prebuild.py: Copying generic highlighter files from {} to {}".format(generic_highlighter_dir, generic_highlighter_install_dir))
__notify_action_started("Copying generic highlighter files", generic_highlighter_dir, generic_highlighter_install_dir)
copy_content_of_dir_to_other_dir(generic_highlighter_dir, generic_highlighter_install_dir)
def copy_snippets(snippets_dir: str, snippets_install_dir: str) -> None:
if not os.path.exists(snippets_dir):
print("prebuild.py: Could not find snippets dir {}".format(snippets_dir))
__notify_satus(f"Could not find snippets dir '{snippets_dir}'")
exit(1)
print("prebuild.py: Copying snippets from {} to {}".format(snippets_dir, snippets_install_dir))
__notify_action_started("Copying snippets", snippets_dir, snippets_install_dir)
copy_content_of_dir_to_other_dir(snippets_dir, snippets_install_dir)
def copy_qhelpgenerator(qhelpgenerator_dir: str, target_libexec_dir: str) -> None:
if not os.path.exists(qhelpgenerator_dir):
print("prebuild.py: Could not find qhelpgenerator in {}".format(qhelpgenerator_dir))
__notify_satus(f"Could not find qhelpgenerator in '{qhelpgenerator_dir}'")
exit(1)
if not os.path.exists(target_libexec_dir):
os.makedirs(target_libexec_dir) # in QtC 4 this folder does not exist
qhelpgenerator = join_dir(qhelpgenerator_dir, 'qhelpgenerator')
print("prebuild.py: Copying qhelpgenerator from {} to {}".format(qhelpgenerator_dir, target_libexec_dir))
__notify_action_started("Copying qhelpgenerator", qhelpgenerator_dir, target_libexec_dir)
shutil.copy2(qhelpgenerator, target_libexec_dir)
@@ -352,18 +375,33 @@ def main():
# Parse arguments
parser = argparse.ArgumentParser(prog='prebuild')
parser.add_argument('--output_dir', dest='env_path', type=str, required=True,
parser.add_argument('--output_dir',
dest='env_path',
type=str,
required=True,
help='Where to put the build environment . This means the '
'specified version of Qt, GrantLee lib and the spacecrator.AppDir which'
' is the final application')
parser.add_argument('--project_dir', dest='project_dir', type=str, required=False,
'specified version of Qt, GrantLee lib and the spacecrator.AppDir which'
' is the final application')
parser.add_argument('--project_dir',
dest='project_dir',
type=str,
required=False,
help='Path to the folder where spacecreator project is')
parser.add_argument('--qt_version', dest='qt_version', type=str, required=True,
parser.add_argument('--qt_version',
dest='qt_version',
type=str,
required=True,
help='Version of Qt to download to the build environment. Format X.Y.Z')
parser.add_argument('--qtcreator_version', dest='qtcreator_version', type=str, required=True,
parser.add_argument('--qtcreator_version',
dest='qtcreator_version',
type=str,
required=True,
help='Version of Qt Creator to download. Format X.Y.Z')
parser.add_argument('--app_dir', dest='app_dir', type=str, required=False,
help='Path to the folder that contains AppDir. Defaults to output_dir/spacecreator.AppDir')
parser.add_argument('--app_dir',
dest='app_dir',
type=str,
required=False,
help="Path to the folder that contains AppDir. Defaults to output_dir/spacecreator.AppDir")
args = parser.parse_args()
# Build the paths object
@@ -371,7 +409,7 @@ def main():
project_dir = args.project_dir
else:
project_dir = default_project_dir
print("prebuild.py: project_dir defaults to {}".format(project_dir))
__notify_satus(f"project_dir defaults to '{project_dir}'")
env_dir = args.env_path
if args.app_dir:
@@ -383,9 +421,9 @@ def main():
qtcreator_version = args.qtcreator_version
paths = build_path_object(project_dir, env_dir, qt_version)
print("prebuild.py: env_dir is {}".format(env_dir))
print("prebuild.py: qt_version was {}".format(qt_version))
print("prebuild.py: qtcreator_version is {}".format(qtcreator_version))
__notify_satus(f"env_dir is '{env_dir}'")
__notify_satus(f"qt_version is {qt_version}")
__notify_satus(f"qtcreator_version is {qtcreator_version}")
check_cmake_version(3, 18, 0)
Loading