|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 #include "testcompiler.h" |
|
43 |
|
44 #include <QProcess> |
|
45 #include <QDir> |
|
46 |
|
47 static QString targetName( BuildType buildMode, const QString& target, const QString& version ) |
|
48 { |
|
49 Q_UNUSED(version); |
|
50 QString targetName = target; |
|
51 |
|
52 #if defined (Q_OS_WIN32) |
|
53 switch (buildMode) |
|
54 { |
|
55 case Exe: // app |
|
56 targetName.append(".exe"); |
|
57 break; |
|
58 case Dll: // dll |
|
59 if (!version.isEmpty()) |
|
60 targetName.append(version.section(".", 0, 0)); |
|
61 targetName.append(".dll"); |
|
62 break; |
|
63 case Lib: // lib |
|
64 #ifdef Q_CC_GNU |
|
65 targetName.prepend("lib"); |
|
66 targetName.append(".a"); |
|
67 #else |
|
68 targetName.append(".lib"); |
|
69 #endif |
|
70 break; |
|
71 case Plain: |
|
72 // no conversion |
|
73 break; |
|
74 } |
|
75 #elif defined( Q_OS_MAC ) |
|
76 switch (buildMode) |
|
77 { |
|
78 case Exe: // app |
|
79 targetName += ".app/Contents/MacOS/" + target.section('/', -1); |
|
80 break; |
|
81 case Dll: // dll |
|
82 targetName.prepend("lib"); |
|
83 targetName.append("." + version + ".dylib"); |
|
84 break; |
|
85 case Lib: // lib |
|
86 targetName.prepend("lib"); |
|
87 targetName.append(".a"); |
|
88 break; |
|
89 case Plain: |
|
90 // no conversion |
|
91 break; |
|
92 } |
|
93 #else |
|
94 switch (buildMode) |
|
95 { |
|
96 case Exe: // app |
|
97 break; |
|
98 case Dll: // dll |
|
99 targetName.prepend("lib"); |
|
100 #if defined (Q_OS_HPUX) && !defined (__ia64) |
|
101 targetName.append(".sl"); |
|
102 #elif defined (Q_OS_AIX) |
|
103 targetName.append(".a"); |
|
104 #else |
|
105 targetName.append(".so"); |
|
106 #endif |
|
107 break; |
|
108 case Lib: // lib |
|
109 targetName.prepend("lib"); |
|
110 targetName.append(".a"); |
|
111 break; |
|
112 case Plain: |
|
113 // no conversion |
|
114 break; |
|
115 } |
|
116 #endif |
|
117 return targetName; |
|
118 } |
|
119 |
|
120 TestCompiler::TestCompiler() |
|
121 { |
|
122 setBaseCommands( "", "" ); |
|
123 } |
|
124 |
|
125 TestCompiler::~TestCompiler() |
|
126 { |
|
127 } |
|
128 |
|
129 bool TestCompiler::runCommand( QString cmdline ) |
|
130 { |
|
131 testOutput_.append("Running command: " + cmdline); |
|
132 |
|
133 QProcess child; |
|
134 if (!environment_.empty()) |
|
135 child.setEnvironment(QProcess::systemEnvironment() + environment_); |
|
136 |
|
137 child.start(cmdline); |
|
138 if (!child.waitForStarted(-1)) { |
|
139 testOutput_.append( "Unable to start child process." ); |
|
140 return false; |
|
141 } |
|
142 |
|
143 bool failed = false; |
|
144 child.setReadChannel(QProcess::StandardError); |
|
145 while (QProcess::Running == child.state()) { |
|
146 if (child.waitForReadyRead(1000)) { |
|
147 QString output = child.readAllStandardError(); |
|
148 testOutput_.append(output); |
|
149 |
|
150 output.prepend('\n'); |
|
151 if (output.contains("\nProject MESSAGE: FAILED")) |
|
152 failed = true; |
|
153 } |
|
154 } |
|
155 |
|
156 child.waitForFinished(-1); |
|
157 |
|
158 return failed |
|
159 ? false |
|
160 : (child.exitStatus() == QProcess::NormalExit) |
|
161 && (child.exitCode() == 0); |
|
162 } |
|
163 |
|
164 void TestCompiler::setBaseCommands( QString makeCmd, QString qmakeCmd ) |
|
165 { |
|
166 makeCmd_ = makeCmd; |
|
167 qmakeCmd_ = qmakeCmd; |
|
168 } |
|
169 |
|
170 void TestCompiler::resetEnvironment() |
|
171 { |
|
172 environment_.clear(); |
|
173 } |
|
174 |
|
175 void TestCompiler::addToEnvironment( QString varAssignment ) |
|
176 { |
|
177 environment_.push_back(varAssignment); |
|
178 } |
|
179 |
|
180 bool TestCompiler::makeClean( const QString &workPath ) |
|
181 { |
|
182 QDir D; |
|
183 if (!D.exists(workPath)) { |
|
184 testOutput_.append( "Directory '" + workPath + "' doesn't exist" ); |
|
185 return false; |
|
186 } |
|
187 |
|
188 D.setCurrent(workPath); |
|
189 QFileInfo Fi( workPath + "/Makefile"); |
|
190 if (Fi.exists()) |
|
191 // Run make clean |
|
192 return runCommand( makeCmd_ + " clean" ); |
|
193 |
|
194 return true; |
|
195 } |
|
196 |
|
197 bool TestCompiler::makeDistClean( const QString &workPath ) |
|
198 { |
|
199 QDir D; |
|
200 if (!D.exists(workPath)) { |
|
201 testOutput_.append( "Directory '" + workPath + "' doesn't exist" ); |
|
202 return false; |
|
203 } |
|
204 |
|
205 D.setCurrent(workPath); |
|
206 QFileInfo Fi( workPath + "/Makefile"); |
|
207 if (Fi.exists()) |
|
208 // Run make distclean |
|
209 return runCommand( makeCmd_ + " distclean" ); |
|
210 |
|
211 return true; |
|
212 |
|
213 } |
|
214 |
|
215 bool TestCompiler::qmake( const QString &workDir, const QString &proName, const QString &buildDir ) |
|
216 { |
|
217 QDir D; |
|
218 D.setCurrent( workDir ); |
|
219 |
|
220 if (D.exists("Makefile")) |
|
221 D.remove("Makefile"); |
|
222 |
|
223 QString projectFile = proName; |
|
224 QString makeFile = buildDir; |
|
225 if (!projectFile.endsWith(".pro")) |
|
226 projectFile += ".pro"; |
|
227 if (!makeFile.isEmpty() && !makeFile.endsWith('/')) |
|
228 makeFile += '/'; |
|
229 makeFile += "Makefile"; |
|
230 |
|
231 // Now start qmake and generate the makefile |
|
232 return runCommand( qmakeCmd_ + " " + projectFile + " -o " + makeFile ); |
|
233 } |
|
234 |
|
235 bool TestCompiler::make( const QString &workPath, const QString &target ) |
|
236 { |
|
237 QDir D; |
|
238 D.setCurrent( workPath ); |
|
239 |
|
240 QString cmdline = makeCmd_; |
|
241 if ( cmdline.contains("nmake", Qt::CaseInsensitive) ) |
|
242 cmdline.append(" /NOLOGO"); |
|
243 if ( !target.isEmpty() ) |
|
244 cmdline += " " + target; |
|
245 |
|
246 return runCommand( cmdline ); |
|
247 } |
|
248 |
|
249 bool TestCompiler::exists( const QString &destDir, const QString &exeName, BuildType buildType, const QString &version ) |
|
250 { |
|
251 QFileInfo f(destDir + "/" + targetName(buildType, exeName, version)); |
|
252 return f.exists(); |
|
253 } |
|
254 |
|
255 bool TestCompiler::removeMakefile( const QString &workPath ) |
|
256 { |
|
257 QDir D; |
|
258 D.setCurrent( workPath ); |
|
259 if ( D.exists( "Makefile" ) ) |
|
260 return D.remove( "Makefile" ); |
|
261 else |
|
262 return true; |
|
263 } |
|
264 |
|
265 QString TestCompiler::commandOutput() const |
|
266 { |
|
267 #ifndef Q_OS_WIN |
|
268 return testOutput_.join("\n"); |
|
269 #else |
|
270 return testOutput_.join("\r\n"); |
|
271 #endif |
|
272 } |
|
273 |
|
274 void TestCompiler::clearCommandOutput() |
|
275 { |
|
276 testOutput_.clear(); |
|
277 } |