2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02: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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 12:57:59 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "profileevaluator.h"
|
2010-06-18 19:48:07 +02:00
|
|
|
|
2012-06-08 21:18:10 +02:00
|
|
|
#include "qmakeglobals.h"
|
2010-01-22 12:26:14 +01:00
|
|
|
#include "ioutils.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2008-12-12 16:30:31 +01:00
|
|
|
|
2012-09-03 21:30:28 +02:00
|
|
|
using namespace QMakeInternal;
|
2010-01-22 12:26:14 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
2010-02-08 16:47:25 +01:00
|
|
|
void ProFileEvaluator::initialize()
|
|
|
|
|
{
|
2012-05-02 15:43:12 +02:00
|
|
|
QMakeEvaluator::initStatics();
|
2010-02-08 16:47:25 +01:00
|
|
|
}
|
|
|
|
|
|
2013-05-29 20:18:51 +02:00
|
|
|
ProFileEvaluator::ProFileEvaluator(ProFileGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
|
2012-06-11 20:28:16 +02:00
|
|
|
QMakeHandler *handler)
|
2013-05-29 20:18:51 +02:00
|
|
|
: d(new QMakeEvaluator(option, parser, vfs, handler))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProFileEvaluator::~ProFileEvaluator()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProFileEvaluator::contains(const QString &variableName) const
|
|
|
|
|
{
|
2012-08-03 15:57:46 +02:00
|
|
|
return d->m_valuemapStack.top().contains(ProKey(variableName));
|
2010-04-27 18:39:10 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-15 22:51:37 +02:00
|
|
|
QString ProFileEvaluator::value(const QString &variable) const
|
|
|
|
|
{
|
|
|
|
|
const QStringList &vals = values(variable);
|
|
|
|
|
if (!vals.isEmpty())
|
|
|
|
|
return vals.first();
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QStringList ProFileEvaluator::values(const QString &variableName) const
|
|
|
|
|
{
|
2012-08-03 15:57:46 +02:00
|
|
|
const ProStringList &values = d->values(ProKey(variableName));
|
2011-04-20 21:16:17 +02:00
|
|
|
QStringList ret;
|
|
|
|
|
ret.reserve(values.size());
|
|
|
|
|
foreach (const ProString &str, values)
|
2012-06-11 21:06:00 +02:00
|
|
|
ret << d->m_option->expandEnvVars(str.toQString());
|
2011-04-20 21:16:17 +02:00
|
|
|
return ret;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ProFileEvaluator::values(const QString &variableName, const ProFile *pro) const
|
|
|
|
|
{
|
2010-02-09 14:58:59 +01:00
|
|
|
// It makes no sense to put any kind of magic into expanding these
|
2012-08-27 15:03:48 +02:00
|
|
|
const ProStringList &values = d->m_valuemapStack.first().value(ProKey(variableName));
|
2011-04-20 18:19:33 +02:00
|
|
|
QStringList ret;
|
|
|
|
|
ret.reserve(values.size());
|
|
|
|
|
foreach (const ProString &str, values)
|
|
|
|
|
if (str.sourceFile() == pro)
|
2012-06-11 21:06:00 +02:00
|
|
|
ret << d->m_option->expandEnvVars(str.toQString());
|
2011-04-20 18:19:33 +02:00
|
|
|
return ret;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-06-11 21:56:05 +02:00
|
|
|
QString ProFileEvaluator::sysrootify(const QString &path, const QString &baseDir) const
|
|
|
|
|
{
|
2012-08-28 18:18:07 +02:00
|
|
|
ProFileGlobals *option = static_cast<ProFileGlobals *>(d->m_option);
|
2012-06-11 21:56:05 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
Qt::CaseSensitivity cs = Qt::CaseInsensitive;
|
|
|
|
|
#else
|
|
|
|
|
Qt::CaseSensitivity cs = Qt::CaseSensitive;
|
|
|
|
|
#endif
|
|
|
|
|
const bool isHostSystemPath =
|
2012-08-28 18:18:07 +02:00
|
|
|
option->sysroot.isEmpty() || path.startsWith(option->sysroot, cs)
|
2012-06-11 21:56:05 +02:00
|
|
|
|| path.startsWith(baseDir, cs) || path.startsWith(d->m_outputDir, cs);
|
|
|
|
|
|
2012-08-28 18:18:07 +02:00
|
|
|
return isHostSystemPath ? path : option->sysroot + path;
|
2012-06-11 21:56:05 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-10 13:37:02 +02:00
|
|
|
QStringList ProFileEvaluator::absolutePathValues(
|
|
|
|
|
const QString &variable, const QString &baseDirectory) const
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
foreach (const QString &el, values(variable)) {
|
2011-01-05 17:56:49 +01:00
|
|
|
QString absEl = IoUtils::isAbsolutePath(el)
|
2012-06-11 21:56:05 +02:00
|
|
|
? sysrootify(el, baseDirectory) : IoUtils::resolvePath(baseDirectory, el);
|
2010-01-22 12:26:14 +01:00
|
|
|
if (IoUtils::fileType(absEl) == IoUtils::FileIsDir)
|
|
|
|
|
result << QDir::cleanPath(absEl);
|
2009-07-10 13:37:02 +02:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ProFileEvaluator::absoluteFileValues(
|
|
|
|
|
const QString &variable, const QString &baseDirectory, const QStringList &searchDirs,
|
|
|
|
|
const ProFile *pro) const
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
foreach (const QString &el, pro ? values(variable, pro) : values(variable)) {
|
2010-01-22 12:26:14 +01:00
|
|
|
QString absEl;
|
|
|
|
|
if (IoUtils::isAbsolutePath(el)) {
|
2012-06-11 21:56:05 +02:00
|
|
|
const QString elWithSysroot = sysrootify(el, baseDirectory);
|
2011-01-05 17:56:49 +01:00
|
|
|
if (IoUtils::exists(elWithSysroot)) {
|
|
|
|
|
result << QDir::cleanPath(elWithSysroot);
|
2009-07-10 13:37:02 +02:00
|
|
|
goto next;
|
|
|
|
|
}
|
2011-01-05 17:56:49 +01:00
|
|
|
absEl = elWithSysroot;
|
2009-07-10 13:37:02 +02:00
|
|
|
} else {
|
|
|
|
|
foreach (const QString &dir, searchDirs) {
|
2010-01-22 12:26:14 +01:00
|
|
|
QString fn = dir + QLatin1Char('/') + el;
|
|
|
|
|
if (IoUtils::exists(fn)) {
|
|
|
|
|
result << QDir::cleanPath(fn);
|
2009-07-10 13:37:02 +02:00
|
|
|
goto next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (baseDirectory.isEmpty())
|
|
|
|
|
goto next;
|
2010-01-22 12:26:14 +01:00
|
|
|
absEl = baseDirectory + QLatin1Char('/') + el;
|
2009-07-10 13:37:02 +02:00
|
|
|
}
|
|
|
|
|
{
|
2010-01-22 12:26:14 +01:00
|
|
|
absEl = QDir::cleanPath(absEl);
|
|
|
|
|
int nameOff = absEl.lastIndexOf(QLatin1Char('/'));
|
2010-06-10 17:14:54 +02:00
|
|
|
QString absDir = d->m_tmp1.setRawData(absEl.constData(), nameOff);
|
2010-01-22 12:26:14 +01:00
|
|
|
if (IoUtils::exists(absDir)) {
|
2010-06-10 17:14:54 +02:00
|
|
|
QString wildcard = d->m_tmp2.setRawData(absEl.constData() + nameOff + 1,
|
2010-01-22 12:26:14 +01:00
|
|
|
absEl.length() - nameOff - 1);
|
2009-07-10 13:37:02 +02:00
|
|
|
if (wildcard.contains(QLatin1Char('*')) || wildcard.contains(QLatin1Char('?'))) {
|
2010-10-21 19:53:29 +02:00
|
|
|
wildcard.detach(); // Keep m_tmp out of QRegExp's cache
|
2010-01-22 12:26:14 +01:00
|
|
|
QDir theDir(absDir);
|
2009-07-10 13:37:02 +02:00
|
|
|
foreach (const QString &fn, theDir.entryList(QStringList(wildcard)))
|
2012-06-11 20:00:37 +02:00
|
|
|
if (fn != QLatin1String(".") && fn != QLatin1String(".."))
|
2010-01-22 12:26:14 +01:00
|
|
|
result << absDir + QLatin1Char('/') + fn;
|
2009-07-10 13:37:02 +02:00
|
|
|
} // else if (acceptMissing)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
next: ;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-15 20:50:57 +02:00
|
|
|
ProFileEvaluator::TemplateType ProFileEvaluator::templateType() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-08-03 15:57:46 +02:00
|
|
|
const ProStringList &templ = d->values(ProKey("TEMPLATE"));
|
2008-12-02 12:01:29 +01:00
|
|
|
if (templ.count() >= 1) {
|
2010-06-24 15:17:28 +02:00
|
|
|
const QString &t = templ.at(0).toQString();
|
2009-05-25 15:58:58 +02:00
|
|
|
if (!t.compare(QLatin1String("app"), Qt::CaseInsensitive))
|
2008-12-02 12:01:29 +01:00
|
|
|
return TT_Application;
|
2009-05-25 15:58:58 +02:00
|
|
|
if (!t.compare(QLatin1String("lib"), Qt::CaseInsensitive))
|
2008-12-02 12:01:29 +01:00
|
|
|
return TT_Library;
|
2009-05-25 15:58:58 +02:00
|
|
|
if (!t.compare(QLatin1String("script"), Qt::CaseInsensitive))
|
2008-12-02 12:01:29 +01:00
|
|
|
return TT_Script;
|
2011-05-05 17:42:35 +02:00
|
|
|
if (!t.compare(QLatin1String("aux"), Qt::CaseInsensitive))
|
|
|
|
|
return TT_Aux;
|
2009-05-25 15:58:58 +02:00
|
|
|
if (!t.compare(QLatin1String("subdirs"), Qt::CaseInsensitive))
|
2008-12-02 12:01:29 +01:00
|
|
|
return TT_Subdirs;
|
|
|
|
|
}
|
|
|
|
|
return TT_Unknown;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 14:58:12 +02:00
|
|
|
bool ProFileEvaluator::loadNamedSpec(const QString &specDir, bool hostSpec)
|
|
|
|
|
{
|
|
|
|
|
d->m_qmakespec = specDir;
|
|
|
|
|
d->m_hostBuild = hostSpec;
|
|
|
|
|
|
|
|
|
|
d->updateMkspecPaths();
|
|
|
|
|
return d->loadSpecInternal();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 20:56:24 +02:00
|
|
|
bool ProFileEvaluator::accept(ProFile *pro, QMakeEvaluator::LoadFlags flags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-06-11 20:28:16 +02:00
|
|
|
return d->visitProFile(pro, QMakeHandler::EvalProjectFile, flags) == QMakeEvaluator::ReturnTrue;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ProFileEvaluator::propertyValue(const QString &name) const
|
|
|
|
|
{
|
2012-08-03 15:57:46 +02:00
|
|
|
return d->m_option->propertyValue(ProKey(name)).toQString();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-04 11:41:32 +02:00
|
|
|
QString ProFileEvaluator::resolvedMkSpec() const
|
|
|
|
|
{
|
2012-09-18 10:54:52 +02:00
|
|
|
return d->m_qmakespec;
|
2012-09-04 11:41:32 +02:00
|
|
|
}
|
|
|
|
|
|
2011-05-31 19:19:34 +02:00
|
|
|
#ifdef PROEVALUATOR_CUMULATIVE
|
2008-12-12 18:10:42 +01:00
|
|
|
void ProFileEvaluator::setCumulative(bool on)
|
|
|
|
|
{
|
|
|
|
|
d->m_cumulative = on;
|
|
|
|
|
}
|
2011-05-31 19:19:34 +02:00
|
|
|
#endif
|
2008-12-12 18:10:42 +01:00
|
|
|
|
2012-10-23 17:40:10 +02:00
|
|
|
void ProFileEvaluator::setExtraVars(const QHash<QString, QStringList> &extraVars)
|
|
|
|
|
{
|
|
|
|
|
ProValueMap map;
|
|
|
|
|
QHash<QString, QStringList>::const_iterator it = extraVars.constBegin();
|
|
|
|
|
QHash<QString, QStringList>::const_iterator end = extraVars.constEnd();
|
|
|
|
|
for ( ; it != end; ++it)
|
|
|
|
|
map.insert(ProKey(it.key()), ProStringList(it.value()));
|
|
|
|
|
d->setExtraVars(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProFileEvaluator::setExtraConfigs(const QStringList &extraConfigs)
|
|
|
|
|
{
|
|
|
|
|
d->setExtraConfigs(ProStringList(extraConfigs));
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-12 16:30:31 +01:00
|
|
|
void ProFileEvaluator::setOutputDir(const QString &dir)
|
|
|
|
|
{
|
|
|
|
|
d->m_outputDir = dir;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_END_NAMESPACE
|