From 24f24c4546c90924faf349daec65c7a754fee61d Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 2 May 2012 18:34:25 +0200 Subject: [PATCH] factor QMakeGlobals into an own file Change-Id: I55d24be06fa78f70bad614a7125c3079c92ab8e5 Reviewed-by: Daniel Teske --- src/plugins/qt4projectmanager/qt4project.h | 2 +- src/plugins/qtsupport/profilereader.h | 1 + src/shared/proparser/profileevaluator.cpp | 128 +------------- src/shared/proparser/profileevaluator.h | 77 +------- src/shared/proparser/proparser.pri | 2 + src/shared/proparser/qmakeglobals.cpp | 196 +++++++++++++++++++++ src/shared/proparser/qmakeglobals.h | 102 +++++++++++ tests/manual/proparser/main.cpp | 1 + tests/manual/proparser/testreader.pro | 4 +- 9 files changed, 308 insertions(+), 205 deletions(-) create mode 100644 src/shared/proparser/qmakeglobals.cpp create mode 100644 src/shared/proparser/qmakeglobals.h diff --git a/src/plugins/qt4projectmanager/qt4project.h b/src/plugins/qt4projectmanager/qt4project.h index cabb191d339..a8457487f39 100644 --- a/src/plugins/qt4projectmanager/qt4project.h +++ b/src/plugins/qt4projectmanager/qt4project.h @@ -45,7 +45,7 @@ #include QT_BEGIN_NAMESPACE -struct QMakeGlobals; +class QMakeGlobals; QT_END_NAMESPACE namespace QtSupport { class ProFileReader; } diff --git a/src/plugins/qtsupport/profilereader.h b/src/plugins/qtsupport/profilereader.h index babb1bea782..be1e4247468 100644 --- a/src/plugins/qtsupport/profilereader.h +++ b/src/plugins/qtsupport/profilereader.h @@ -34,6 +34,7 @@ #define PROFILEREADER_H #include "qtsupport_global.h" +#include "proparser/qmakeglobals.h" #include "proparser/profileparser.h" #include "proparser/profileevaluator.h" diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp index 20b1b9174ac..3ef3838888a 100644 --- a/src/shared/proparser/profileevaluator.cpp +++ b/src/shared/proparser/profileevaluator.cpp @@ -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 diff --git a/src/shared/proparser/profileevaluator.h b/src/shared/proparser/profileevaluator.h index 2265bec7540..266dc785d6d 100644 --- a/src/shared/proparser/profileevaluator.h +++ b/src/shared/proparser/profileevaluator.h @@ -38,17 +38,10 @@ #include #include -#ifndef QT_BOOTSTRAPPED -# include -#endif -#ifdef PROEVALUATOR_THREAD_SAFE -# include -# include -#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 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 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 diff --git a/src/shared/proparser/proparser.pri b/src/shared/proparser/proparser.pri index dbae4abf5bf..cdca47cdf41 100644 --- a/src/shared/proparser/proparser.pri +++ b/src/shared/proparser/proparser.pri @@ -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 \ diff --git a/src/shared/proparser/qmakeglobals.cpp b/src/shared/proparser/qmakeglobals.cpp new file mode 100644 index 00000000000..d23ceb44d3b --- /dev/null +++ b/src/shared/proparser/qmakeglobals.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef PROEVALUATOR_THREAD_SAFE +# include +#endif + +#ifdef Q_OS_UNIX +#include +#include +#else +#include +#endif +#include +#include + +#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 diff --git a/src/shared/proparser/qmakeglobals.h b/src/shared/proparser/qmakeglobals.h new file mode 100644 index 00000000000..ca7a756ebbb --- /dev/null +++ b/src/shared/proparser/qmakeglobals.h @@ -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 +#include +#ifndef QT_BOOTSTRAPPED +# include +#endif +#ifdef PROEVALUATOR_THREAD_SAFE +# include +# include +#endif + +QT_BEGIN_NAMESPACE + +class QMAKE_EXPORT QMakeGlobals +{ +public: + QMakeGlobals(); + ~QMakeGlobals(); + + QString dir_sep; + QString dirlist_sep; + QString qmakespec; + QString cachefile; + QHash 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 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 diff --git a/tests/manual/proparser/main.cpp b/tests/manual/proparser/main.cpp index 2b914e6998a..1f3c7823c39 100644 --- a/tests/manual/proparser/main.cpp +++ b/tests/manual/proparser/main.cpp @@ -30,6 +30,7 @@ ** **************************************************************************/ +#include "qmakeglobals.h" #include "profileparser.h" #include "profileevaluator.h" diff --git a/tests/manual/proparser/testreader.pro b/tests/manual/proparser/testreader.pro index a585ddd2ded..1cdb20307f2 100644 --- a/tests/manual/proparser/testreader.pro +++ b/tests/manual/proparser/testreader.pro @@ -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