| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-01-26 18:33:46 +01:00
										 |  |  | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** This file may be used under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  | ** License version 2.1 as published by the Free Software Foundation and | 
					
						
							|  |  |  | ** appearing in the file LICENSE.LGPL included in the packaging of this file. | 
					
						
							|  |  |  | ** Please review the following information to ensure the GNU Lesser General | 
					
						
							|  |  |  | ** Public License version 2.1 requirements will be met: | 
					
						
							|  |  |  | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** rights. These rights are described in the Nokia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** Other Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used in accordance with the terms and | 
					
						
							|  |  |  | ** conditions contained in a signed written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Nokia at qt-info@nokia.com. | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-02 18:34:25 +02:00
										 |  |  | #include "qmakeglobals.h"
 | 
					
						
							| 
									
										
										
										
											2012-05-02 15:39:02 +02:00
										 |  |  | #include "qmakeparser.h"
 | 
					
						
							| 
									
										
										
										
											2012-05-02 18:59:46 +02:00
										 |  |  | #include "qmakeevaluator.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | #include "profileevaluator.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 10:42:41 +01:00
										 |  |  | #include <QCoreApplication>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QDir>
 | 
					
						
							|  |  |  | #include <QFile>
 | 
					
						
							|  |  |  | #include <QFileInfo>
 | 
					
						
							|  |  |  | #include <QLibraryInfo>
 | 
					
						
							|  |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QStringList>
 | 
					
						
							|  |  |  | #include <QTextCodec>
 | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-18 13:30:03 +02:00
										 |  |  | static void print(const QString &fileName, int lineNo, const QString &msg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (lineNo) | 
					
						
							|  |  |  |         qWarning("%s(%d): %s", qPrintable(fileName), lineNo, qPrintable(msg)); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         qWarning("%s", qPrintable(msg)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-11 20:28:16 +02:00
										 |  |  | class EvalHandler : public QMakeHandler { | 
					
						
							| 
									
										
										
										
											2010-06-18 13:30:03 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     virtual void parseError(const QString &fileName, int lineNo, const QString &msg) | 
					
						
							|  |  |  |         { print(fileName, lineNo, msg); } | 
					
						
							| 
									
										
										
										
											2010-06-18 19:48:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-18 13:30:03 +02:00
										 |  |  |     virtual void configError(const QString &msg) | 
					
						
							|  |  |  |         { qWarning("%s", qPrintable(msg)); } | 
					
						
							|  |  |  |     virtual void evalError(const QString &fileName, int lineNo, const QString &msg) | 
					
						
							|  |  |  |         { print(fileName, lineNo, msg); } | 
					
						
							|  |  |  |     virtual void fileMessage(const QString &msg) | 
					
						
							|  |  |  |         { qWarning("%s", qPrintable(msg)); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void aboutToEval(ProFile *, ProFile *, EvalFileType) {} | 
					
						
							|  |  |  |     virtual void doneWithEval(ProFile *) {} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static EvalHandler evalHandler; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | static QString value(ProFileEvaluator &reader, const QString &variable) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList vals = reader.values(variable); | 
					
						
							|  |  |  |     if (!vals.isEmpty()) | 
					
						
							|  |  |  |         return vals.first(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return QString(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int evaluate(const QString &fileName, const QString &in_pwd, const QString &out_pwd, | 
					
						
							| 
									
										
										
										
											2012-05-02 15:39:02 +02:00
										 |  |  |                     bool cumulative, QMakeGlobals *option, QMakeParser *parser, int level) | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     static QSet<QString> visited; | 
					
						
							|  |  |  |     if (visited.contains(fileName)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     visited.insert(fileName); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-18 19:48:07 +02:00
										 |  |  |     ProFileEvaluator visitor(option, parser, &evalHandler); | 
					
						
							| 
									
										
										
										
											2011-05-31 19:19:34 +02:00
										 |  |  | #ifdef PROEVALUATOR_CUMULATIVE
 | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |     visitor.setCumulative(cumulative); | 
					
						
							| 
									
										
										
										
											2011-05-31 19:19:34 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |     visitor.setOutputDir(out_pwd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ProFile *pro; | 
					
						
							| 
									
										
										
										
											2010-06-18 19:48:07 +02:00
										 |  |  |     if (!(pro = parser->parsedProFile(fileName))) | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |         return 2; | 
					
						
							| 
									
										
										
										
											2010-04-19 22:36:24 +02:00
										 |  |  |     if (!visitor.accept(pro)) { | 
					
						
							| 
									
										
										
										
											2010-06-15 13:44:19 +02:00
										 |  |  |         pro->deref(); | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |         return 2; | 
					
						
							| 
									
										
										
										
											2010-04-19 22:36:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (visitor.templateType() == ProFileEvaluator::TT_Subdirs) { | 
					
						
							| 
									
										
										
										
											2010-04-20 11:59:07 +02:00
										 |  |  |         QStringList subdirs = visitor.values(QLatin1String("SUBDIRS")); | 
					
						
							|  |  |  |         subdirs.removeDuplicates(); | 
					
						
							|  |  |  |         foreach (const QString &subDirVar, subdirs) { | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |             QString realDir; | 
					
						
							|  |  |  |             const QString subDirKey = subDirVar + QLatin1String(".subdir"); | 
					
						
							|  |  |  |             const QString subDirFileKey = subDirVar + QLatin1String(".file"); | 
					
						
							|  |  |  |             if (visitor.contains(subDirKey)) | 
					
						
							|  |  |  |                 realDir = QFileInfo(value(visitor, subDirKey)).filePath(); | 
					
						
							|  |  |  |             else if (visitor.contains(subDirFileKey)) | 
					
						
							|  |  |  |                 realDir = QFileInfo(value(visitor, subDirFileKey)).filePath(); | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 realDir = subDirVar; | 
					
						
							|  |  |  |             QFileInfo info(realDir); | 
					
						
							|  |  |  |             if (!info.isAbsolute()) | 
					
						
							|  |  |  |                 info.setFile(in_pwd + QLatin1Char('/') + realDir); | 
					
						
							|  |  |  |             if (info.isDir()) | 
					
						
							|  |  |  |                 info.setFile(QString::fromLatin1("%1/%2.pro").arg(info.filePath(), info.fileName())); | 
					
						
							|  |  |  |             if (!info.exists()) { | 
					
						
							| 
									
										
										
										
											2010-02-02 19:00:57 +01:00
										 |  |  |                 qDebug() << "Could not find sub dir" << info.filePath(); | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-06 21:07:25 +02:00
										 |  |  |             QString inFile = QDir::cleanPath(info.absoluteFilePath()), | 
					
						
							|  |  |  |                     inPwd = QDir::cleanPath(info.path()), | 
					
						
							|  |  |  |                     outPwd = QDir::cleanPath(QDir(out_pwd).absoluteFilePath( | 
					
						
							|  |  |  |                             QDir(in_pwd).relativeFilePath(info.path()))); | 
					
						
							|  |  |  |             int nlevel = level; | 
					
						
							|  |  |  |             if (nlevel >= 0) { | 
					
						
							|  |  |  |                 printf("%sReading %s%s\n", QByteArray().fill(' ', nlevel).constData(), | 
					
						
							|  |  |  |                        qPrintable(inFile), (inPwd == outPwd) ? "" : | 
					
						
							|  |  |  |                        qPrintable(QString(QLatin1String(" [") + outPwd + QLatin1Char(']')))); | 
					
						
							|  |  |  |                 fflush(stdout); | 
					
						
							|  |  |  |                 nlevel++; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-06-18 19:48:07 +02:00
										 |  |  |             evaluate(inFile, inPwd, outPwd, cumulative, option, parser, nlevel); | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-15 13:44:19 +02:00
										 |  |  |     pro->deref(); | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char **argv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QCoreApplication app(argc, argv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QStringList args = app.arguments(); | 
					
						
							|  |  |  |     args.removeFirst(); | 
					
						
							| 
									
										
										
										
											2010-04-06 21:07:25 +02:00
										 |  |  |     int level = -1; // verbose
 | 
					
						
							|  |  |  |     if (args.count() && args.first() == QLatin1String("-v")) | 
					
						
							|  |  |  |         level = 0, args.removeFirst(); | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  |     if (args.count() < 2) | 
					
						
							| 
									
										
										
										
											2011-03-18 20:03:22 +01:00
										 |  |  |         qFatal("need at least two arguments: [-v] <cumulative?> <filenme> [<out_pwd> [<qmake options>]]"); | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-02 15:20:08 +02:00
										 |  |  |     QMakeGlobals option; | 
					
						
							| 
									
										
										
										
											2011-06-01 16:01:22 +02:00
										 |  |  |     option.initProperties(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/qmake")); | 
					
						
							| 
									
										
										
										
											2011-03-18 20:03:22 +01:00
										 |  |  |     if (args.count() >= 4) | 
					
						
							|  |  |  |         option.setCommandLineArguments(args.mid(3)); | 
					
						
							| 
									
										
										
										
											2012-06-11 20:28:16 +02:00
										 |  |  |     QMakeParser parser(0, &evalHandler); | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool cumulative = args[0] == QLatin1String("true"); | 
					
						
							|  |  |  |     QFileInfo infi(args[1]); | 
					
						
							|  |  |  |     QString file = infi.absoluteFilePath(); | 
					
						
							|  |  |  |     QString in_pwd = infi.absolutePath(); | 
					
						
							|  |  |  |     QString out_pwd = (args.count() > 2) ? QFileInfo(args[2]).absoluteFilePath() : in_pwd; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-18 19:48:07 +02:00
										 |  |  |     return evaluate(file, in_pwd, out_pwd, cumulative, &option, &parser, level); | 
					
						
							| 
									
										
										
										
											2010-01-20 14:31:44 +01:00
										 |  |  | } |