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
|
|
|
|
2021-05-06 11:40:53 +00:00
|
|
|
#include "cachekeys.h"
|
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)
|
|
|
|
{
|
2021-05-06 11:40:53 +00:00
|
|
|
if (vr == ReturnError) {
|
|
|
|
qmakeClearCaches();
|
2012-09-19 19:56:16 +00:00
|
|
|
exit(3);
|
2021-05-06 11:40:53 +00:00
|
|
|
}
|
2012-09-19 19:56:16 +00:00
|
|
|
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
|
|
|
|
2017-08-11 17:22:58 +00:00
|
|
|
auto adef = statics.functions.constFind(func);
|
|
|
|
if (adef != statics.functions.constEnd())
|
|
|
|
return boolRet(evaluateBuiltinConditional(*adef, 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.")
|
2017-04-07 15:10:37 +00:00
|
|
|
.arg(func.toQStringView()));
|
2012-09-03 18:57:59 +00:00
|
|
|
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
|
|
|
|
2017-08-11 17:22:58 +00:00
|
|
|
auto adef = statics.expands.constFind(func);
|
|
|
|
if (adef != statics.expands.constEnd()) {
|
2016-11-25 19:41:20 +00:00
|
|
|
ProStringList ret;
|
2017-08-11 17:22:58 +00:00
|
|
|
if (evaluateBuiltinExpand(*adef, func, prepareBuiltinArgs(args), ret) == ReturnError)
|
2016-11-25 19:41:20 +00:00
|
|
|
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.")
|
2017-04-07 15:10:37 +00:00
|
|
|
.arg(func.toQStringView()));
|
2012-09-03 18:57:59 +00:00
|
|
|
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;
|
2020-05-30 21:29:21 +00:00
|
|
|
ProFile *pro = m_parser->parsedProBlock(QStringView(expr), 0, where, line,
|
2016-05-13 13:32:50 +00:00
|
|
|
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
|
|
|
{
|
2019-05-02 16:44:32 +00:00
|
|
|
ProValueMap::ConstIterator it = m_valuemapStack.front().constFind(v);
|
|
|
|
return it == m_valuemapStack.front().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;
|
2019-05-02 16:44:32 +00:00
|
|
|
for (ProValueMap::ConstIterator it = m_valuemapStack.front().begin();
|
|
|
|
it != m_valuemapStack.front().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
|