#!/usr/bin/env python
# encoding: utf-8
-# Thomas Nagy, 2006-2016 (ita)
+# Thomas Nagy, 2006-2018 (ita)
"""
This tool helps with finding Qt5 tools and libraries,
incs = set(self.to_list(getattr(self, 'includes', '')))
for x in self.compiled_tasks:
incs.add(x.inputs[0].parent.path_from(self.path))
- self.includes = list(incs)
+ self.includes = sorted(incs)
Note: another tool provides Qt processing that does not require
.moc includes, see 'playground/slow_qt/'.
QT5_XCOMPILE=1 QT5_FORCE_STATIC=1 waf configure
"""
+from __future__ import with_statement
+
try:
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
# direct injection in the build phase (safe because called from the main thread)
gen = self.generator.bld.producer
- gen.outstanding.appendleft(tsk)
+ gen.outstanding.append(tsk)
gen.total += 1
return tsk
Parses ``.qrc`` files
"""
def __init__(self):
+ ContentHandler.__init__(self)
self.buf = []
self.files = []
def startElement(self, name, attrs):
@extension(*EXT_RCC)
def create_rcc_task(self, node):
"Creates rcc and cxx tasks for ``.qrc`` files"
- rcnode = node.change_ext('_rc.cpp')
+ rcnode = node.change_ext('_rc.%d.cpp' % self.idx)
self.create_task('rcc', node, rcnode)
cpptask = self.create_task('cxx', rcnode, rcnode.change_ext('.o'))
try:
@extension(*EXT_UI)
def create_uic_task(self, node):
"Create uic tasks for user interface ``.ui`` definition files"
- uictask = self.create_task('ui5', node)
- uictask.outputs = [node.parent.find_or_declare(self.env.ui_PATTERN % node.name[:-3])]
+
+ """
+ If UIC file is used in more than one bld, we would have a conflict in parallel execution
+ It is not possible to change the file names (like .self.idx. as for objects) as they have
+ to be referenced by the source file, but we can assume that the transformation will be identical
+ and the tasks can be shared in a global cache.
+ """
+ try:
+ uic_cache = self.bld.uic_cache
+ except AttributeError:
+ uic_cache = self.bld.uic_cache = {}
+
+ if node not in uic_cache:
+ uictask = uic_cache[node] = self.create_task('ui5', node)
+ uictask.outputs = [node.parent.find_or_declare(self.env.ui_PATTERN % node.name[:-3])]
@extension('.ts')
def add_lang(self, node):
for x in self.to_list(self.lang):
if isinstance(x, str):
x = self.path.find_resource(x + '.ts')
- qmtasks.append(self.create_task('ts2qm', x, x.change_ext('.qm')))
+ qmtasks.append(self.create_task('ts2qm', x, x.change_ext('.%d.qm' % self.idx)))
if getattr(self, 'update', None) and Options.options.trans_qt5:
cxxnodes = [a.inputs[0] for a in self.compiled_tasks] + [
- a.inputs[0] for a in self.tasks if getattr(a, 'inputs', None) and a.inputs[0].name.endswith('.ui')]
+ a.inputs[0] for a in self.tasks if a.inputs and a.inputs[0].name.endswith('.ui')]
for x in qmtasks:
self.create_task('trans_update', cxxnodes, x.inputs)
qmnodes = [x.outputs[0] for x in qmtasks]
rcnode = self.langname
if isinstance(rcnode, str):
- rcnode = self.path.find_or_declare(rcnode + '.qrc')
+ rcnode = self.path.find_or_declare(rcnode + ('.%d.qrc' % self.idx))
t = self.create_task('qm2rcc', qmnodes, rcnode)
k = create_rcc_task(self, t.outputs[0])
self.link_task.inputs.append(k.outputs[0])
lst = []
for flag in self.to_list(self.env.CXXFLAGS):
- if len(flag) < 2: continue
+ if len(flag) < 2:
+ continue
f = flag[0:2]
if f in ('-D', '-I', '/D', '/I'):
if (f[0] == '/'):
parser = make_parser()
curHandler = XMLHandler()
parser.setContentHandler(curHandler)
- fi = open(self.inputs[0].abspath(), 'r')
- try:
- parser.parse(fi)
- finally:
- fi.close()
+ with open(self.inputs[0].abspath(), 'r') as f:
+ parser.parse(f)
nodes = []
names = []
root = self.inputs[0].parent
for x in curHandler.files:
nd = root.find_resource(x)
- if nd: nodes.append(nd)
- else: names.append(x)
+ if nd:
+ nodes.append(nd)
+ else:
+ names.append(x)
return (nodes, names)
class moc(Task.Task):
self.fatal('Could not build a simple Qt application')
# FreeBSD does not add /usr/local/lib and the pkg-config files do not provide it either :-/
- from waflib import Utils
if Utils.unversioned_sys_platform() == 'freebsd':
frag = '#include <QApplication>\nint main(int argc, char **argv) { QApplication app(argc, argv); return NULL != (void*) (&app);}\n'
try:
uicver = uicver.replace('Qt User Interface Compiler ','').replace('User Interface Compiler for Qt', '')
self.end_msg(uicver)
if uicver.find(' 3.') != -1 or uicver.find(' 4.') != -1:
- self.fatal('this uic compiler is for qt3 or qt5, add uic for qt5 to your path')
+ self.fatal('this uic compiler is for qt3 or qt4, add uic for qt5 to your path')
find_bin(['moc-qt5', 'moc'], 'QT_MOC')
find_bin(['rcc-qt5', 'rcc'], 'QT_RCC')
self.msg('Checking for %s' % i, False, 'YELLOW')
env.append_unique('INCLUDES_' + uselib, os.path.join(env.QTLIBS, frameworkName, 'Headers'))
else:
- for j in ('', 'd'):
- k = '_DEBUG' if j == 'd' else ''
- ret = self.find_single_qt5_lib(i + j, uselib + k, env.QTLIBS, qtincludes, force_static)
- if not force_static and not ret:
- ret = self.find_single_qt5_lib(i + j, uselib + k, env.QTLIBS, qtincludes, True)
- self.msg('Checking for %s' % (i + j), ret, 'GREEN' if ret else 'YELLOW')
+ ret = self.find_single_qt5_lib(i, uselib, env.QTLIBS, qtincludes, force_static)
+ if not force_static and not ret:
+ ret = self.find_single_qt5_lib(i, uselib, env.QTLIBS, qtincludes, True)
+ self.msg('Checking for %s' % i, ret, 'GREEN' if ret else 'YELLOW')
else:
path = '%s:%s:%s/pkgconfig:/usr/lib/qt5/lib/pkgconfig:/opt/qt5/lib/pkgconfig:/usr/lib/qt5/lib:/opt/qt5/lib' % (
self.environ.get('PKG_CONFIG_PATH', ''), env.QTLIBS, env.QTLIBS)
- for i in self.qt5_vars_debug + self.qt5_vars:
+ for i in self.qt5_vars:
self.check_cfg(package=i, args='--cflags --libs', mandatory=False, force_static=force_static, pkg_config_path=path)
@conf
accu.append(lib)
env['LIBPATH_'+var] = accu
process_lib(self.qt5_vars, 'LIBPATH_QTCORE')
- process_lib(self.qt5_vars_debug, 'LIBPATH_QTCORE_DEBUG')
@conf
def add_qt5_rpath(self):
accu.append('-Wl,--rpath='+lib)
env['RPATH_' + var] = accu
process_rpath(self.qt5_vars, 'LIBPATH_QTCORE')
- process_rpath(self.qt5_vars_debug, 'LIBPATH_QTCORE_DEBUG')
@conf
def set_qt5_libs_to_check(self):
if qtextralibs:
self.qt5_vars.extend(qtextralibs.split(','))
- if not hasattr(self, 'qt5_vars_debug'):
- self.qt5_vars_debug = [a + '_DEBUG' for a in self.qt5_vars]
- self.qt5_vars_debug = Utils.to_list(self.qt5_vars_debug)
-
@conf
def set_qt5_defines(self):
if sys.platform != 'win32':
for x in self.qt5_vars:
y=x.replace('Qt5', 'Qt')[2:].upper()
self.env.append_unique('DEFINES_%s' % x.upper(), 'QT_%s_LIB' % y)
- self.env.append_unique('DEFINES_%s_DEBUG' % x.upper(), 'QT_%s_LIB' % y)
def options(opt):
"""
opt.add_option('--translate', action='store_true', help='collect translation strings', dest='trans_qt5', default=False)
opt.add_option('--qtextralibs', type='string', default='', dest='qtextralibs', help='additional qt libraries on the system to add to default ones, comma separated')
+