Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notify_sdk function #500

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aqt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class OutOfMemory(AqtException):
pass


class QmakeNotFound(AqtException):
pass


class OutOfDiskSpace(AqtException):
pass

Expand Down
3 changes: 2 additions & 1 deletion aqt/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
setup_logging,
)
from aqt.metadata import ArchiveId, MetadataFactory, QtRepoProperty, SimpleSpec, Version, show_list, suggested_follow_up
from aqt.updater import Updater, dir_for_version
from aqt.updater import Notifier, Updater, dir_for_version

try:
import py7zr
Expand Down Expand Up @@ -443,6 +443,7 @@ def to_archives(baseurl: str) -> QtArchives:
if autodesk_arch is not None:
d_target_config = TargetConfig(str(_version), "desktop", autodesk_arch, os_name)
Updater.update(d_target_config, base_path, expect_desktop_archdir)
Notifier.notify_sdk(target_config, base_dir)
self.logger.info("Finished installation")
self.logger.info("Time elapsed: {time:.8f} second".format(time=time.perf_counter() - start_time))

Expand Down
137 changes: 109 additions & 28 deletions aqt/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import logging
import os
import pathlib
import re
import stat
import subprocess
Expand All @@ -30,7 +31,7 @@
import patch

from aqt.archives import TargetConfig
from aqt.exceptions import UpdaterError
from aqt.exceptions import QmakeNotFound, UpdaterError
from aqt.helper import Settings
from aqt.metadata import ArchiveId, MetadataFactory, QtRepoProperty, SimpleSpec, Version

Expand All @@ -46,6 +47,33 @@ def unpatched_paths() -> List[str]:
]


class QtConfig:
"""
detect Qt configurations from qmake.
"""

def __init__(self, prefix: pathlib.Path):
self.qmake_path = None
self.qconfigs = {}
for qmake_path in [
prefix.joinpath("bin", "qmake"),
prefix.joinpath("bin", "qmake.exe"),
]:
if not qmake_path.exists():
continue
try:
result = subprocess.run([str(qmake_path), "-query"], stdout=subprocess.PIPE)
except (subprocess.SubprocessError, IOError, OSError):
raise QmakeNotFound()
if result.returncode == 0:
self.qmake_path = qmake_path
for line in result.stdout.splitlines():
vals = line.decode("UTF-8").split(":")
self.qconfigs[vals[0]] = vals[1]
return
raise QmakeNotFound()


class Updater:
def __init__(self, prefix: Path, logger):
self.logger = logger
Expand Down Expand Up @@ -87,26 +115,6 @@ def _patch_textfile(self, file: Path, old: Union[str, re.Pattern], new: str, *,
file.write_text(data, "UTF-8")
os.chmod(str(file), file_mode)

def _detect_qmake(self) -> bool:
"""detect Qt configurations from qmake."""
for qmake_path in [
self.prefix.joinpath("bin", "qmake"),
self.prefix.joinpath("bin", "qmake.exe"),
]:
if not qmake_path.exists():
continue
try:
result = subprocess.run([str(qmake_path), "-query"], stdout=subprocess.PIPE)
except (subprocess.SubprocessError, IOError, OSError):
return False
if result.returncode == 0:
self.qmake_path = qmake_path
for line in result.stdout.splitlines():
vals = line.decode("UTF-8").split(":")
self.qconfigs[vals[0]] = vals[1]
return True
return False

def patch_prl(self, oldvalue):
for prlfile in self.prefix.joinpath("lib").glob("*.prl"):
self.logger.info("Patching {}".format(prlfile))
Expand Down Expand Up @@ -164,25 +172,26 @@ def patch_libtool(self, oldvalue, os_name):

def patch_qmake(self):
"""Patch to qmake binary"""
if self._detect_qmake():
if self.qmake_path is None:
return
self.logger.info("Patching {}".format(str(self.qmake_path)))
try:
qmake_config = QtConfig(prefix=self.prefix)
self.logger.info("Patching {}".format(str(qmake_config.qmake_path)))
self._patch_binfile(
self.qmake_path,
qmake_config.qmake_path,
key=b"qt_prfxpath=",
newpath=bytes(str(self.prefix), "UTF-8"),
)
self._patch_binfile(
self.qmake_path,
qmake_config.qmake_path,
key=b"qt_epfxpath=",
newpath=bytes(str(self.prefix), "UTF-8"),
)
self._patch_binfile(
self.qmake_path,
qmake_config.qmake_path,
key=b"qt_hpfxpath=",
newpath=bytes(str(self.prefix), "UTF-8"),
)
except QmakeNotFound:
pass

def patch_qmake_script(self, base_dir, qt_version: str, os_name: str, desktop_arch_dir: str):
sep = "\\" if os_name == "windows" else "/"
Expand Down Expand Up @@ -340,3 +349,75 @@ def patch_kde(cls, src_dir):
logger.info("Apply patch: " + p)
patchfile = patch.fromurl(PATCH_URL_BASE + p)
patchfile.apply(strip=True, root=os.path.join(src_dir, "qtbase"))


class Notifier:
@staticmethod
def notify_sdk(target, base_dir):
arch = target.arch
version = Version(target.version)
os_name = target.os_name
version_dir = dir_for_version(version)
arch_dir = QtRepoProperty.get_arch_dir_name(arch, os_name, version)
prefix = pathlib.Path(base_dir) / version_dir / arch_dir
if os_name == "windows":
sdktoolbinary = pathlib.Path(base_dir) / "Tools" / "QtCreator" / "bin" / "sdktool.exe"
toolchain = "x86-windows-generic-64bit"
component_name = "fix.me.component.name.should.unique" # FIXME
elif os_name == "mac":
sdktoolbinary = pathlib.Path(base_dir) / "Tools" / "QtCreator" / "libexec" / "qtcreator" / "sdktool"
toolchain = "x86-macos-generic-mach_o-64bit"
component_name = "fix.me.component.name.should.unique" # FIXME
else:
sdktoolbinary = pathlib.Path(base_dir) / "Tools" / "QtCreator" / "libexec" / "qtcreator" / "sdktool"
toolchain = "x86-linux-generic-elf-64bit"
component_name = "fix.me.component.name.should.unique" # FIXME
if not sdktoolbinary.exists():
return
try:
qmake_config = QtConfig(prefix)
except QmakeNotFound:
# give up notifying
return
# register Qt
qmake_full_path = qmake_config.qmake_path.absolute()
command_args = [
sdktoolbinary,
"addQt",
"--id",
component_name,
"--name",
"Desktop Qt {} {}".format(version, arch),
"--type",
"Qt4ProjectManager.QtVersion.Desktop",
"--qmake",
qmake_full_path,
]
try:
subprocess.run(command_args, stdout=subprocess.PIPE, check=True)
except subprocess.CalledProcessError as cpe:
msg = "\n".join(filter(None, [f"sdktool error: {cpe.returncode}", cpe.stdout, cpe.stderr]))
raise UpdaterError(msg) from cpe
# register SDK
kitname = component_name + "_kit"
command_args = [
sdktoolbinary,
"addKit",
"--id",
kitname,
"--name",
"Desktop Qt {} {}".format(version, arch),
"--Ctoolchain",
toolchain,
"--Cxxtoolchain",
toolchain,
"--qt",
component_name,
"--devicetype",
"Desktop",
]
try:
subprocess.run(command_args, stdout=subprocess.PIPE, check=True)
except subprocess.CalledProcessError as cpe:
msg = "\n".join(filter(None, [f"sdktool error: {cpe.returncode}", cpe.stdout, cpe.stderr]))
raise UpdaterError(msg) from cpe