factor QMakeGlobals into an own file

Change-Id: I55d24be06fa78f70bad614a7125c3079c92ab8e5
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
Oswald Buddenhagen
2012-05-02 18:34:25 +02:00
parent 37b2f88e27
commit 24f24c4546
9 changed files with 308 additions and 205 deletions

View File

@@ -45,7 +45,7 @@
#include <QFuture>
QT_BEGIN_NAMESPACE
struct QMakeGlobals;
class QMakeGlobals;
QT_END_NAMESPACE
namespace QtSupport { class ProFileReader; }

View File

@@ -34,6 +34,7 @@
#define PROFILEREADER_H
#include "qtsupport_global.h"
#include "proparser/qmakeglobals.h"
#include "proparser/profileparser.h"
#include "proparser/profileevaluator.h"

View File

@@ -32,6 +32,7 @@
#include "profileevaluator.h"
#include "qmakeglobals.h"
#include "profileparser.h"
#include "ioutils.h"
@@ -78,133 +79,6 @@ using namespace ProStringConstants;
#define fL1S(s) QString::fromLatin1(s)
///////////////////////////////////////////////////////////////////////
//
// QMakeGlobal
//
///////////////////////////////////////////////////////////////////////
QMakeGlobals::QMakeGlobals()
{
#ifdef Q_OS_WIN
dirlist_sep = QLatin1Char(';');
dir_sep = QLatin1Char('\\');
#else
dirlist_sep = QLatin1Char(':');
dir_sep = QLatin1Char('/');
#endif
qmakespec = getEnv(QLatin1String("QMAKESPEC"));
host_mode = HOST_UNKNOWN_MODE;
target_mode = TARG_UNKNOWN_MODE;
#ifdef PROEVALUATOR_THREAD_SAFE
base_inProgress = false;
#endif
}
QMakeGlobals::~QMakeGlobals()
{
}
void QMakeGlobals::setCommandLineArguments(const QStringList &args)
{
QStringList _precmds, _preconfigs, _postcmds, _postconfigs;
bool after = false;
bool isConf = false;
foreach (const QString &arg, args) {
if (isConf) {
isConf = false;
if (after)
_postconfigs << arg;
else
_preconfigs << arg;
} else if (arg.startsWith(QLatin1Char('-'))) {
if (arg == QLatin1String("-after")) {
after = true;
} else if (arg == QLatin1String("-config")) {
isConf = true;
} else if (arg == QLatin1String("-win32")) {
host_mode = HOST_WIN_MODE;
target_mode = TARG_WIN_MODE;
} else if (arg == QLatin1String("-unix")) {
host_mode = HOST_UNIX_MODE;
target_mode = TARG_UNIX_MODE;
} else if (arg == QLatin1String("-macx")) {
host_mode = HOST_MACX_MODE;
target_mode = TARG_MACX_MODE;
}
} else if (arg.contains(QLatin1Char('='))) {
if (after)
_postcmds << arg;
else
_precmds << arg;
}
}
if (!_preconfigs.isEmpty())
_precmds << (fL1S("CONFIG += ") + _preconfigs.join(fL1S(" ")));
precmds = _precmds.join(fL1S("\n"));
if (!_postconfigs.isEmpty())
_postcmds << (fL1S("CONFIG += ") + _postconfigs.join(fL1S(" ")));
postcmds = _postcmds.join(fL1S("\n"));
if (host_mode != HOST_UNKNOWN_MODE)
applyHostMode();
}
void QMakeGlobals::applyHostMode()
{
if (host_mode == HOST_WIN_MODE) {
dir_sep = fL1S("\\");
} else {
dir_sep = fL1S("/");
}
}
QString QMakeGlobals::getEnv(const QString &var) const
{
#ifndef QT_BOOTSTRAPPED
if (!environment.isEmpty())
return environment.value(var);
#endif
return QString::fromLocal8Bit(qgetenv(var.toLocal8Bit().constData()));
}
#ifdef PROEVALUATOR_INIT_PROPS
bool QMakeGlobals::initProperties(const QString &qmake)
{
QByteArray data;
#ifndef QT_BOOTSTRAPPED
QProcess proc;
proc.start(qmake, QStringList() << QLatin1String("-query"));
if (!proc.waitForFinished())
return false;
data = proc.readAll();
#else
if (FILE *proc = QT_POPEN(QString(IoUtils::shellQuote(qmake) + QLatin1String(" -query"))
.toLocal8Bit(), "r")) {
char buff[1024];
while (!feof(proc))
data.append(buff, int(fread(buff, 1, 1023, proc)));
QT_PCLOSE(proc);
}
#endif
foreach (QByteArray line, data.split('\n'))
if (!line.startsWith("QMAKE_")) {
int off = line.indexOf(':');
if (off < 0) // huh?
continue;
if (line.endsWith('\r'))
line.chop(1);
properties.insert(QString::fromLatin1(line.left(off)),
QString::fromLocal8Bit(line.mid(off + 1)));
}
return true;
}
#endif
///////////////////////////////////////////////////////////////////////
//
// ProFileEvaluator::Private

