2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:03:39 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 03:06:31 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-05-24 09:34:08 +00: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.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-24 09:34:08 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2011-05-24 09:34:08 +00: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.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "project.h"
|
2012-09-05 16:29:19 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#include "option.h"
|
2012-09-03 18:57:59 +00:00
|
|
|
#include <qmakeevaluator_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include <qdir.h>
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
#include <stdio.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-03 18:57:59 +00:00
|
|
|
using namespace QMakeInternal;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeProject::QMakeProject()
|
|
|
|
: QMakeEvaluator(Option::globals, Option::parser, &Option::evalHandler)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeProject::QMakeProject(QMakeProject *p)
|
|
|
|
: QMakeEvaluator(Option::globals, Option::parser, &Option::evalHandler)
|
2012-04-27 16:34:09 +00:00
|
|
|
{
|
2012-09-05 16:29:19 +00:00
|
|
|
initFrom(*p);
|
2012-04-27 16:34:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 19:56:16 +00:00
|
|
|
bool QMakeProject::boolRet(VisitReturn vr)
|
|
|
|
{
|
|
|
|
if (vr == ReturnError)
|
|
|
|
exit(3);
|
|
|
|
Q_ASSERT(vr == ReturnTrue || vr == ReturnFalse);
|
|
|
|
return vr != ReturnFalse;
|
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
bool QMakeProject::read(const QString &project, LoadFlags what)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-09-05 16:29:19 +00:00
|
|
|
m_projectFile = project;
|
|
|
|
setOutputDir(Option::output_dir);
|
|
|
|
QString absproj = (project == QLatin1String("-"))
|
|
|
|
? QLatin1String("(stdin)")
|
|
|
|
: QDir::cleanPath(QDir(qmake_getpwd()).absoluteFilePath(project));
|
2012-09-19 19:56:16 +00:00
|
|
|
return boolRet(evaluateFile(absproj, QMakeHandler::EvalProjectFile, what));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
static ProStringList prepareBuiltinArgs(const QList<ProStringList> &args)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-09-05 16:29:19 +00:00
|
|
|
ProStringList ret;
|
|
|
|
ret.reserve(args.size());
|
|
|
|
foreach (const ProStringList &arg, args)
|
2012-05-18 18:00:23 +00:00
|
|
|
ret << arg.join(' ');
|
2011-04-27 10:05:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
bool QMakeProject::test(const ProKey &func, const QList<ProStringList> &args)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-09-05 16:29:19 +00:00
|
|
|
m_current.clear();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-03 18:57:59 +00:00
|
|
|
if (int func_t = statics.functions.value(func))
|
2012-09-19 19:56:16 +00:00
|
|
|
return boolRet(evaluateBuiltinConditional(func_t, func, prepareBuiltinArgs(args)));
|
2012-09-03 18:57:59 +00:00
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QHash<ProKey, ProFunctionDef>::ConstIterator it =
|
|
|
|
m_functionDefs.testFunctions.constFind(func);
|
|
|
|
if (it != m_functionDefs.testFunctions.constEnd())
|
2012-09-19 19:56:16 +00:00
|
|
|
return boolRet(evaluateBoolFunction(*it, args, func));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-03 18:57:59 +00:00
|
|
|
evalError(QStringLiteral("'%1' is not a recognized test function.")
|
|
|
|
.arg(func.toQString(m_tmp1)));
|
|
|
|
return false;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QStringList QMakeProject::expand(const ProKey &func, const QList<ProStringList> &args)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-09-05 16:29:19 +00:00
|
|
|
m_current.clear();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-03 18:57:59 +00:00
|
|
|
if (int func_t = statics.expands.value(func))
|
|
|
|
return evaluateBuiltinExpand(func_t, func, prepareBuiltinArgs(args)).toQStringList();
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QHash<ProKey, ProFunctionDef>::ConstIterator it =
|
|
|
|
m_functionDefs.replaceFunctions.constFind(func);
|
2012-09-19 19:56:16 +00:00
|
|
|
if (it != m_functionDefs.replaceFunctions.constEnd()) {
|
|
|
|
QMakeProject::VisitReturn vr;
|
|
|
|
ProStringList ret = evaluateFunction(*it, args, &vr);
|
|
|
|
if (vr == QMakeProject::ReturnError)
|
|
|
|
exit(3);
|
|
|
|
return ret.toQStringList();
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-03 18:57:59 +00:00
|
|
|
evalError(QStringLiteral("'%1' is not a recognized replace function.")
|
|
|
|
.arg(func.toQString(m_tmp1)));
|
|
|
|
return QStringList();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString QMakeProject::expand(const QString &expr, const QString &where, int line)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString ret;
|
|
|
|
if (ProFile *pro = m_parser->parsedProBlock(expr, where, line, QMakeParser::ValueGrammar)) {
|
|
|
|
if (pro->isOk()) {
|
|
|
|
m_current.pro = pro;
|
|
|
|
m_current.line = 0;
|
|
|
|
const ushort *tokPtr = pro->tokPtr();
|
|
|
|
ProStringList result = expandVariableReferences(tokPtr, 1, true);
|
|
|
|
if (!result.isEmpty())
|
|
|
|
ret = result.at(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-09-05 16:29:19 +00:00
|
|
|
pro->deref();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-04-17 12:30:15 +00:00
|
|
|
return ret;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
bool QMakeProject::isEmpty(const ProKey &v) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-09-05 16:29:19 +00:00
|
|
|
ProValueMap::ConstIterator it = m_valuemapStack.first().constFind(v);
|
|
|
|
return it == m_valuemapStack.first().constEnd() || it->isEmpty();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
void QMakeProject::dump() const
|
2012-04-23 17:27:43 +00:00
|
|
|
{
|
|
|
|
QStringList out;
|
2012-09-05 16:29:19 +00:00
|
|
|
for (ProValueMap::ConstIterator it = m_valuemapStack.first().begin();
|
|
|
|
it != m_valuemapStack.first().end(); ++it) {
|
2012-04-23 17:27:43 +00:00
|
|
|
if (!it.key().startsWith('.')) {
|
|
|
|
QString str = it.key() + " =";
|
2012-09-05 16:29:19 +00:00
|
|
|
foreach (const ProString &v, it.value())
|
|
|
|
str += ' ' + formatValue(v);
|
2012-04-23 17:27:43 +00:00
|
|
|
out << str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out.sort();
|
|
|
|
foreach (const QString &v, out)
|
|
|
|
puts(qPrintable(v));
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|