QtBase  v6.3.1
project.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the qmake application of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include "project.h"
30 
31 #include "cachekeys.h"
32 #include "option.h"
33 #include <qmakeevaluator_p.h>
34 
35 #include <qdir.h>
36 
37 #include <stdio.h>
38 
39 using namespace QMakeInternal;
40 
42 
44  : QMakeEvaluator(Option::globals, Option::parser, Option::vfs, &Option::evalHandler)
45 {
46 }
47 
49  : QMakeEvaluator(Option::globals, Option::parser, Option::vfs, &Option::evalHandler)
50 {
51  initFrom(p);
52 }
53 
54 bool QMakeProject::boolRet(VisitReturn vr)
55 {
56  if (vr == ReturnError) {
58  exit(3);
59  }
60  Q_ASSERT(vr == ReturnTrue || vr == ReturnFalse);
61  return vr != ReturnFalse;
62 }
63 
64 bool QMakeProject::read(const QString &project, LoadFlags what)
65 {
66  m_projectFile = project;
68  QString absproj = (project == QLatin1String("-"))
69  ? QLatin1String("(stdin)")
70  : QDir::cleanPath(QDir(qmake_getpwd()).absoluteFilePath(project));
71  m_projectDir = QFileInfo(absproj).path();
72  return boolRet(evaluateFile(absproj, QMakeHandler::EvalProjectFile, what));
73 }
74 
75 static ProStringList prepareBuiltinArgs(const QList<ProStringList> &args)
76 {
78  ret.reserve(args.size());
79  for (const ProStringList &arg : args)
80  ret << arg.join(' ');
81  return ret;
82 }
83 
85 {
86  m_current.clear();
87 
88  auto adef = statics.functions.constFind(func);
89  if (adef != statics.functions.constEnd())
90  return boolRet(evaluateBuiltinConditional(*adef, func, prepareBuiltinArgs(args)));
91 
95  return boolRet(evaluateBoolFunction(*it, args, func));
96 
97  evalError(QStringLiteral("'%1' is not a recognized test function.")
98  .arg(func.toQStringView()));
99  return false;
100 }
101 
103 {
104  m_current.clear();
105 
106  auto adef = statics.expands.constFind(func);
107  if (adef != statics.expands.constEnd()) {
109  if (evaluateBuiltinExpand(*adef, func, prepareBuiltinArgs(args), ret) == ReturnError)
110  exit(3);
111  return ret.toQStringList();
112  }
113 
119  exit(3);
120  return ret.toQStringList();
121  }
122 
123  evalError(QStringLiteral("'%1' is not a recognized replace function.")
124  .arg(func.toQStringView()));
125  return QStringList();
126 }
127 
128 ProString QMakeProject::expand(const QString &expr, const QString &where, int line)
129 {
130  ProString ret;
131  ProFile *pro = m_parser->parsedProBlock(QStringView(expr), 0, where, line,
133  if (pro->isOk()) {
134  m_current.pro = pro;
135  m_current.line = 0;
136  const ushort *tokPtr = pro->tokPtr();
138  if (expandVariableReferences(tokPtr, 1, &result, true) == ReturnError)
139  exit(3);
140  if (!result.isEmpty())
141  ret = result.at(0);
142  }
143  pro->deref();
144  return ret;
145 }
146 
147 bool QMakeProject::isEmpty(const ProKey &v) const
148 {
149  ProValueMap::ConstIterator it = m_valuemapStack.front().constFind(v);
150  return it == m_valuemapStack.front().constEnd() || it->isEmpty();
151 }
152 
153 void QMakeProject::dump() const
154 {
156  for (ProValueMap::ConstIterator it = m_valuemapStack.front().begin();
157  it != m_valuemapStack.front().end(); ++it) {
158  if (!it.key().startsWith('.')) {
159  QString str = it.key() + " =";
160  for (const ProString &v : it.value())
161  str += ' ' + formatValue(v);
162  out << str;
163  }
164  }
165  out.sort();
166  for (const QString &v : qAsConst(out))
167  puts(qPrintable(v));
168 }
169 
void qmakeClearCaches()
Definition: option.cpp:625
void deref()
Definition: proitems.h:445
const ushort * tokPtr() const
Definition: proitems.h:441
bool isOk() const
Definition: proitems.h:447
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:55
static QString cleanPath(const QString &path)
Definition: qdir.cpp:2350
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:57
QString path() const
Definition: qfileinfo.cpp:634
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qhash.h:773
const_iterator constFind(const Key &key) const noexcept
Definition: qhash.h:1224
const_iterator constEnd() const noexcept
Definition: qhash.h:1162
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
Definition: qstring.h:84
Definition: qlist.h:108
ProFunctionDefs m_functionDefs
VisitReturn evaluateBuiltinConditional(const QMakeInternal::QMakeBuiltin &adef, const ProKey &function, const ProStringList &args)
QMakeParser * m_parser
VisitReturn evaluateBuiltinExpand(const QMakeInternal::QMakeBuiltin &adef, const ProKey &function, const ProStringList &args, ProStringList &ret)
VisitReturn evaluateFunction(const ProFunctionDef &func, const QList< ProStringList > &argumentsList, ProStringList *ret)
VisitReturn evaluateBoolFunction(const ProFunctionDef &func, const QList< ProStringList > &argumentsList, const ProString &function)
VisitReturn evaluateFile(const QString &fileName, QMakeHandler::EvalFileType type, LoadFlags flags)
VisitReturn expandVariableReferences(const ushort *&tokPtr, int sizeHint, ProStringList *ret, bool joined)
Location m_current
void initFrom(const QMakeEvaluator *other)
void setOutputDir(const QString &outputDir)
void evalError(const QString &msg) const
ProValueMapStack m_valuemapStack
ProFile * parsedProBlock(QStringView contents, int id, const QString &name, int line=0, SubGrammar grammar=FullGrammar)
bool isEmpty(const ProKey &v) const
Definition: project.cpp:147
ProString expand(const QString &v, const QString &file, int line)
Definition: project.cpp:128
void dump() const
Definition: project.cpp:153
bool test(const QString &v, const QString &file, int line)
Definition: project.h:57
bool read(const QString &project, LoadFlags what=LoadAll)
Definition: project.cpp:64
const_iterator ConstIterator
Definition: qmap.h:670
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
Definition: qstringview.h:122
QString str
[2]
QMakeStatics statics
parser
Definition: devices.py:74
QList< QString > QStringList
Definition: qcontainerfwd.h:64
unsigned short ushort
Definition: qglobal.h:333
QString qmake_getpwd()
Definition: main.cpp:434
GLsizei const GLfloat * v
[13]
GLenum func
Definition: qopenglext.h:663
GLuint64EXT * result
[6]
Definition: qopenglext.h:10932
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84
SSL_CTX int(*) void arg)
#define QStringLiteral(str)
QTextStream out(stdout)
[7]
QStringList::Iterator it
static QString output_dir
Definition: option.h:168
QHash< ProKey, ProFunctionDef > replaceFunctions
Definition: proitems.h:507
QHash< ProKey, ProFunctionDef > testFunctions
Definition: proitems.h:506
QHash< ProKey, QMakeBuiltin > functions
QHash< ProKey, QMakeBuiltin > expands