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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
#!/usr/bin/env python
#
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
Look if qt is installed, and try out all builders.
"""
import os
import sys
import TestSCons
test = TestSCons.TestSCons()
if not os.environ.get('QTDIR', None):
x ="External environment variable $QTDIR not set; skipping test(s).\n"
test.skip_test(x)
test.Qt_dummy_installation()
QTDIR=os.environ['QTDIR']
test.write('SConstruct', """\
import os
dummy_env = Environment()
ENV = dummy_env['ENV']
try:
PATH=ARGUMENTS['PATH']
if 'PATH' in ENV:
ENV_PATH = PATH + os.pathsep + ENV['PATH']
else:
Exit(0) # this is certainly a weird system :-)
except KeyError:
ENV_PATH=ENV.get('PATH', '')
env = Environment(tools=['default','qt'],
ENV={'PATH':ENV_PATH,
'PATHEXT':os.environ.get('PATHEXT'),
'HOME':os.getcwd(),
'SystemRoot':ENV.get('SystemRoot')},
# moc / uic want to write stuff in ~/.qt
CXXFILESUFFIX=".cpp")
conf = env.Configure()
if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0):
conf.env['QT_LIB'] = 'qt-mt'
if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0):
Exit(0)
env = conf.Finish()
VariantDir('bld', '.')
env.Program('bld/test_realqt', ['bld/mocFromCpp.cpp',
'bld/mocFromH.cpp',
'bld/anUiFile.ui',
'bld/main.cpp'])
""")
test.write('mocFromCpp.h', """\
void mocFromCpp();
""")
test.write('mocFromCpp.cpp', """\
#include <qobject.h>
#include "mocFromCpp.h"
class MyClass1 : public QObject {
Q_OBJECT
public:
MyClass1() : QObject() {};
public slots:
void myslot() {};
};
void mocFromCpp() {
MyClass1 myclass;
}
#include "mocFromCpp.moc"
""")
test.write('mocFromH.h', """\
#include <qobject.h>
class MyClass2 : public QObject {
Q_OBJECT;
public:
MyClass2();
public slots:
void myslot();
};
void mocFromH();
""")
test.write('mocFromH.cpp', """\
#include "mocFromH.h"
MyClass2::MyClass2() : QObject() {}
void MyClass2::myslot() {}
void mocFromH() {
MyClass2 myclass;
}
""")
test.write('anUiFile.ui', """\
<!DOCTYPE UI><UI>
<class>MyWidget</class>
<widget>
<class>QWidget</class>
<property name="name">
<cstring>MyWidget</cstring>
</property>
<property name="caption">
<string>MyWidget</string>
</property>
</widget>
<includes>
<include location="local" impldecl="in implementation">anUiFile.ui.h</include>
</includes>
<slots>
<slot>testSlot()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>
""")
test.write('anUiFile.ui.h', r"""
#include <stdio.h>
#if QT_VERSION >= 0x030100
void MyWidget::testSlot()
{
printf("Hello World\n");
}
#endif
""")
test.write('main.cpp', r"""
#include <qapp.h>
#include "mocFromCpp.h"
#include "mocFromH.h"
#include "anUiFile.h"
#include <stdio.h>
int main(int argc, char **argv) {
QApplication app(argc, argv);
mocFromCpp();
mocFromH();
MyWidget mywidget;
#if QT_VERSION >= 0x030100
mywidget.testSlot();
#else
printf("Hello World\n");
#endif
return 0;
}
""")
test.run(arguments="--warn=no-tool-qt-deprecated bld/test_realqt" + TestSCons._exe)
test.run(
program=test.workpath("bld", "test_realqt"),
arguments="--warn=no-tool-qt-deprecated",
stdout=None,
status=None,
stderr=None,
)
if test.stdout() != "Hello World\n" or test.stderr() != '' or test.status:
sys.stdout.write(test.stdout())
sys.stderr.write(test.stderr())
# The test might be run on a system that doesn't have an X server
# running, or may be run by an ID that can't connect to the server.
# If so, then print whatever it showed us (which is in and of itself
# an indication that it built correctly) but don't fail the test.
expect = 'cannot connect to X server'
test.fail_test(test.stdout())
test.fail_test(expect not in test.stderr())
if test.status != 1 and (test.status >> 8) != 1:
sys.stdout.write('test_realqt returned status %s\n' % test.status)
test.fail_test()
QTDIR = os.environ['QTDIR']
PATH = os.environ['PATH']
os.environ['QTDIR'] = ''
os.environ['PATH'] = '.'
test.run(
stderr=None,
arguments="--warn=no-tool-qt-deprecated -c bld/test_realqt" + TestSCons._exe,
)
expect1 = "scons: warning: Could not detect qt, using empty QTDIR"
expect2 = "scons: warning: Could not detect qt, using moc executable as a hint"
test.fail_test(expect1 not in test.stderr() and expect2 not in test.stderr())
test.pass_test()
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|