View File

@@ -38,17 +38,10 @@
#include <QHash>
#include <QStringList>
#ifndef QT_BOOTSTRAPPED
# include <QProcess>
#endif
#ifdef PROEVALUATOR_THREAD_SAFE
# include <QMutex>
# include <QWaitCondition>
#endif
QT_BEGIN_NAMESPACE
struct QMakeGlobals;
class QMakeGlobals;
class ProFileParser;
class QMAKE_EXPORT ProFileEvaluatorHandler
@@ -142,77 +135,11 @@ public:
private:
Private *d;
friend struct QMakeGlobals;
friend class QMakeGlobals;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ProFileEvaluator::LoadFlags)
// This struct is from qmake, but we are not using everything.
struct QMAKE_EXPORT QMakeGlobals {
QMakeGlobals();
~QMakeGlobals();
//simply global convenience
//QString libtool_ext;
//QString pkgcfg_ext;
//QString prf_ext;
//QString prl_ext;
//QString ui_ext;
//QStringList h_ext;
//QStringList cpp_ext;
//QString h_moc_ext;
//QString cpp_moc_ext;
//QString obj_ext;
//QString lex_ext;
//QString yacc_ext;
//QString h_moc_mod;
//QString cpp_moc_mod;
//QString lex_mod;
//QString yacc_mod;
QString dir_sep;
QString dirlist_sep;
QString qmakespec;
QString cachefile;
QHash<QString, QString> properties;
#ifndef QT_BOOTSTRAPPED
QProcessEnvironment environment;
#endif
QString sysroot;
//QString pro_ext;
//QString res_ext;
// -nocache, -cache, -spec, QMAKESPEC
// -set persistent value
void setCommandLineArguments(const QStringList &args);
#ifdef PROEVALUATOR_INIT_PROPS
bool initProperties(const QString &qmake);
#endif
private:
friend class ProFileEvaluator;
friend class ProFileEvaluator::Private;
void applyHostMode();
QString getEnv(const QString &) const;
QHash<ProString, ProStringList> base_valuemap; // Cached results of qmake.conf, .qmake.cache & default_pre.prf
ProFileEvaluator::FunctionDefs base_functions;
QStringList feature_roots;
QString qmakespec_name;
QString precmds, postcmds;
enum HOST_MODE { HOST_UNKNOWN_MODE, HOST_UNIX_MODE, HOST_WIN_MODE, HOST_MACX_MODE };
HOST_MODE host_mode;
enum TARG_MODE { TARG_UNKNOWN_MODE, TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE,
TARG_SYMBIAN_MODE };
TARG_MODE target_mode;
#ifdef PROEVALUATOR_THREAD_SAFE
QMutex mutex;
QWaitCondition cond;
bool base_inProgress;
#endif
};
Q_DECLARE_TYPEINFO(ProFileEvaluator::FunctionDef, Q_MOVABLE_TYPE);
QT_END_NAMESPACE

