dependencies/ui: Allow qt compilers and qmake to be specified in native file

This commit is contained in:
Dylan Baker 2018-10-24 14:17:44 -07:00
parent 71a5f990d0
commit aa04147a4a
5 changed files with 62 additions and 31 deletions

View File

@ -1241,8 +1241,8 @@ class ExternalProgram:
class NonExistingExternalProgram(ExternalProgram):
"A program that will never exist"
def __init__(self):
self.name = 'nonexistingprogram'
def __init__(self, name='nonexistingprogram'):
self.name = name
self.command = [None]
self.path = None

View File

@ -30,7 +30,7 @@ from ..mesonlib import (
from ..environment import detect_cpu
from .base import DependencyException, DependencyMethods
from .base import ExternalDependency, ExternalProgram
from .base import ExternalDependency, ExternalProgram, NonExistingExternalProgram
from .base import ExtraFrameworkDependency, PkgConfigDependency
from .base import ConfigToolDependency
@ -230,21 +230,46 @@ class QtBaseDependency(ExternalDependency):
self.from_text = mlog.format_list(methods)
self.version = None
def compilers_detect(self):
def compilers_detect(self, interp_obj):
"Detect Qt (4 or 5) moc, uic, rcc in the specified bindir or in PATH"
if self.bindir or for_windows(self.env.is_cross_build(), self.env):
moc = ExternalProgram(os.path.join(self.bindir, 'moc'), silent=True)
uic = ExternalProgram(os.path.join(self.bindir, 'uic'), silent=True)
rcc = ExternalProgram(os.path.join(self.bindir, 'rcc'), silent=True)
lrelease = ExternalProgram(os.path.join(self.bindir, 'lrelease'), silent=True)
# It is important that this list does not change order as the order of
# the returned ExternalPrograms will change as well
bins = ['moc', 'uic', 'rcc', 'lrelease']
found = {b: NonExistingExternalProgram(name='{}-{}'.format(b, self.name))
for b in bins}
def gen_bins():
for b in bins:
yield '{}-{}'.format(b, self.name), b, False
yield b, b, self.required
for b, name, required in gen_bins():
if found[name].found():
continue
# prefer the <tool>-qt<version> of the tool to the plain one, as we
# don't know what the unsuffixed one points to without calling it.
p = interp_obj.find_program_impl([b], silent=True, required=required).held_object
if not p.found():
continue
if b.startswith('lrelease'):
arg = ['-version']
elif mesonlib.version_compare(self.version, '>= 5'):
arg = ['--version']
else:
# We don't accept unsuffixed 'moc', 'uic', and 'rcc' because they
# are sometimes older, or newer versions.
moc = ExternalProgram('moc-' + self.name, silent=True)
uic = ExternalProgram('uic-' + self.name, silent=True)
rcc = ExternalProgram('rcc-' + self.name, silent=True)
lrelease = ExternalProgram('lrelease-' + self.name, silent=True)
return moc, uic, rcc, lrelease
arg = ['-v']
# Ensure that the version of qt and each tool are the same
_, out, err = mesonlib.Popen_safe(p.get_command() + arg)
if b.startswith('lrelease') or not self.version.startswith('4'):
care = out
else:
care = err
if mesonlib.version_compare(self.version, '== {}'.format(care.split(' ')[-1])):
found[name] = p
return tuple([found[b] for b in bins])
def _pkgconfig_detect(self, mods, kwargs):
# We set the value of required to False so that we can try the
@ -302,8 +327,15 @@ class QtBaseDependency(ExternalDependency):
def _find_qmake(self, qmake):
# Even when cross-compiling, if a cross-info qmake is not specified, we
# fallback to using the qmake in PATH because that's what we used to do
if self.env.is_cross_build() and 'qmake' in self.env.cross_info.config['binaries']:
if self.env.is_cross_build():
if 'qmake' in self.env.cross_info.config['binaries']:
return ExternalProgram.from_bin_list(self.env.cross_info.config['binaries'], 'qmake')
elif self.env.config_info:
# Prefer suffixed to unsuffixed version
p = ExternalProgram.from_bin_list(self.env.config_info.binaries, 'qmake-' + self.name)
if p.found():
return p
return ExternalProgram.from_bin_list(self.env.config_info.binaries, 'qmake')
return ExternalProgram(qmake, silent=True)
def _qmake_detect(self, mods, kwargs):

View File

@ -18,7 +18,7 @@ from .. import build
from ..mesonlib import MesonException, Popen_safe, extract_as_list, File
from ..dependencies import Dependency, Qt4Dependency, Qt5Dependency
import xml.etree.ElementTree as ET
from . import ModuleReturnValue, get_include_args
from . import ModuleReturnValue, get_include_args, ExtensionModule
from ..interpreterbase import permittedKwargs, FeatureNewKwargs
_QT_DEPS_LUT = {
@ -27,10 +27,11 @@ _QT_DEPS_LUT = {
}
class QtBaseModule:
class QtBaseModule(ExtensionModule):
tools_detected = False
def __init__(self, qt_version=5):
def __init__(self, interpreter, qt_version=5):
ExtensionModule.__init__(self, interpreter)
self.qt_version = qt_version
def _detect_tools(self, env, method):
@ -43,7 +44,7 @@ class QtBaseModule:
kwargs = {'required': 'true', 'modules': 'Core', 'silent': 'true', 'method': method}
qt = _QT_DEPS_LUT[self.qt_version](env, kwargs)
# Get all tools and then make sure that they are the right version
self.moc, self.uic, self.rcc, self.lrelease = qt.compilers_detect()
self.moc, self.uic, self.rcc, self.lrelease = qt.compilers_detect(self.interpreter)
# Moc, uic and rcc write their version strings to stderr.
# Moc and rcc return a non-zero result when doing so.
# What kind of an idiot thought that was a good idea?

View File

@ -14,14 +14,13 @@
from .. import mlog
from .qt import QtBaseModule
from . import ExtensionModule
class Qt4Module(ExtensionModule, QtBaseModule):
class Qt4Module(QtBaseModule):
def __init__(self, interpreter):
QtBaseModule.__init__(self, qt_version=4)
ExtensionModule.__init__(self, interpreter)
QtBaseModule.__init__(self, interpreter, qt_version=4)
def initialize(*args, **kwargs):
mlog.warning('rcc dependencies will not work properly until this upstream issue is fixed:',

View File

@ -14,14 +14,13 @@
from .. import mlog
from .qt import QtBaseModule
from . import ExtensionModule
class Qt5Module(ExtensionModule, QtBaseModule):
class Qt5Module(QtBaseModule):
def __init__(self, interpreter):
QtBaseModule.__init__(self, qt_version=5)
ExtensionModule.__init__(self, interpreter)
QtBaseModule.__init__(self, interpreter, qt_version=5)
def initialize(*args, **kwargs):
mlog.warning('rcc dependencies will not work reliably until this upstream issue is fixed:',