2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2010-01-20 14:31:44 +01:00
|
|
|
|
2012-05-02 18:34:25 +02:00
|
|
|
#include "qmakeglobals.h"
|
2013-05-29 20:18:51 +02:00
|
|
|
#include "qmakevfs.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
|
|
|
|
2012-07-06 20:34:29 +02:00
|
|
|
static void print(const QString &fileName, int lineNo, int type, const QString &msg)
|
2010-06-18 13:30:03 +02:00
|
|
|
{
|
2012-07-06 20:34:29 +02:00
|
|
|
QString pfx = ((type & QMakeHandler::CategoryMask) == QMakeHandler::WarningMessage)
|
|
|
|
? QString::fromLatin1("WARNING: ") : QString();
|
2012-08-22 11:19:54 +02:00
|
|
|
if (lineNo > 0)
|
2012-07-06 20:34:29 +02:00
|
|
|
qWarning("%s%s:%d: %s", qPrintable(pfx), qPrintable(fileName), lineNo, qPrintable(msg));
|
2012-08-22 11:19:54 +02:00
|
|
|
else if (lineNo)
|
|
|
|
qWarning("%s%s: %s", qPrintable(pfx), qPrintable(fileName), qPrintable(msg));
|
2010-06-18 13:30:03 +02:00
|
|
|
else
|
2012-07-06 20:34:29 +02:00
|
|
|
qWarning("%s%s", qPrintable(pfx), qPrintable(msg));
|
2010-06-18 13:30:03 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 20:28:16 +02:00
|
|
|
class EvalHandler : public QMakeHandler {
|
2010-06-18 13:30:03 +02:00
|
|
|
public:
|
2012-07-06 20:34:29 +02:00
|
|
|
virtual void message(int type, const QString &msg, const QString &fileName, int lineNo)
|
|
|
|
{ print(fileName, lineNo, type, msg); }
|
2010-06-18 19:48:07 +02:00
|
|
|
|
2016-01-07 15:53:41 +01:00
|
|
|
virtual void fileMessage(int /*type*/, const QString &msg)
|
2010-06-18 13:30:03 +02:00
|
|
|
{ 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 int evaluate(const QString &fileName, const QString &in_pwd, const QString &out_pwd,
|
2016-10-21 20:23:07 +02:00
|
|
|
bool cumulative, QMakeGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
|
2013-05-29 20:18:51 +02:00
|
|
|
int level)
|
2010-01-20 14:31:44 +01:00
|
|
|
{
|
|
|
|
static QSet<QString> visited;
|
|
|
|
if (visited.contains(fileName))
|
|
|
|
return 0;
|
|
|
|
visited.insert(fileName);
|
|
|
|
|
2013-05-29 20:18:51 +02:00
|
|
|
ProFileEvaluator visitor(option, parser, vfs, &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;
|
2012-08-15 16:42:21 +02:00
|
|
|
if (!(pro = parser->parsedProFile(fileName))) {
|
|
|
|
if (!QFile::exists(fileName)) {
|
|
|
|
qCritical("Input file %s does not exist.", qPrintable(fileName));
|
|
|
|
return 3;
|
|
|
|
}
|
2010-01-20 14:31:44 +01:00
|
|
|
return 2;
|
2012-08-15 16:42:21 +02:00
|
|
|
}
|
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))
|
2012-08-01 17:48:53 +02:00
|
|
|
realDir = QFileInfo(visitor.value(subDirKey)).filePath();
|
2010-01-20 14:31:44 +01:00
|
|
|
else if (visitor.contains(subDirFileKey))
|
2012-08-01 17:48:53 +02:00
|
|
|
realDir = QFileInfo(visitor.value(subDirFileKey)).filePath();
|
2010-01-20 14:31:44 +01:00
|
|
|
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++;
|
|
|
|
}
|
2013-05-29 20:18:51 +02:00
|
|
|
evaluate(inFile, inPwd, outPwd, cumulative, option, parser, vfs, 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);
|
|
|
|
|
2016-10-21 20:23:07 +02:00
|
|
|
QMakeGlobals option;
|
2012-07-24 14:55:58 +02:00
|
|
|
QString qmake = QString::fromLocal8Bit(qgetenv("TESTREADER_QMAKE"));
|
2022-07-25 09:54:07 +02:00
|
|
|
if (qmake.isEmpty())
|
2022-02-01 12:08:59 +01:00
|
|
|
qmake = QLibraryInfo::path(QLibraryInfo::BinariesPath) + QLatin1String("/qmake");
|
2012-07-24 14:55:58 +02:00
|
|
|
option.qmake_abslocation = QDir::cleanPath(qmake);
|
2012-06-18 18:16:50 +02:00
|
|
|
option.initProperties();
|
2010-01-20 14:31:44 +01:00
|
|
|
|
2012-08-15 18:11:54 +02:00
|
|
|
QStringList args = app.arguments();
|
|
|
|
args.removeFirst();
|
|
|
|
int level = -1; // verbose
|
|
|
|
bool cumulative = false;
|
|
|
|
QString file;
|
|
|
|
QString in_pwd;
|
|
|
|
QString out_pwd;
|
|
|
|
QMakeCmdLineParserState state(QDir::currentPath());
|
|
|
|
for (int pos = 0; ; ) {
|
|
|
|
QMakeGlobals::ArgumentReturn cmdRet = option.addCommandLineArguments(state, args, &pos);
|
|
|
|
if (cmdRet == QMakeGlobals::ArgumentsOk)
|
|
|
|
break;
|
|
|
|
if (cmdRet == QMakeGlobals::ArgumentMalformed) {
|
|
|
|
qCritical("argument %s needs a parameter", qPrintable(args.at(pos - 1)));
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
Q_ASSERT(cmdRet == QMakeGlobals::ArgumentUnknown);
|
|
|
|
QString arg = args.at(pos++);
|
|
|
|
if (arg == QLatin1String("-v")) {
|
|
|
|
level = 0;
|
2012-08-28 19:24:30 +02:00
|
|
|
} else if (arg == QLatin1String("-d")) {
|
|
|
|
option.debugLevel++;
|
2012-08-15 18:11:54 +02:00
|
|
|
} else if (arg == QLatin1String("-c")) {
|
|
|
|
cumulative = true;
|
|
|
|
} else if (arg.startsWith(QLatin1Char('-'))) {
|
|
|
|
qCritical("unrecognized option %s", qPrintable(arg));
|
|
|
|
return 3;
|
|
|
|
} else if (file.isEmpty()) {
|
|
|
|
QFileInfo infi(arg);
|
|
|
|
file = QDir::cleanPath(infi.absoluteFilePath());
|
|
|
|
in_pwd = QDir::cleanPath(infi.absolutePath());
|
|
|
|
} else if (out_pwd.isEmpty()) {
|
|
|
|
out_pwd = QDir::cleanPath(QFileInfo(arg).absoluteFilePath());
|
|
|
|
} else {
|
|
|
|
qCritical("excess argument '%s'", qPrintable(arg));
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (file.isEmpty()) {
|
2012-08-28 19:24:30 +02:00
|
|
|
qCritical("usage: testreader [-v] [-d [-d]] [-c] <filenme> [<out_pwd>] [<variable assignments>]");
|
2012-08-15 18:11:54 +02:00
|
|
|
return 3;
|
|
|
|
}
|
2016-07-09 09:48:27 -04:00
|
|
|
option.commitCommandLineArguments(state);
|
|
|
|
option.useEnvironment();
|
2012-08-15 18:11:54 +02:00
|
|
|
if (out_pwd.isEmpty())
|
|
|
|
out_pwd = in_pwd;
|
2012-07-25 19:10:07 +02:00
|
|
|
option.setDirectories(in_pwd, out_pwd);
|
2010-01-20 14:31:44 +01:00
|
|
|
|
2013-05-29 20:18:51 +02:00
|
|
|
QMakeVfs vfs;
|
|
|
|
QMakeParser parser(0, &vfs, &evalHandler);
|
|
|
|
return evaluate(file, in_pwd, out_pwd, cumulative, &option, &parser, &vfs, level);
|
2010-01-20 14:31:44 +01:00
|
|
|
}
|