2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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
|
|
|
|
2010-01-22 12:26:14 +01:00
|
|
|
using namespace ProFileEvaluatorInternal;
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2012-05-02 15:39:02 +02:00
|
|
|
ProFileEvaluator::ProFileEvaluator(QMakeGlobals *option, QMakeParser *parser,
|
2012-06-11 20:28:16 +02:00
|
|
|
QMakeHandler *handler)
|
2012-05-02 15:43:12 +02:00
|
|
|
: d(new QMakeEvaluator(option, parser, handler))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProFileEvaluator::~ProFileEvaluator()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProFileEvaluator::contains(const QString &variableName) const
|
|
|
|
|
{
|
2010-04-27 18:39:10 +02:00
|
|
|
return d->m_valuemapStack.top().contains(ProString(variableName));
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2011-04-20 21:16:17 +02:00
|
|
|
const ProStringList &values = d->values(ProString(variableName));
|
|
|
|
|
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
|
2011-04-20 18:19:33 +02:00
|
|
|
const ProStringList &values = d->m_valuemapStack.at(0).value(ProString(variableName));
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
Qt::CaseSensitivity cs = Qt::CaseInsensitive;
|
|
|
|
|
#else
|
|
|
|
|
Qt::CaseSensitivity cs = Qt::CaseSensitive;
|
|
|
|
|
#endif
|
|
|
|
|
const bool isHostSystemPath =
|
|
|
|
|
d->m_option->sysroot.isEmpty() || path.startsWith(d->m_option->sysroot, cs)
|
|
|
|
|
|| path.startsWith(baseDir, cs) || path.startsWith(d->m_outputDir, cs);
|
|
|
|
|
|
|
|
|
|
return isHostSystemPath ? path : d->m_option->sysroot + path;
|
|
|
|
|
}
|
|
|
|
|
|
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-06-11 20:00:37 +02:00
|
|
|
const ProStringList &templ = d->values(ProString("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-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
|
|
|
|
|
{
|
2010-06-24 18:57:07 +02:00
|
|
|
return d->propertyValue(name, false);
|
2008-12-02 12:01:29 +01: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
|
|
|
|
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
|