View File

@@ -7,6 +7,7 @@ DEPENDPATH *= $$PWD $$PWD/..
# Input
HEADERS += \
qmake_global.h \
qmakeglobals.h \
profileparser.h \
profileevaluator.h \
proitems.h \
@@ -14,6 +15,7 @@ HEADERS += \
ioutils.h
SOURCES += \
qmakeglobals.cpp \
profileparser.cpp \
profileevaluator.cpp \
proitems.cpp \

View File

@@ -0,0 +1,196 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "qmakeglobals.h"
#include "ioutils.h"
#include <QByteArray>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QList>
#include <QRegExp>
#include <QSet>
#include <QStack>
#include <QString>
#include <QStringList>
#include <QTextStream>
#ifdef PROEVALUATOR_THREAD_SAFE
# include <QThreadPool>
#endif
#ifdef Q_OS_UNIX
#include <unistd.h>
#include <sys/utsname.h>
#else
#include <Windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifdef Q_OS_WIN32
#define QT_POPEN _popen
#define QT_PCLOSE _pclose
#else
#define QT_POPEN popen
#define QT_PCLOSE pclose
#endif
QT_BEGIN_NAMESPACE
#define fL1S(s) QString::fromLatin1(s)
QMakeGlobals::QMakeGlobals()
{
#ifdef Q_OS_WIN
dirlist_sep = QLatin1Char(';');
dir_sep = QLatin1Char('\\');
#else
dirlist_sep = QLatin1Char(':');
dir_sep = QLatin1Char('/');
#endif
qmakespec = getEnv(QLatin1String("QMAKESPEC"));
host_mode = HOST_UNKNOWN_MODE;
target_mode = TARG_UNKNOWN_MODE;
#ifdef PROEVALUATOR_THREAD_SAFE
base_inProgress = false;
#endif
}
QMakeGlobals::~QMakeGlobals()
{
}
void QMakeGlobals::setCommandLineArguments(const QStringList &args)
{
QStringList _precmds, _preconfigs, _postcmds, _postconfigs;
bool after = false;
bool isConf = false;
foreach (const QString &arg, args) {
if (isConf) {
isConf = false;
if (after)
_postconfigs << arg;
else
_preconfigs << arg;
} else if (arg.startsWith(QLatin1Char('-'))) {
if (arg == QLatin1String("-after")) {
after = true;
} else if (arg == QLatin1String("-config")) {
isConf = true;
} else if (arg == QLatin1String("-win32")) {
host_mode = HOST_WIN_MODE;
target_mode = TARG_WIN_MODE;
} else if (arg == QLatin1String("-unix")) {
host_mode = HOST_UNIX_MODE;
target_mode = TARG_UNIX_MODE;
} else if (arg == QLatin1String("-macx")) {
host_mode = HOST_MACX_MODE;
target_mode = TARG_MACX_MODE;
}
} else if (arg.contains(QLatin1Char('='))) {
if (after)
_postcmds << arg;
else
_precmds << arg;
}
}
if (!_preconfigs.isEmpty())
_precmds << (fL1S("CONFIG += ") + _preconfigs.join(fL1S(" ")));
precmds = _precmds.join(fL1S("\n"));
if (!_postconfigs.isEmpty())
_postcmds << (fL1S("CONFIG += ") + _postconfigs.join(fL1S(" ")));
postcmds = _postcmds.join(fL1S("\n"));
if (host_mode != HOST_UNKNOWN_MODE)
applyHostMode();
}
void QMakeGlobals::applyHostMode()
{
if (host_mode == HOST_WIN_MODE) {
dir_sep = fL1S("\\");
} else {
dir_sep = fL1S("/");
}
}
QString QMakeGlobals::getEnv(const QString &var) const
{
#ifndef QT_BOOTSTRAPPED
if (!environment.isEmpty())
return environment.value(var);
#endif
return QString::fromLocal8Bit(qgetenv(var.toLocal8Bit().constData()));
}
#ifdef PROEVALUATOR_INIT_PROPS
bool QMakeGlobals::initProperties(const QString &qmake)
{
QByteArray data;
#ifndef QT_BOOTSTRAPPED
QProcess proc;
proc.start(qmake, QStringList() << QLatin1String("-query"));
if (!proc.waitForFinished())
return false;
data = proc.readAll();
#else
if (FILE *proc = QT_POPEN(QString(IoUtils::shellQuote(qmake) + QLatin1String(" -query"))
.toLocal8Bit(), "r")) {
char buff[1024];
while (!feof(proc))
data.append(buff, int(fread(buff, 1, 1023, proc)));
QT_PCLOSE(proc);
}
#endif
foreach (QByteArray line, data.split('\n'))
if (!line.startsWith("QMAKE_")) {
int off = line.indexOf(':');
if (off < 0) // huh?
continue;
if (line.endsWith('\r'))
line.chop(1);
properties.insert(QString::fromLatin1(line.left(off)),
QString::fromLocal8Bit(line.mid(off + 1)));
}
return true;
}
#endif
QT_END_NAMESPACE

