Qdoc: put hardcoded url as workaround QTBUG-28500
[profile/ivi/qtbase.git] / qmake / project.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the qmake application of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "project.h"
43
44 #include "option.h"
45 #include <qmakeevaluator_p.h>
46
47 #include <qdir.h>
48
49 #include <stdio.h>
50
51 using namespace QMakeInternal;
52
53 QT_BEGIN_NAMESPACE
54
55 QMakeProject::QMakeProject()
56     : QMakeEvaluator(Option::globals, Option::parser, &Option::evalHandler)
57 {
58 }
59
60 QMakeProject::QMakeProject(QMakeProject *p)
61     : QMakeEvaluator(Option::globals, Option::parser, &Option::evalHandler)
62 {
63     initFrom(*p);
64 }
65
66 bool QMakeProject::boolRet(VisitReturn vr)
67 {
68     if (vr == ReturnError)
69         exit(3);
70     Q_ASSERT(vr == ReturnTrue || vr == ReturnFalse);
71     return vr != ReturnFalse;
72 }
73
74 bool QMakeProject::read(const QString &project, LoadFlags what)
75 {
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));
82 }
83
84 static ProStringList prepareBuiltinArgs(const QList<ProStringList> &args)
85 {
86     ProStringList ret;
87     ret.reserve(args.size());
88     foreach (const ProStringList &arg, args)
89         ret << arg.join(' ');
90     return ret;
91 }
92
93 bool QMakeProject::test(const ProKey &func, const QList<ProStringList> &args)
94 {
95     m_current.clear();
96
97     if (int func_t = statics.functions.value(func))
98         return boolRet(evaluateBuiltinConditional(func_t, func, prepareBuiltinArgs(args)));
99
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));
104
105     evalError(QStringLiteral("'%1' is not a recognized test function.")
106               .arg(func.toQString(m_tmp1)));
107     return false;
108 }
109
110 QStringList QMakeProject::expand(const ProKey &func, const QList<ProStringList> &args)
111 {
112     m_current.clear();
113
114     if (int func_t = statics.expands.value(func))
115         return evaluateBuiltinExpand(func_t, func, prepareBuiltinArgs(args)).toQStringList();
116
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)
123             exit(3);
124         return ret.toQStringList();
125     }
126
127     evalError(QStringLiteral("'%1' is not a recognized replace function.")
128               .arg(func.toQString(m_tmp1)));
129     return QStringList();
130 }
131
132 ProString QMakeProject::expand(const QString &expr, const QString &where, int line)
133 {
134     ProString ret;
135     if (ProFile *pro = m_parser->parsedProBlock(expr, where, line, QMakeParser::ValueGrammar)) {
136         if (pro->isOk()) {
137             m_current.pro = pro;
138             m_current.line = 0;
139             const ushort *tokPtr = pro->tokPtr();
140             ProStringList result = expandVariableReferences(tokPtr, 1, true);
141             if (!result.isEmpty())
142                 ret = result.at(0);
143         }
144         pro->deref();
145     }
146     return ret;
147 }
148
149 bool QMakeProject::isEmpty(const ProKey &v) const
150 {
151     ProValueMap::ConstIterator it = m_valuemapStack.first().constFind(v);
152     return it == m_valuemapStack.first().constEnd() || it->isEmpty();
153 }
154
155 void QMakeProject::dump() const
156 {
157     QStringList out;
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);
164             out << str;
165         }
166     }
167     out.sort();
168     foreach (const QString &v, out)
169         puts(qPrintable(v));
170 }
171
172 QT_END_NAMESPACE