1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# Copyright 2015 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .. import dependencies, mlog
import os, subprocess
from .. import build
from ..mesonlib import MesonException
import xml.etree.ElementTree as ET
class Qt5Module():
def __init__(self):
mlog.log('Detecting Qt tools.')
# The binaries have different names on different
# distros. Joy.
self.moc = dependencies.ExternalProgram('moc-qt5', silent=True)
if not self.moc.found():
self.moc = dependencies.ExternalProgram('moc', silent=True)
self.uic = dependencies.ExternalProgram('uic-qt5', silent=True)
if not self.uic.found():
self.uic = dependencies.ExternalProgram('uic', silent=True)
self.rcc = dependencies.ExternalProgram('rcc-qt5', silent=True)
if not self.rcc.found():
self.rcc = dependencies.ExternalProgram('rcc', silent=True)
# 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?
if self.moc.found():
mp = subprocess.Popen(self.moc.get_command() + ['-v'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = mp.communicate()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'Qt 5' in stderr:
moc_ver = stderr
elif '5.' in stdout:
moc_ver = stdout
else:
raise MesonException('Moc preprocessor is not for Qt 5. Output:\n%s\n%s' %
(stdout, stderr))
mlog.log(' moc:', mlog.green('YES'), '(%s, %s)' % \
(' '.join(self.moc.fullpath), moc_ver.split()[-1]))
else:
mlog.log(' moc:', mlog.red('NO'))
if self.uic.found():
up = subprocess.Popen(self.uic.get_command() + ['-v'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = up.communicate()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'version 5.' in stderr:
uic_ver = stderr
elif '5.' in stdout:
uic_ver = stdout
else:
raise MesonException('Uic compiler is not for Qt 5. Output:\n%s\n%s' %
(stdout, stderr))
mlog.log(' uic:', mlog.green('YES'), '(%s, %s)' % \
(' '.join(self.uic.fullpath), uic_ver.split()[-1]))
else:
mlog.log(' uic:', mlog.red('NO'))
if self.rcc.found():
rp = subprocess.Popen(self.rcc.get_command() + ['-v'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = rp.communicate()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'version 5.' in stderr:
rcc_ver = stderr
elif '5.' in stdout:
rcc_ver = stdout
else:
raise MesonException('Rcc compiler is not for Qt 5. Output:\n%s\n%s' %
(stdout, stderr))
mlog.log(' rcc:', mlog.green('YES'), '(%s, %s)'\
% (' '.join(self.rcc.fullpath), rcc_ver.split()[-1]))
else:
mlog.log(' rcc:', mlog.red('NO'))
def parse_qrc(self, state, fname):
abspath = os.path.join(state.environment.source_dir, state.subdir, fname)
relative_part = os.path.split(fname)[0]
try:
tree = ET.parse(abspath)
root = tree.getroot()
result = []
for child in root[0]:
if child.tag != 'file':
mlog.log("Warning, malformed rcc file: ", os.path.join(state.subdir, fname))
break
else:
result.append(os.path.join(state.subdir, relative_part, child.text))
return result
except Exception:
return []
def preprocess(self, state, args, kwargs):
rcc_files = kwargs.pop('qresources', [])
if not isinstance(rcc_files, list):
rcc_files = [rcc_files]
ui_files = kwargs.pop('ui_files', [])
if not isinstance(ui_files, list):
ui_files = [ui_files]
moc_headers = kwargs.pop('moc_headers', [])
if not isinstance(moc_headers, list):
moc_headers = [moc_headers]
moc_sources = kwargs.pop('moc_sources', [])
if not isinstance(moc_sources, list):
moc_sources = [moc_sources]
srctmp = kwargs.pop('sources', [])
if not isinstance(srctmp, list):
srctmp = [srctmp]
sources = args[1:] + srctmp
if len(rcc_files) > 0:
rcc_kwargs = {'output' : '@BASENAME@.cpp',
'arguments' : ['@INPUT@', '-o', '@OUTPUT@']}
qrc_deps = []
for i in rcc_files:
qrc_deps += self.parse_qrc(state, i)
rcc_kwargs = {'input' : rcc_files,
'output' : rcc_files[0] + '.cpp',
'command' : [self.rcc, '-o', '@OUTPUT@', '@INPUT@'],
'depend_files' : qrc_deps,
}
res_target = build.CustomTarget(rcc_files[0].replace('.', '_'),
state.subdir,
rcc_kwargs)
sources.append(res_target)
if len(ui_files) > 0:
ui_kwargs = {'output' : 'ui_@BASENAME@.h',
'arguments' : ['-o', '@OUTPUT@', '@INPUT@']}
ui_gen = build.Generator([self.uic], ui_kwargs)
ui_output = build.GeneratedList(ui_gen)
[ui_output.add_file(os.path.join(state.subdir, a)) for a in ui_files]
sources.append(ui_output)
if len(moc_headers) > 0:
moc_kwargs = {'output' : 'moc_@BASENAME@.cpp',
'arguments' : ['@INPUT@', '-o', '@OUTPUT@']}
moc_gen = build.Generator([self.moc], moc_kwargs)
moc_output = build.GeneratedList(moc_gen)
[moc_output.add_file(os.path.join(state.subdir, a)) for a in moc_headers]
sources.append(moc_output)
if len(moc_sources) > 0:
moc_kwargs = {'output' : '@BASENAME@.moc',
'arguments' : ['@INPUT@', '-o', '@OUTPUT@']}
moc_gen = build.Generator([self.moc], moc_kwargs)
moc_output = build.GeneratedList(moc_gen)
[moc_output.add_file(os.path.join(state.subdir, a)) for a in moc_sources]
sources.append(moc_output)
return sources
def initialize():
mlog.log('Warning, rcc dependencies will not work reliably until this upstream issue is fixed:',
mlog.bold('https://bugreports.qt.io/browse/QTBUG-45460'))
return Qt5Module()
|