Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
profileevaluator.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
6#include "qmakeglobals.h"
7#include "ioutils.h"
8#include "qmakevfs.h"
9
10#include <QDir>
11
12using namespace QMakeInternal;
13
14QT_BEGIN_NAMESPACE
15
16void ProFileEvaluator::initialize()
17{
18 QMakeEvaluator::initStatics();
19}
20
26
28{
29 delete d;
30}
31
32bool ProFileEvaluator::contains(const QString &variableName) const
33{
34 return d->m_valuemapStack.top().contains(ProKey(variableName));
35}
36
37QString ProFileEvaluator::value(const QString &variable) const
38{
39 const QStringList &vals = values(variable);
40 if (!vals.isEmpty())
41 return vals.first();
42
43 return QString();
44}
45
46QStringList ProFileEvaluator::values(const QString &variableName) const
47{
48 const ProStringList &values = d->values(ProKey(variableName));
49 QStringList ret;
50 ret.reserve(values.size());
51 for (const ProString &str : values)
52 ret << d->m_option->expandEnvVars(str.toQString());
53 return ret;
54}
55
56QStringList ProFileEvaluator::values(const QString &variableName, const ProFile *pro) const
57{
58 // It makes no sense to put any kind of magic into expanding these
59 const ProStringList &values = d->m_valuemapStack.front().value(ProKey(variableName));
60 QStringList ret;
61 ret.reserve(values.size());
62 for (const ProString &str : values)
63 if (str.sourceFile() == pro->id())
64 ret << d->m_option->expandEnvVars(str.toQString());
65 return ret;
66}
67
68QString ProFileEvaluator::sysrootify(const QString &path, const QString &baseDir) const
69{
70 ProFileGlobals *option = static_cast<ProFileGlobals *>(d->m_option);
71#ifdef Q_OS_WIN
72 Qt::CaseSensitivity cs = Qt::CaseInsensitive;
73#else
74 Qt::CaseSensitivity cs = Qt::CaseSensitive;
75#endif
76 const bool isHostSystemPath =
77 option->sysroot.isEmpty() || path.startsWith(option->sysroot, cs)
78 || path.startsWith(baseDir, cs) || path.startsWith(d->m_outputDir, cs);
79
80 return isHostSystemPath ? path : option->sysroot + path;
81}
82
84 const QString &variable, const QString &baseDirectory) const
85{
86 QStringList result;
87 for (const QString &el : values(variable)) {
88 QString absEl = IoUtils::isAbsolutePath(el)
89 ? sysrootify(el, baseDirectory) : IoUtils::resolvePath(baseDirectory, el);
90 if (IoUtils::fileType(absEl) == IoUtils::FileIsDir)
91 result << QDir::cleanPath(absEl);
92 }
93 return result;
94}
95
97 const QString &variable, const QString &baseDirectory, const QStringList &searchDirs,
98 const ProFile *pro) const
99{
100 QStringList result;
101 const auto vals = pro ? values(variable, pro) : values(variable);
102 for (const QString &el : vals) {
103 QString absEl;
104 if (IoUtils::isAbsolutePath(el)) {
105 const QString elWithSysroot = QDir::cleanPath(sysrootify(el, baseDirectory));
106 if (d->m_vfs->exists(elWithSysroot, QMakeVfs::VfsCumulative)) {
107 result << elWithSysroot;
108 goto next;
109 }
110 absEl = elWithSysroot;
111 } else {
112 for (const QString &dir : searchDirs) {
113 QString fn = QDir::cleanPath(dir + QLatin1Char('/') + el);
114 if (d->m_vfs->exists(fn, QMakeVfs::VfsCumulative)) {
115 result << fn;
116 goto next;
117 }
118 }
119 if (baseDirectory.isEmpty())
120 goto next;
121 absEl = QDir::cleanPath(baseDirectory + QLatin1Char('/') + el);
122 }
123 {
124 int nameOff = absEl.lastIndexOf(QLatin1Char('/'));
125 QString absDir = d->m_tmp1.setRawData(absEl.constData(), nameOff);
126 // NOTE: This does not support virtual files. That shouldn't be a problem,
127 // because no sane project would add generated files by wildcard.
128 if (IoUtils::fileType(absDir) == IoUtils::FileIsDir) {
129 QString wildcard = d->m_tmp2.setRawData(absEl.constData() + nameOff + 1,
130 absEl.size() - nameOff - 1);
131 if (wildcard.contains(QLatin1Char('*')) || wildcard.contains(QLatin1Char('?'))) {
132 QDir theDir(absDir);
133 for (const QString &fn : theDir.entryList(QStringList(wildcard)))
134 if (fn != QLatin1String(".") && fn != QLatin1String(".."))
135 result << absDir + QLatin1Char('/') + fn;
136 } // else if (acceptMissing)
137 }
138 }
139 next: ;
140 }
141 return result;
142}
143
145{
146 const ProStringList &templ = d->values(ProKey("TEMPLATE"));
147 if (templ.size() >= 1) {
148 const QString &t = templ.at(0).toQString();
149 if (!t.compare(QLatin1String("app"), Qt::CaseInsensitive))
150 return TT_Application;
151 if (!t.compare(QLatin1String("lib"), Qt::CaseInsensitive))
152 return TT_Library;
153 if (!t.compare(QLatin1String("script"), Qt::CaseInsensitive))
154 return TT_Script;
155 if (!t.compare(QLatin1String("aux"), Qt::CaseInsensitive))
156 return TT_Aux;
157 if (!t.compare(QLatin1String("subdirs"), Qt::CaseInsensitive))
158 return TT_Subdirs;
159 }
160 return TT_Unknown;
161}
162
163bool ProFileEvaluator::loadNamedSpec(const QString &specDir, bool hostSpec)
164{
165 d->m_qmakespec = specDir;
166 d->m_hostBuild = hostSpec;
167
169 return d->loadSpecInternal();
170}
171
172bool ProFileEvaluator::accept(ProFile *pro, QMakeEvaluator::LoadFlags flags)
173{
174 return d->visitProFile(pro, QMakeHandler::EvalProjectFile, flags) == QMakeEvaluator::ReturnTrue;
175}
176
177QString ProFileEvaluator::propertyValue(const QString &name) const
178{
180}
181
183{
184 return d->m_qmakespec;
185}
186
187#ifdef PROEVALUATOR_CUMULATIVE
188void ProFileEvaluator::setCumulative(bool on)
189{
190 d->m_cumulative = on;
191}
192#endif
193
194void ProFileEvaluator::setExtraVars(const QHash<QString, QStringList> &extraVars)
195{
196 ProValueMap map;
197 for (auto it = extraVars.cbegin(), end = extraVars.cend() ; it != end; ++it)
198 map.insert(ProKey(it.key()), ProStringList(it.value()));
200}
201
202void ProFileEvaluator::setExtraConfigs(const QStringList &extraConfigs)
203{
205}
206
207void ProFileEvaluator::setOutputDir(const QString &dir)
208{
209 d->m_outputDir = dir;
210}
211
212QT_END_NAMESPACE
ProFileEvaluator::TemplateType templateType() const
ProFileEvaluator(ProFileGlobals *option, QMakeParser *parser, QMakeVfs *vfs, QMakeHandler *handler)
void setExtraConfigs(const QStringList &extraConfigs)
void setExtraVars(const QHash< QString, QStringList > &extraVars)
QStringList values(const QString &variableName, const ProFile *pro) const
QString value(const QString &variableName) const
bool contains(const QString &variableName) const
QString resolvedMkSpec() const
bool accept(ProFile *pro, QMakeEvaluator::LoadFlags flags=QMakeEvaluator::LoadAll)
QStringList absoluteFileValues(const QString &variable, const QString &baseDirectory, const QStringList &searchDirs, const ProFile *pro) const
void setOutputDir(const QString &dir)
QStringList absolutePathValues(const QString &variable, const QString &baseDirectory) const
QStringList values(const QString &variableName) const
QString propertyValue(const QString &val) const
bool loadNamedSpec(const QString &specDir, bool hostSpec)
ProKey(const QString &str)
Definition proitems.cpp:102
PROITEM_EXPLICIT ProKey(const char *str)
Definition proitems.cpp:107
QString toQString() const
Definition proitems.cpp:128
ProValueMap & top()
QMakeGlobals * m_option
void setExtraConfigs(const ProStringList &extraConfigs)
ProStringList values(const ProKey &variableName) const
void setExtraVars(const ProValueMap &extraVars)
ProValueMapStack m_valuemapStack
ProString propertyValue(const ProKey &name) const
QMap< ProKey, ProStringList > ProValueMap
Definition proitems.h:330