View File

@@ -0,0 +1,102 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef QMAKEGLOBALS_H
#define QMAKEGLOBALS_H
#include "qmake_global.h"
#include "proitems.h"
#include "profileevaluator.h"
#include <QHash>
#include <QStringList>
#ifndef QT_BOOTSTRAPPED
# include <QProcess>
#endif
#ifdef PROEVALUATOR_THREAD_SAFE
# include <QMutex>
# include <QWaitCondition>
#endif
QT_BEGIN_NAMESPACE
class QMAKE_EXPORT QMakeGlobals
{
public:
QMakeGlobals();
~QMakeGlobals();
QString dir_sep;
QString dirlist_sep;
QString qmakespec;
QString cachefile;
QHash<QString, QString> properties;
#ifndef QT_BOOTSTRAPPED
QProcessEnvironment environment;
#endif
QString sysroot;
// -nocache, -cache, -spec, QMAKESPEC
// -set persistent value
void setCommandLineArguments(const QStringList &args);
#ifdef PROEVALUATOR_INIT_PROPS
bool initProperties(const QString &qmake);
#endif
private:
void applyHostMode();
QString getEnv(const QString &) const;
QHash<ProString, ProStringList> base_valuemap; // Cached results of qmake.conf, .qmake.cache & default_pre.prf
ProFileEvaluator::FunctionDefs base_functions;
QStringList feature_roots;
QString qmakespec_name;
QString precmds, postcmds;
enum HOST_MODE { HOST_UNKNOWN_MODE, HOST_UNIX_MODE, HOST_WIN_MODE, HOST_MACX_MODE };
HOST_MODE host_mode;
enum TARG_MODE { TARG_UNKNOWN_MODE, TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE,
TARG_SYMBIAN_MODE };
TARG_MODE target_mode;
#ifdef PROEVALUATOR_THREAD_SAFE
QMutex mutex;
QWaitCondition cond;
bool base_inProgress;
#endif
friend class ProFileEvaluator;
friend class ProFileEvaluator::Private;
};
QT_END_NAMESPACE
#endif // QMAKEGLOBALS_H

View File

@@ -30,6 +30,7 @@
**
**************************************************************************/
#include "qmakeglobals.h"
#include "profileparser.h"
#include "profileevaluator.h"

View File

@@ -15,8 +15,8 @@ build_all:!build_pass {
CONFIG += release
}
SOURCES = main.cpp profileparser.cpp profileevaluator.cpp proitems.cpp ioutils.cpp
HEADERS = profileparser.h profileevaluator.h proitems.h ioutils.h
SOURCES = main.cpp qmakeglobals.cpp profileparser.cpp profileevaluator.cpp proitems.cpp ioutils.cpp
HEADERS = qmakeglobals.h profileparser.h profileevaluator.h proitems.h ioutils.h
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
DEFINES += QT_USE_FAST_OPERATOR_PLUS QT_USE_FAST_CONCATENATION