DepperDan/build_functions/build_qwt.py

95 lines
3.6 KiB
Python

# (c) 2025 by Stephan Menzel
# Licensed under the Apache License, Version 2.0.
# See attached file LICENSE for full details
import os
import re
from pathlib import Path
from build_functions.build_utils import run_in_shell, print_banner, file_and_console_log
from common.azure import write_package_version_batch
from common.directory_helpers import pushd
from common.errors import BuildError
from common.git_helpers import clone_git_tag
import common.settings
from package.package_info import get_package_info
def build_qwt(prefix: Path | str, sbom: dict):
"""This gave me a lot of headaches. Very unusual build system, if that term is applicable at all.
Also, they seemed to have moved _from_ github _to_ Sourceforge prior to the 6.3.0 tag.
They have also changed the build config files a bit, so this will only work with 6.3.0
"""
print_banner("Building Qwt")
if not os.name == "nt":
raise BuildError(f"qwt is only implemented on windows. Please implement me for your system")
package_info = get_package_info("qwt")
package_info.add_to_sbom(sbom)
qt_install_path = package_info.dependency_path("qt5")
qmake_path = qt_install_path / "bin" / "qmake.exe" if os.name == "nt" else "qmake"
if not qmake_path.is_file():
raise BuildError(f"Qmake executable at {qmake_path} doesn't seem to be present")
src_dir = clone_git_tag(package_info, recursive=False)
with pushd(src_dir):
if not common.settings.rebuild and os.path.exists("built_and_installed.txt"):
file_and_console_log("already built, exiting")
return prefix
install_dir = package_info.install_location()
# I don't think this old hand-rolled build system supports out-of-src builds.
# I will try to build it right here.
# It looks like as if configuring this involves two modifications to local files.
buildfile = Path("qwtbuild.pri")
buildfile_bak = Path("qwtbuild.pri.bak")
buildfile_bak.unlink(missing_ok=True)
buildfile.rename(buildfile_bak)
# I'm trying to set the build config to release here but that doesn't work.
# It still builds debug as well. No idea how to fix this
with open(buildfile_bak, 'r') as fi, open(buildfile, 'w') as fo:
found = False
regex = re.compile(R"^\s+CONFIG\s+\+=\s(debug_and_release)$")
for line in fi:
if not found:
if m := regex.match(line):
line = line.replace(m.group(1),"release")
found = True
fo.write(line)
else:
fo.write(line)
configfile = Path("qwtconfig.pri")
configfile_bak = Path("qwtconfig.pri.bak")
configfile_bak.unlink(missing_ok=True)
configfile.rename(configfile_bak)
with open(configfile_bak, 'r') as fi, open(configfile, 'w') as fo:
found = False
regex = re.compile(R"^\s*QWT_INSTALL_PREFIX\s+=\s+(C:/Qwt-\$\$QWT_VERSION-dev)$")
for line in fi:
if not found:
if m := regex.match(line):
line = line.replace(m.group(1), str(install_dir.as_posix()))
found = True
fo.write(line)
else:
fo.write(line)
run_in_shell(f'{qmake_path} qwt.pro')
run_in_shell("nmake")
run_in_shell("nmake install")
with open("built_and_installed.txt", "w") as lockfile:
lockfile.write(f"built release")
write_package_version_batch(package_info.version)
return install_dir