2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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()
|
2013-05-29 18:18:51 +00:00
|
|
|
: QMakeEvaluator(Option::globals, Option::parser, Option::vfs, &Option::evalHandler)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeProject::QMakeProject(QMakeProject *p)
|
2013-05-29 18:18:51 +00:00
|
|
|
: QMakeEvaluator(Option::globals, Option::parser, Option::vfs, &Option::evalHandler)
|
2012-04-27 16:34:09 +00:00
|
|
|
{
|
2014-06-16 12:31:30 +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));
|
2015-04-13 19:18:36 +00:00
|
|
|
m_projectDir = QFileInfo(absproj).path();
|
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());
|
2016-01-26 13:38:54 +00:00
|
|
|
for (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
|
|
|
|
2016-11-25 19:41:20 +00:00
|
|
|
if (int func_t = statics.expands.value(func)) {
|
|
|
|
ProStringList ret;
|
|
|
|
if (evaluateBuiltinExpand(func_t, func, prepareBuiltinArgs(args), ret) == ReturnError)
|
|
|
|
exit(3);
|
|
|
|
return ret.toQStringList();
|
|
|
|
}
|
2012-09-03 18:57:59 +00:00
|
|
|
|
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()) {
|
2016-06-29 14:56:57 +00:00
|
|
|
ProStringList ret;
|
|
|
|
if (evaluateFunction(*it, args, &ret) == QMakeProject::ReturnError)
|
2012-09-19 19:56:16 +00:00
|
|
|
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;
|
2016-05-13 13:32:50 +00:00
|
|
|
ProFile *pro = m_parser->parsedProBlock(QStringRef(&expr), where, line,
|
|
|
|
QMakeParser::ValueGrammar);
|
2015-02-02 17:52:24 +00:00
|
|
|
if (pro->isOk()) {
|
|
|
|
m_current.pro = pro;
|
|
|
|
m_current.line = 0;
|
|
|
|
const ushort *tokPtr = pro->tokPtr();
|
2016-06-29 14:56:57 +00:00
|
|
|
ProStringList result;
|
|
|
|
if (expandVariableReferences(tokPtr, 1, &result, true) == ReturnError)
|
|
|
|
exit(3);
|
2015-02-02 17:52:24 +00:00
|
|
|
if (!result.isEmpty())
|
|
|
|
ret = result.at(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-02-02 17:52:24 +00:00
|
|
|
pro->deref();
|
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() + " =";
|
2016-01-26 13:38:54 +00:00
|
|
|
for (const ProString &v : it.value())
|
2012-09-05 16:29:19 +00:00
|
|
|
str += ' ' + formatValue(v);
|
2012-04-23 17:27:43 +00:00
|
|
|
out << str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out.sort();
|
2016-01-26 13:38:54 +00:00
|
|
|
for (const QString &v : qAsConst(out))
|
2012-04-23 17:27:43 +00:00
|
|
|
puts(qPrintable(v));
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|