1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the qmake application of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
45 #include <qmakeevaluator_p.h>
51 using namespace QMakeInternal;
55 QMakeProject::QMakeProject()
56 : QMakeEvaluator(Option::globals, Option::parser, &Option::evalHandler)
60 QMakeProject::QMakeProject(QMakeProject *p)
61 : QMakeEvaluator(Option::globals, Option::parser, &Option::evalHandler)
66 bool QMakeProject::boolRet(VisitReturn vr)
68 if (vr == ReturnError)
70 Q_ASSERT(vr == ReturnTrue || vr == ReturnFalse);
71 return vr != ReturnFalse;
74 bool QMakeProject::read(const QString &project, LoadFlags what)
76 m_projectFile = project;
77 setOutputDir(Option::output_dir);
78 QString absproj = (project == QLatin1String("-"))
79 ? QLatin1String("(stdin)")
80 : QDir::cleanPath(QDir(qmake_getpwd()).absoluteFilePath(project));
81 return boolRet(evaluateFile(absproj, QMakeHandler::EvalProjectFile, what));
84 static ProStringList prepareBuiltinArgs(const QList<ProStringList> &args)
87 ret.reserve(args.size());
88 foreach (const ProStringList &arg, args)
93 bool QMakeProject::test(const ProKey &func, const QList<ProStringList> &args)
97 if (int func_t = statics.functions.value(func))
98 return boolRet(evaluateBuiltinConditional(func_t, func, prepareBuiltinArgs(args)));
100 QHash<ProKey, ProFunctionDef>::ConstIterator it =
101 m_functionDefs.testFunctions.constFind(func);
102 if (it != m_functionDefs.testFunctions.constEnd())
103 return boolRet(evaluateBoolFunction(*it, args, func));
105 evalError(QStringLiteral("'%1' is not a recognized test function.")
106 .arg(func.toQString(m_tmp1)));
110 QStringList QMakeProject::expand(const ProKey &func, const QList<ProStringList> &args)
114 if (int func_t = statics.expands.value(func))
115 return evaluateBuiltinExpand(func_t, func, prepareBuiltinArgs(args)).toQStringList();
117 QHash<ProKey, ProFunctionDef>::ConstIterator it =
118 m_functionDefs.replaceFunctions.constFind(func);
119 if (it != m_functionDefs.replaceFunctions.constEnd()) {
120 QMakeProject::VisitReturn vr;
121 ProStringList ret = evaluateFunction(*it, args, &vr);
122 if (vr == QMakeProject::ReturnError)
124 return ret.toQStringList();
127 evalError(QStringLiteral("'%1' is not a recognized replace function.")
128 .arg(func.toQString(m_tmp1)));
129 return QStringList();
132 ProString QMakeProject::expand(const QString &expr, const QString &where, int line)
135 if (ProFile *pro = m_parser->parsedProBlock(expr, where, line, QMakeParser::ValueGrammar)) {
139 const ushort *tokPtr = pro->tokPtr();
140 ProStringList result = expandVariableReferences(tokPtr, 1, true);
141 if (!result.isEmpty())
149 bool QMakeProject::isEmpty(const ProKey &v) const
151 ProValueMap::ConstIterator it = m_valuemapStack.first().constFind(v);
152 return it == m_valuemapStack.first().constEnd() || it->isEmpty();
155 void QMakeProject::dump() const
158 for (ProValueMap::ConstIterator it = m_valuemapStack.first().begin();
159 it != m_valuemapStack.first().end(); ++it) {
160 if (!it.key().startsWith('.')) {
161 QString str = it.key() + " =";
162 foreach (const ProString &v, it.value())
163 str += ' ' + formatValue(v);
168 foreach (const QString &v, out)