author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include "externaltests.h" |
|
44 |
||
45 |
#include <QtCore/QTemporaryFile> |
|
46 |
#include <QtCore/QProcess> |
|
47 |
#include <QtCore/QByteArray> |
|
48 |
#include <QtCore/QString> |
|
49 |
#include <QtCore/QFileInfo> |
|
50 |
#include <QtCore/QDir> |
|
51 |
#include <QtCore/QDirIterator> |
|
52 |
#include <QtCore/QDateTime> |
|
53 |
||
54 |
#ifdef Q_OS_SYMBIAN |
|
55 |
#define DEFAULT_MAKESPEC "X:/STLsupport/mkspecs/symbian-abld/" |
|
56 |
#endif |
|
57 |
||
58 |
#ifndef DEFAULT_MAKESPEC |
|
59 |
# error DEFAULT_MAKESPEC not defined |
|
60 |
#endif |
|
61 |
||
62 |
#ifdef Q_OS_UNIX |
|
63 |
# include <fcntl.h> |
|
64 |
# include <unistd.h> |
|
65 |
#endif |
|
66 |
||
67 |
static QString makespec() |
|
68 |
{ |
|
69 |
static const char default_makespec[] = DEFAULT_MAKESPEC; |
|
70 |
const char *p; |
|
71 |
for (p = default_makespec + sizeof(default_makespec) - 1; p >= default_makespec; --p) |
|
72 |
if (*p == '/' || *p == '\\') |
|
73 |
break; |
|
74 |
||
75 |
return QString::fromLatin1(p + 1); |
|
76 |
} |
|
77 |
||
78 |
static bool removeRecursive(const QString &pathname) |
|
79 |
{ |
|
80 |
QFileInfo fi(pathname); |
|
81 |
if (!fi.exists()) |
|
82 |
return true; |
|
83 |
||
84 |
if (fi.isFile()) |
|
85 |
return QFile::remove(pathname); |
|
86 |
||
87 |
if (!fi.isDir()) { |
|
88 |
// not a file or directory. How do I remove it? |
|
89 |
return false; |
|
90 |
} |
|
91 |
||
92 |
// not empty -- we must empty it first |
|
93 |
QDirIterator di(pathname, QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot); |
|
94 |
while (di.hasNext()) { |
|
95 |
di.next(); |
|
96 |
if (!di.fileInfo().exists() && !di.fileInfo().isSymLink()) |
|
97 |
continue; |
|
98 |
bool ok; |
|
99 |
if (di.fileInfo().isFile() || di.fileInfo().isSymLink()) |
|
100 |
ok = QFile::remove(di.filePath()); |
|
101 |
else |
|
102 |
ok = removeRecursive(di.filePath()); |
|
103 |
if (!ok) { |
|
104 |
return false; |
|
105 |
} |
|
106 |
} |
|
107 |
||
108 |
QDir dir(pathname); |
|
109 |
QString dirname = dir.dirName(); |
|
110 |
dir.cdUp(); |
|
111 |
return dir.rmdir(dirname); |
|
112 |
} |
|
113 |
||
114 |
QT_BEGIN_NAMESPACE |
|
115 |
namespace QTest { |
|
116 |
class QExternalProcess: public QProcess |
|
117 |
{ |
|
118 |
protected: |
|
119 |
#ifdef Q_OS_UNIX |
|
120 |
void setupChildProcess() |
|
121 |
{ |
|
122 |
// run in user code |
|
123 |
QProcess::setupChildProcess(); |
|
124 |
||
125 |
if (processChannelMode() == ForwardedChannels) { |
|
126 |
// reopen /dev/tty into stdin |
|
127 |
int fd = ::open("/dev/tty", O_RDONLY); |
|
128 |
if (fd == -1) |
|
129 |
return; |
|
130 |
::dup2(fd, 0); |
|
131 |
::close(fd); |
|
132 |
} |
|
133 |
} |
|
134 |
#endif |
|
135 |
}; |
|
136 |
||
137 |
class QExternalTestPrivate |
|
138 |
{ |
|
139 |
public: |
|
140 |
QExternalTestPrivate() |
|
141 |
: qtModules(QExternalTest::QtCore | QExternalTest::QtGui | QExternalTest::QtTest), |
|
142 |
appType(QExternalTest::AutoApplication), |
|
143 |
exitCode(-1) |
|
144 |
{ |
|
145 |
} |
|
146 |
~QExternalTestPrivate() |
|
147 |
{ |
|
148 |
clear(); |
|
149 |
} |
|
150 |
||
151 |
enum Target { Compile, Link, Run }; |
|
152 |
||
153 |
QList<QByteArray> qmakeLines; |
|
154 |
QStringList extraProgramSources; |
|
155 |
QByteArray programHeader; |
|
156 |
QExternalTest::QtModules qtModules; |
|
157 |
QExternalTest::ApplicationType appType; |
|
158 |
||
159 |
QString temporaryDir; |
|
160 |
QByteArray sourceCode; |
|
161 |
QByteArray std_out; |
|
162 |
QByteArray std_err; |
|
163 |
int exitCode; |
|
164 |
QExternalTest::Stage failedStage; |
|
165 |
||
166 |
void clear(); |
|
167 |
bool tryCompile(const QByteArray &body); |
|
168 |
bool tryLink(const QByteArray &body); |
|
169 |
bool tryRun(const QByteArray &body); |
|
170 |
||
171 |
private: |
|
172 |
void removeTemporaryDirectory(); |
|
173 |
bool createTemporaryDirectory(); |
|
174 |
bool prepareSourceCode(const QByteArray &body); |
|
175 |
bool createProjectFile(); |
|
176 |
bool runQmake(); |
|
177 |
bool runMake(Target target); |
|
178 |
bool commonSetup(const QByteArray &body); |
|
179 |
}; |
|
180 |
||
181 |
QExternalTest::QExternalTest() |
|
182 |
: d(new QExternalTestPrivate) |
|
183 |
{ |
|
184 |
} |
|
185 |
||
186 |
QExternalTest::~QExternalTest() |
|
187 |
{ |
|
188 |
delete d; |
|
189 |
} |
|
190 |
||
191 |
QList<QByteArray> QExternalTest::qmakeSettings() const |
|
192 |
{ |
|
193 |
return d->qmakeLines; |
|
194 |
} |
|
195 |
||
196 |
void QExternalTest::setQmakeSettings(const QList<QByteArray> &settings) |
|
197 |
{ |
|
198 |
d->qmakeLines = settings; |
|
199 |
} |
|
200 |
||
201 |
QExternalTest::QtModules QExternalTest::qtModules() const |
|
202 |
{ |
|
203 |
return d->qtModules; |
|
204 |
} |
|
205 |
||
206 |
void QExternalTest::setQtModules(QtModules modules) |
|
207 |
{ |
|
208 |
d->qtModules = modules; |
|
209 |
} |
|
210 |
||
211 |
QExternalTest::ApplicationType QExternalTest::applicationType() const |
|
212 |
{ |
|
213 |
return d->appType; |
|
214 |
} |
|
215 |
||
216 |
void QExternalTest::setApplicationType(ApplicationType type) |
|
217 |
{ |
|
218 |
d->appType = type; |
|
219 |
} |
|
220 |
||
221 |
QStringList QExternalTest::extraProgramSources() const |
|
222 |
{ |
|
223 |
return d->extraProgramSources; |
|
224 |
} |
|
225 |
||
226 |
void QExternalTest::setExtraProgramSources(const QStringList &extra) |
|
227 |
{ |
|
228 |
d->extraProgramSources = extra; |
|
229 |
} |
|
230 |
||
231 |
QByteArray QExternalTest::programHeader() const |
|
232 |
{ |
|
233 |
return d->programHeader; |
|
234 |
} |
|
235 |
||
236 |
void QExternalTest::setProgramHeader(const QByteArray &header) |
|
237 |
{ |
|
238 |
d->programHeader = header; |
|
239 |
} |
|
240 |
||
241 |
bool QExternalTest::tryCompile(const QByteArray &body) |
|
242 |
{ |
|
243 |
return d->tryCompile(body) && d->exitCode == 0; |
|
244 |
} |
|
245 |
||
246 |
bool QExternalTest::tryLink(const QByteArray &body) |
|
247 |
{ |
|
248 |
return d->tryLink(body) && d->exitCode == 0; |
|
249 |
} |
|
250 |
||
251 |
bool QExternalTest::tryRun(const QByteArray &body) |
|
252 |
{ |
|
253 |
return d->tryRun(body) && d->exitCode == 0; |
|
254 |
} |
|
255 |
||
256 |
bool QExternalTest::tryCompileFail(const QByteArray &body) |
|
257 |
{ |
|
258 |
return d->tryCompile(body) && d->exitCode != 0; |
|
259 |
} |
|
260 |
||
261 |
bool QExternalTest::tryLinkFail(const QByteArray &body) |
|
262 |
{ |
|
263 |
return d->tryLink(body) && d->exitCode != 0; |
|
264 |
} |
|
265 |
||
266 |
bool QExternalTest::tryRunFail(const QByteArray &body) |
|
267 |
{ |
|
268 |
return d->tryRun(body) && d->exitCode != 0; |
|
269 |
} |
|
270 |
||
271 |
QExternalTest::Stage QExternalTest::failedStage() const |
|
272 |
{ |
|
273 |
return d->failedStage; |
|
274 |
} |
|
275 |
||
276 |
int QExternalTest::exitCode() const |
|
277 |
{ |
|
278 |
return d->exitCode; |
|
279 |
} |
|
280 |
||
281 |
QByteArray QExternalTest::fullProgramSource() const |
|
282 |
{ |
|
283 |
return d->sourceCode; |
|
284 |
} |
|
285 |
||
286 |
QByteArray QExternalTest::standardOutput() const |
|
287 |
{ |
|
288 |
return d->std_out; |
|
289 |
} |
|
290 |
||
291 |
QByteArray QExternalTest::standardError() const |
|
292 |
{ |
|
293 |
return d->std_err; |
|
294 |
} |
|
295 |
||
296 |
QString QExternalTest::errorReport() const |
|
297 |
{ |
|
298 |
const char *stage = 0; |
|
299 |
switch (d->failedStage) { |
|
300 |
case FileStage: |
|
301 |
stage = "creating files"; |
|
302 |
break; |
|
303 |
case QmakeStage: |
|
304 |
stage = "executing qmake"; |
|
305 |
break; |
|
306 |
case CompilationStage: |
|
307 |
stage = "during compilation"; |
|
308 |
break; |
|
309 |
case LinkStage: |
|
310 |
stage = "during linking"; |
|
311 |
break; |
|
312 |
case RunStage: |
|
313 |
stage = "executing program"; |
|
314 |
break; |
|
315 |
} |
|
316 |
||
317 |
QString report = QString::fromLatin1( |
|
318 |
"External test failed %1 with exit code %4\n" |
|
319 |
"==== standard error: ====\n" |
|
320 |
"%2\n" |
|
321 |
"==== standard output: ====\n" |
|
322 |
"%3\n" |
|
323 |
"==== ====\n"); |
|
324 |
return report.arg(QString::fromLatin1(stage), |
|
325 |
QString::fromLocal8Bit(d->std_err), |
|
326 |
QString::fromLocal8Bit(d->std_out)) |
|
327 |
.arg(d->exitCode); |
|
328 |
} |
|
329 |
||
330 |
// actual execution code |
|
331 |
void QExternalTestPrivate::clear() |
|
332 |
{ |
|
333 |
if (!temporaryDir.isEmpty()) |
|
334 |
removeTemporaryDirectory(); |
|
335 |
||
336 |
sourceCode.clear(); |
|
337 |
std_out.clear(); |
|
338 |
std_err.clear(); |
|
339 |
exitCode = -1; |
|
340 |
failedStage = QExternalTest::FileStage; |
|
341 |
} |
|
342 |
||
343 |
void QExternalTestPrivate::removeTemporaryDirectory() |
|
344 |
{ |
|
345 |
Q_ASSERT(!temporaryDir.isEmpty()); |
|
346 |
removeRecursive(temporaryDir); |
|
347 |
temporaryDir.clear(); |
|
348 |
} |
|
349 |
||
350 |
bool QExternalTestPrivate::prepareSourceCode(const QByteArray &body) |
|
351 |
{ |
|
352 |
sourceCode.clear(); |
|
353 |
sourceCode.reserve(8192); |
|
354 |
||
355 |
sourceCode += programHeader; |
|
356 |
||
357 |
// Add Qt header includes |
|
358 |
if (qtModules & QExternalTest::QtCore) |
|
359 |
sourceCode += "#include <QtCore/QtCore>\n"; |
|
360 |
if (qtModules & QExternalTest::QtGui) |
|
361 |
sourceCode += "#include <QtGui/QtGui>\n"; |
|
362 |
if (qtModules & QExternalTest::QtNetwork) |
|
363 |
sourceCode += "#include <QtNetwork/QtNetwork>\n"; |
|
364 |
if (qtModules & QExternalTest::QtXml) |
|
365 |
sourceCode += "#include <QtXml/QtXml>\n"; |
|
366 |
if (qtModules & QExternalTest::QtXmlPatterns) |
|
367 |
sourceCode += "#include <QtXmlPatterns/QtXmlPatterns>\n"; |
|
368 |
if (qtModules & QExternalTest::QtOpenGL) |
|
369 |
sourceCode += "#include <QtOpenGL/QtOpenGL>\n"; |
|
370 |
if (qtModules & QExternalTest::QtSql) |
|
371 |
sourceCode += "#include <QtSql/QtSql>\n"; |
|
372 |
if (qtModules & QExternalTest::Qt3Support) |
|
373 |
sourceCode += "#include <Qt3Support/Qt3Support>\n"; |
|
374 |
if (qtModules & QExternalTest::QtSvg) |
|
375 |
sourceCode += "#include <QtSvg/QtSvg>\n"; |
|
376 |
if (qtModules & QExternalTest::QtScript) |
|
377 |
sourceCode += "#include <QtScript/QtScript>\n"; |
|
378 |
if (qtModules & QExternalTest::QtTest) |
|
379 |
sourceCode += "#include <QtTest/QtTest>\n"; |
|
380 |
if (qtModules & QExternalTest::QtDBus) |
|
381 |
sourceCode += "#include <QtDBus/QtDBus>\n"; |
|
382 |
if (qtModules & QExternalTest::QtWebKit) |
|
383 |
sourceCode += "#include <QtWebKit/QtWebKit>\n"; |
|
384 |
if (qtModules & QExternalTest::Phonon) |
|
385 |
sourceCode += "#include <Phonon/Phonon>\n"; |
|
386 |
sourceCode += |
|
387 |
"#include <stdlib.h>\n" |
|
388 |
"#include <stddef.h>\n"; |
|
389 |
||
390 |
sourceCode += |
|
391 |
"\n" |
|
392 |
"void q_external_test_user_code()\n" |
|
393 |
"{\n" |
|
394 |
"#include \"user_code.cpp\"\n" |
|
395 |
"}\n" |
|
396 |
"\n" |
|
397 |
"#ifdef Q_OS_WIN\n" |
|
398 |
"#include <windows.h>\n" |
|
399 |
"static void q_test_setup()\n" |
|
400 |
"{\n" |
|
401 |
" SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);\n" |
|
402 |
"}\n" |
|
403 |
"#else\n" |
|
404 |
"static void q_test_setup() { }\n" |
|
405 |
"#endif\n" |
|
406 |
"int main(int argc, char **argv)\n" |
|
407 |
"{\n"; |
|
408 |
||
409 |
switch (appType) { |
|
410 |
applicationless: |
|
411 |
case QExternalTest::Applicationless: |
|
412 |
sourceCode += |
|
413 |
" (void)argc; (void)argv;\n"; |
|
414 |
break; |
|
415 |
||
416 |
coreapplication: |
|
417 |
case QExternalTest::QCoreApplication: |
|
418 |
sourceCode += |
|
419 |
" QCoreApplication app(argc, argv);\n"; |
|
420 |
break; |
|
421 |
||
422 |
case QExternalTest::QApplicationTty: |
|
423 |
sourceCode += |
|
424 |
" QApplication app(argc, argv, QApplication::Tty);\n"; |
|
425 |
break; |
|
426 |
||
427 |
guiapplication: |
|
428 |
case QExternalTest::QApplicationGuiClient: |
|
429 |
sourceCode += |
|
430 |
" QApplication app(argc, argv, QApplication::GuiClient);\n"; |
|
431 |
break; |
|
432 |
||
433 |
case QExternalTest::QApplicationGuiServer: |
|
434 |
sourceCode += |
|
435 |
" QApplication app(argc, argv, QApplication::GuiServer);\n"; |
|
436 |
break; |
|
437 |
||
438 |
case QExternalTest::AutoApplication: |
|
439 |
if (qtModules & QExternalTest::QtGui) |
|
440 |
goto guiapplication; |
|
441 |
if (qtModules == 0) |
|
442 |
goto applicationless; |
|
443 |
goto coreapplication; |
|
444 |
} |
|
445 |
||
446 |
sourceCode += |
|
447 |
" q_test_setup();\n" |
|
448 |
" q_external_test_user_code();\n" |
|
449 |
" return 0;\n" |
|
450 |
"}\n"; |
|
451 |
||
452 |
QFile sourceFile(temporaryDir + QLatin1String("/project.cpp")); |
|
453 |
if (!sourceFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { |
|
454 |
std_err = sourceFile.errorString().toLocal8Bit(); |
|
455 |
return false; |
|
456 |
} |
|
457 |
||
458 |
sourceFile.write(sourceCode); |
|
459 |
sourceFile.close(); |
|
460 |
||
461 |
sourceFile.setFileName(temporaryDir + QLatin1String("/user_code.cpp")); |
|
462 |
if (!sourceFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { |
|
463 |
std_err = sourceFile.errorString().toLocal8Bit(); |
|
464 |
return false; |
|
465 |
} |
|
466 |
sourceFile.write(body); |
|
467 |
||
468 |
return true; |
|
469 |
} |
|
470 |
||
471 |
bool QExternalTestPrivate::createTemporaryDirectory() |
|
472 |
{ |
|
473 |
QDir temp = QDir::temp(); |
|
474 |
QString subdir = QString::fromLatin1("qexternaltest-%1-%2-%3") |
|
475 |
.arg(QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss"))) |
|
476 |
.arg(quintptr(this), 0, 16) |
|
477 |
.arg(qrand()); |
|
478 |
if (!temp.mkdir(subdir)) |
|
479 |
return false; |
|
480 |
||
481 |
if (!temp.cd(subdir)) |
|
482 |
return false; |
|
483 |
||
484 |
temporaryDir = temp.absolutePath(); |
|
485 |
return true; |
|
486 |
} |
|
487 |
||
488 |
bool QExternalTestPrivate::createProjectFile() |
|
489 |
{ |
|
490 |
Q_ASSERT(!temporaryDir.isEmpty()); |
|
491 |
||
492 |
QFile projectFile(temporaryDir + QLatin1String("/project.pro")); |
|
493 |
if (!projectFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { |
|
494 |
std_err = projectFile.errorString().toLocal8Bit(); |
|
495 |
return false; |
|
496 |
} |
|
497 |
||
498 |
projectFile.write( |
|
499 |
"TEMPLATE = app\n" |
|
500 |
"\n" |
|
501 |
"TARGET = externaltest\n" |
|
502 |
"CONFIG -= app_bundle\n" // for the Mac |
|
503 |
"CONFIG -= debug_and_release\n" |
|
504 |
"DESTDIR = .\n" |
|
505 |
"OBJECTS_DIR = .\n" |
|
506 |
"UI_DIR = .\n" |
|
507 |
"MOC_DIR = .\n" |
|
508 |
"RCC_DIR = .\n" |
|
509 |
"HEADERS +=\n" |
|
510 |
"SOURCES += project.cpp\n" |
|
511 |
"QT -= core gui\n" |
|
512 |
"INCLUDEPATH += . "); |
|
513 |
projectFile.write(QFile::encodeName(QDir::currentPath())); |
|
514 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
515 |
#ifndef QT_NO_DEBUG |
0 | 516 |
projectFile.write("\nCONFIG += debug\n"); |
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
517 |
#else |
0 | 518 |
projectFile.write("\nCONFIG += release\n"); |
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
519 |
#endif |
0 | 520 |
|
521 |
QByteArray extraSources = QFile::encodeName(extraProgramSources.join(" ")); |
|
522 |
if (!extraSources.isEmpty()) { |
|
523 |
projectFile.write("SOURCES += "); |
|
524 |
projectFile.write(extraSources); |
|
525 |
projectFile.putChar('\n'); |
|
526 |
} |
|
527 |
||
528 |
// Add Qt modules |
|
529 |
if (qtModules & QExternalTest::QtCore) |
|
530 |
projectFile.write("QT += core\n"); |
|
531 |
if (qtModules & QExternalTest::QtGui) |
|
532 |
projectFile.write("QT += gui\n"); |
|
533 |
if (qtModules & QExternalTest::QtNetwork) |
|
534 |
projectFile.write("QT += network\n"); |
|
535 |
if (qtModules & QExternalTest::QtXml) |
|
536 |
projectFile.write("QT += xml\n"); |
|
537 |
if (qtModules & QExternalTest::QtXmlPatterns) |
|
538 |
projectFile.write("QT += xmlpatterns\n"); |
|
539 |
if (qtModules & QExternalTest::QtOpenGL) |
|
540 |
projectFile.write("QT += opengl\n"); |
|
541 |
if (qtModules & QExternalTest::QtSql) |
|
542 |
projectFile.write("QT += sql\n"); |
|
543 |
if (qtModules & QExternalTest::Qt3Support) |
|
544 |
projectFile.write("QT += qt3support\n"); |
|
545 |
if (qtModules & QExternalTest::QtSvg) |
|
546 |
projectFile.write("QT += svg\n"); |
|
547 |
if (qtModules & QExternalTest::QtScript) |
|
548 |
projectFile.write("QT += script\n"); |
|
549 |
if (qtModules & QExternalTest::QtTest) |
|
550 |
projectFile.write("QT += testlib\n"); |
|
551 |
if (qtModules & QExternalTest::QtDBus) |
|
552 |
projectFile.write("QT += dbus\n"); |
|
553 |
if (qtModules & QExternalTest::QtWebKit) |
|
554 |
projectFile.write("QT += webkit\n"); |
|
555 |
if (qtModules & QExternalTest::Phonon) |
|
556 |
projectFile.write("QT += phonon\n"); |
|
557 |
||
558 |
projectFile.write("\n### User-specified settings start ###\n"); |
|
559 |
foreach (QByteArray line, qmakeLines) { |
|
560 |
projectFile.write(line); |
|
561 |
projectFile.write("\n"); |
|
562 |
} |
|
563 |
projectFile.write("\n### User-specified settings end ###\n"); |
|
564 |
||
565 |
// Use qmake to just compile: |
|
566 |
projectFile.write( |
|
567 |
"\n" |
|
568 |
"test_compile.depends += $(OBJECTS)\n" |
|
569 |
"QMAKE_EXTRA_TARGETS += test_compile\n"); |
|
570 |
||
571 |
// Use qmake to run the app too: |
|
572 |
projectFile.write( |
|
573 |
"\n" |
|
574 |
"unix:test_run.commands = ./$(QMAKE_TARGET)\n" |
|
575 |
"else:test_run.commands = $(QMAKE_TARGET)\n" |
|
576 |
"embedded:test_run.commands += -qws\n" |
|
577 |
"QMAKE_EXTRA_TARGETS += test_run\n"); |
|
578 |
||
579 |
// Use qmake to debug: |
|
580 |
projectFile.write( |
|
581 |
"\n" |
|
582 |
"*-g++* {\n" |
|
583 |
" unix:test_debug.commands = gdb --args ./$(QMAKE_TARGET)\n" |
|
584 |
" else:test_debug.commands = gdb --args $(QMAKE_TARGET)\n" |
|
585 |
" embedded:test_debug.commands += -qws\n" |
|
586 |
" QMAKE_EXTRA_TARGETS += test_debug\n" |
|
587 |
"}\n"); |
|
588 |
||
589 |
// Also use qmake to run the app with valgrind: |
|
590 |
projectFile.write( |
|
591 |
"\n" |
|
592 |
"unix:test_valgrind.commands = valgrind ./$(QMAKE_TARGET)\n" |
|
593 |
"else:test_valgrind.commands = valgrind $(QMAKE_TARGET)\n" |
|
594 |
"embedded:test_valgrind.commands += -qws\n" |
|
595 |
"QMAKE_EXTRA_TARGETS += test_valgrind\n"); |
|
596 |
||
597 |
return true; |
|
598 |
} |
|
599 |
||
600 |
bool QExternalTestPrivate::runQmake() |
|
601 |
{ |
|
602 |
Q_ASSERT(!temporaryDir.isEmpty()); |
|
603 |
if (!createProjectFile()) |
|
604 |
return false; |
|
605 |
||
606 |
failedStage = QExternalTest::QmakeStage; |
|
607 |
QProcess qmake; |
|
608 |
QStringList args; |
|
609 |
args << QLatin1String("-makefile") |
|
610 |
<< QLatin1String("-spec") |
|
611 |
<< makespec() |
|
612 |
<< QLatin1String("project.pro"); |
|
613 |
qmake.setWorkingDirectory(temporaryDir); |
|
614 |
qmake.start(QLatin1String("qmake"), args); |
|
615 |
||
616 |
std_out += "### --- stdout from qmake --- ###\n"; |
|
617 |
std_err += "### --- stderr from qmake --- ###\n"; |
|
618 |
bool ok = qmake.waitForStarted(); |
|
619 |
if (!ok) { |
|
620 |
exitCode = 255; |
|
621 |
std_err += "qmake: "; |
|
622 |
std_err += qmake.errorString().toLocal8Bit(); |
|
623 |
} else { |
|
624 |
ok = qmake.waitForFinished(); |
|
625 |
exitCode = qmake.exitCode(); |
|
626 |
||
627 |
std_out += qmake.readAllStandardOutput(); |
|
628 |
std_err += qmake.readAllStandardError(); |
|
629 |
} |
|
630 |
||
631 |
return ok && exitCode == 0; |
|
632 |
} |
|
633 |
||
634 |
bool QExternalTestPrivate::runMake(Target target) |
|
635 |
{ |
|
636 |
Q_ASSERT(!temporaryDir.isEmpty()); |
|
637 |
||
638 |
QExternalProcess make; |
|
639 |
make.setWorkingDirectory(temporaryDir); |
|
640 |
||
641 |
QStringList environment = QProcess::systemEnvironment(); |
|
642 |
environment += QLatin1String("LC_ALL=C"); |
|
643 |
make.setEnvironment(environment); |
|
644 |
||
645 |
QStringList args; |
|
646 |
QProcess::ProcessChannelMode channelMode = QProcess::SeparateChannels; |
|
647 |
if (target == Compile) { |
|
648 |
args << QLatin1String("test_compile"); |
|
649 |
} else if (target == Run) { |
|
650 |
QByteArray run = qgetenv("QTEST_EXTERNAL_RUN"); |
|
651 |
if (run == "valgrind") |
|
652 |
args << QLatin1String("test_valgrind"); |
|
653 |
else if (run == "debug") |
|
654 |
args << QLatin1String("test_debug"); |
|
655 |
else |
|
656 |
args << QLatin1String("test_run"); |
|
657 |
if (!run.isEmpty()) |
|
658 |
channelMode = QProcess::ForwardedChannels; |
|
659 |
} |
|
660 |
||
661 |
make.setProcessChannelMode(channelMode); |
|
662 |
||
663 |
#if defined(Q_OS_WIN) && !defined(Q_CC_MINGW) |
|
664 |
make.start(QLatin1String("nmake.exe"), args); |
|
665 |
make.waitForStarted(); |
|
666 |
#else |
|
667 |
static const char makes[] = |
|
668 |
# ifdef Q_CC_MINGW |
|
669 |
"mingw32-make.exe\0" |
|
670 |
# endif |
|
671 |
"gmake\0" |
|
672 |
"make\0"; |
|
673 |
for (const char *p = makes; *p; p += strlen(p) + 1) { |
|
674 |
make.start(QLatin1String(p), args); |
|
675 |
if (make.waitForStarted()) |
|
676 |
break; |
|
677 |
} |
|
678 |
#endif |
|
679 |
||
680 |
if (make.state() != QProcess::Running) { |
|
681 |
exitCode = 255; |
|
682 |
std_err += "make: "; |
|
683 |
std_err += make.errorString().toLocal8Bit(); |
|
684 |
return false; |
|
685 |
} |
|
686 |
||
687 |
make.closeWriteChannel(); |
|
688 |
bool ok = make.waitForFinished(channelMode == QProcess::ForwardedChannels ? -1 : 60000); |
|
689 |
if (!ok) |
|
690 |
make.terminate(); |
|
691 |
exitCode = make.exitCode(); |
|
692 |
std_out += make.readAllStandardOutput(); |
|
693 |
std_err += make.readAllStandardError(); |
|
694 |
||
695 |
return ok; |
|
696 |
} |
|
697 |
||
698 |
bool QExternalTestPrivate::commonSetup(const QByteArray &body) |
|
699 |
{ |
|
700 |
clear(); |
|
701 |
||
702 |
if (!createTemporaryDirectory()) |
|
703 |
return false; |
|
704 |
if (!createProjectFile()) |
|
705 |
return false; |
|
706 |
if (!prepareSourceCode(body)) |
|
707 |
return false; |
|
708 |
if (!runQmake()) |
|
709 |
return false; |
|
710 |
return true; |
|
711 |
} |
|
712 |
||
713 |
bool QExternalTestPrivate::tryCompile(const QByteArray &body) |
|
714 |
{ |
|
715 |
if (!commonSetup(body)) |
|
716 |
return false; |
|
717 |
||
718 |
// compile |
|
719 |
failedStage = QExternalTest::CompilationStage; |
|
720 |
std_out += "\n### --- stdout from make (compilation) --- ###\n"; |
|
721 |
std_err += "\n### --- stderr from make (compilation) --- ###\n"; |
|
722 |
return runMake(Compile); |
|
723 |
} |
|
724 |
||
725 |
bool QExternalTestPrivate::tryLink(const QByteArray &body) |
|
726 |
{ |
|
727 |
if (!tryCompile(body) || exitCode != 0) |
|
728 |
return false; |
|
729 |
||
730 |
// link |
|
731 |
failedStage = QExternalTest::LinkStage; |
|
732 |
std_out += "\n### --- stdout from make (linking) --- ###\n"; |
|
733 |
std_err += "\n### --- stderr from make (linking) --- ###\n"; |
|
734 |
return runMake(Link); |
|
735 |
} |
|
736 |
||
737 |
bool QExternalTestPrivate::tryRun(const QByteArray &body) |
|
738 |
{ |
|
739 |
if (!tryLink(body) || exitCode != 0) |
|
740 |
return false; |
|
741 |
||
742 |
// run |
|
743 |
failedStage = QExternalTest::RunStage; |
|
744 |
std_out += "\n### --- stdout from process --- ###\n"; |
|
745 |
std_err += "\n### --- stderr from process --- ###\n"; |
|
746 |
return runMake(Run); |
|
747 |
} |
|
748 |
} |
|
749 |
QT_END_NAMESPACE |