Commit 48fe0f45 authored by dt's avatar dt
Browse files

Refactoring: Move all the debugging helper static methods into a class

Enables me to move some stuff back again.
parent 84637dfc
......@@ -141,8 +141,8 @@ void CMakeRunConfiguration::setArguments(const QString &newText)
QString CMakeRunConfiguration::dumperLibrary() const
{
QString qmakePath = ProjectExplorer::QtVersionManager::findSystemQt(environment());
QString dhl = ProjectExplorer::QtVersionManager::debuggingHelperLibrary(qmakePath);
QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
QString dhl = ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibrary(qmakePath);
return dhl;
}
......
......@@ -230,7 +230,7 @@ void QtVersionManager::addNewVersionsFromInstaller()
void QtVersionManager::updateSystemVersion()
{
bool haveSystemVersion = false;
QString systemQMakePath = findSystemQt(Environment::systemEnvironment());
QString systemQMakePath = DebuggingHelperLibrary::findSystemQt(Environment::systemEnvironment());
QString systemQtPath;
if (systemQMakePath.isNull()) {
systemQtPath = tr("<not found>");
......@@ -259,7 +259,7 @@ void QtVersionManager::updateSystemVersion()
++m_defaultVersion;
}
QStringList QtVersionManager::possibleQMakeCommands()
QStringList DebuggingHelperLibrary::possibleQMakeCommands()
{
// On windows noone has renamed qmake, right?
#ifdef Q_OS_WIN
......@@ -271,39 +271,6 @@ QStringList QtVersionManager::possibleQMakeCommands()
return result;
}
QString QtVersionManager::qtVersionForQMake(const QString &qmakePath)
{
QProcess qmake;
qmake.start(qmakePath, QStringList()<<"--version");
if (!qmake.waitForFinished())
return false;
QString output = qmake.readAllStandardOutput();
QRegExp regexp("(QMake version|QMake version:)[\\s]*([\\d.]*)", Qt::CaseInsensitive);
regexp.indexIn(output);
if (regexp.cap(2).startsWith("2.")) {
QRegExp regexp2("Using Qt version[\\s]*([\\d\\.]*)", Qt::CaseInsensitive);
regexp2.indexIn(output);
return regexp2.cap(1);
}
return QString();
}
QString QtVersionManager::findSystemQt(const Environment &env)
{
QStringList paths = env.path();
foreach (const QString &path, paths) {
foreach (const QString &possibleCommand, possibleQMakeCommands()) {
QFileInfo qmake(path + "/" + possibleCommand);
if (qmake.exists()) {
if (!qtVersionForQMake(qmake.absoluteFilePath()).isNull()) {
return qmake.absoluteFilePath();
}
}
}
}
return QString::null;
}
QtVersion *QtVersionManager::currentQtVersion() const
{
if (m_defaultVersion < m_versions.count())
......@@ -781,11 +748,11 @@ QString QtVersion::qmakeCommand() const
return m_qmakeCommand;
QDir qtDir = path() + "/bin/";
foreach (const QString &possibleCommand, QtVersionManager::possibleQMakeCommands()) {
foreach (const QString &possibleCommand, DebuggingHelperLibrary::possibleQMakeCommands()) {
QString s = qtDir.absoluteFilePath(possibleCommand);
QFileInfo qmake(s);
if (qmake.exists() && qmake.isExecutable()) {
QString qtVersion = QtVersionManager::qtVersionForQMake(qmake.absoluteFilePath());
QString qtVersion = DebuggingHelperLibrary::qtVersionForQMake(qmake.absoluteFilePath());
if (!qtVersion.isNull()) {
m_qtVersionString = qtVersion;
m_qmakeCommand = qmake.absoluteFilePath();
......@@ -888,7 +855,7 @@ QString QtVersion::debuggingHelperLibrary() const
QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
if (qtInstallData.isEmpty())
qtInstallData = path();
return QtVersionManager::debuggingHelperLibrary(qtInstallData, path());
return DebuggingHelperLibrary::debuggingHelperLibrary(qtInstallData, path());
}
......@@ -928,8 +895,8 @@ QString QtVersion::buildDebuggingHelperLibrary()
else if (t == ProjectExplorer::ToolChain::GCC || t == ProjectExplorer::ToolChain::LinuxICC)
make = "make";
QString directory = QtVersionManager::copyDebuggingHelperLibrary(qtInstallData, path());
QString output = QtVersionManager::buildDebuggingHelperLibrary(directory, make, qmakeCommand(), mkspec(), env);
QString directory = DebuggingHelperLibrary::copyDebuggingHelperLibrary(qtInstallData, path());
QString output = DebuggingHelperLibrary::buildDebuggingHelperLibrary(directory, make, qmakeCommand(), mkspec(), env);
m_hasDebuggingHelper = !debuggingHelperLibrary().isEmpty();
return output;
}
......@@ -939,12 +906,28 @@ QString QtVersion::buildDebuggingHelperLibrary()
// Helper functions for building, checking for existance and finding the debugging helper library
///
bool QtVersionManager::hasDebuggingHelperLibrary(const QString &qmakePath)
QString DebuggingHelperLibrary::findSystemQt(const Environment &env)
{
QStringList paths = env.path();
foreach (const QString &path, paths) {
foreach (const QString &possibleCommand, possibleQMakeCommands()) {
QFileInfo qmake(path + "/" + possibleCommand);
if (qmake.exists()) {
if (!qtVersionForQMake(qmake.absoluteFilePath()).isNull()) {
return qmake.absoluteFilePath();
}
}
}
}
return QString::null;
}
bool DebuggingHelperLibrary::hasDebuggingHelperLibrary(const QString &qmakePath)
{
return !debuggingHelperLibrary(qmakePath).isNull();
}
QStringList QtVersionManager::debuggingHelperLibraryDirectories(const QString &qtInstallData, const QString &qtpath)
QStringList DebuggingHelperLibrary::debuggingHelperLibraryDirectories(const QString &qtInstallData, const QString &qtpath)
{
uint hash = qHash(qtpath);
QStringList directories;
......@@ -955,12 +938,12 @@ QStringList QtVersionManager::debuggingHelperLibraryDirectories(const QString &q
return directories;
}
QString QtVersionManager::debuggingHelperLibrary(const QString &qmakePath)
QString DebuggingHelperLibrary::debuggingHelperLibrary(const QString &qmakePath)
{
return debuggingHelperLibrary(qtInstallDataDir(qmakePath), qtDir(qmakePath));
}
QString QtVersionManager::qtInstallDataDir(const QString &qmakePath)
QString DebuggingHelperLibrary::qtInstallDataDir(const QString &qmakePath)
{
QProcess proc;
proc.start(qmakePath, QStringList() << "-query"<< "QT_INSTALL_DATA");
......@@ -969,7 +952,7 @@ QString QtVersionManager::qtInstallDataDir(const QString &qmakePath)
return QString::null;
}
QString QtVersionManager::qtDir(const QString &qmakePath)
QString DebuggingHelperLibrary::qtDir(const QString &qmakePath)
{
QDir dir = QFileInfo(qmakePath).absoluteDir();
dir.cdUp();
......@@ -978,7 +961,7 @@ QString QtVersionManager::qtDir(const QString &qmakePath)
// Debugging Helper Library
QString QtVersionManager::debuggingHelperLibrary(const QString &qtInstallData, const QString &qtpath)
QString DebuggingHelperLibrary::debuggingHelperLibrary(const QString &qtInstallData, const QString &qtpath)
{
foreach(const QString &directory, debuggingHelperLibraryDirectories(qtInstallData, qtpath)) {
#if defined(Q_OS_WIN)
......@@ -995,20 +978,20 @@ QString QtVersionManager::debuggingHelperLibrary(const QString &qtInstallData, c
}
QString QtVersionManager::buildDebuggingHelperLibrary(const QString &qmakePath, const QString &make, const Environment &env)
QString DebuggingHelperLibrary::buildDebuggingHelperLibrary(const QString &qmakePath, const QString &make, const Environment &env)
{
QString directory = copyDebuggingHelperLibrary(qtInstallDataDir(qmakePath), qtDir(qmakePath));
return buildDebuggingHelperLibrary(directory, make, qmakePath, QString::null, env);
return QString::null;
}
QString QtVersionManager::copyDebuggingHelperLibrary(const QString &qtInstallData, const QString &qtdir)
QString DebuggingHelperLibrary::copyDebuggingHelperLibrary(const QString &qtInstallData, const QString &qtdir)
{
// Locations to try:
// $QTDIR/qtc-debugging-helper
// $APPLICATION-DIR/qtc-debugging-helper/$hash
// $USERDIR/qtc-debugging-helper/$hash
QStringList directories = QtVersionManager::debuggingHelperLibraryDirectories(qtInstallData, qtdir);
QStringList directories = DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData, qtdir);
QStringList files;
files << "gdbmacros.cpp" << "gdbmacros.pro"
......@@ -1034,7 +1017,7 @@ QString QtVersionManager::copyDebuggingHelperLibrary(const QString &qtInstallDat
return QString::null;
}
QString QtVersionManager::buildDebuggingHelperLibrary(const QString &directory, const QString &makeCommand, const QString &qmakeCommand, const QString &mkspec, const Environment &env)
QString DebuggingHelperLibrary::buildDebuggingHelperLibrary(const QString &directory, const QString &makeCommand, const QString &qmakeCommand, const QString &mkspec, const Environment &env)
{
QString output;
// Setup process
......@@ -1075,3 +1058,21 @@ QString QtVersionManager::buildDebuggingHelperLibrary(const QString &directory,
}
return output;
}
QString DebuggingHelperLibrary::qtVersionForQMake(const QString &qmakePath)
{
QProcess qmake;
qmake.start(qmakePath, QStringList()<<"--version");
if (!qmake.waitForFinished())
return false;
QString output = qmake.readAllStandardOutput();
QRegExp regexp("(QMake version|QMake version:)[\\s]*([\\d.]*)", Qt::CaseInsensitive);
regexp.indexIn(output);
if (regexp.cap(2).startsWith("2.")) {
QRegExp regexp2("Using Qt version[\\s]*([\\d\\.]*)", Qt::CaseInsensitive);
regexp2.indexIn(output);
return regexp2.cap(1);
}
return QString();
}
......@@ -145,28 +145,8 @@ public:
void addVersion(QtVersion *version);
// Static Methods
// returns something like qmake4, qmake, qmake-qt4 or whatever distributions have chosen (used by QtVersion)
static QStringList possibleQMakeCommands();
// return true if the qmake at qmakePath is qt4 (used by QtVersion)
static QString qtVersionForQMake(const QString &qmakePath);
static QtVersion::QmakeBuildConfig scanMakefileForQmakeConfig(const QString &directory, QtVersion::QmakeBuildConfig defaultBuildConfig);
static QString findQtVersionFromMakefile(const QString &directory);
// returns the full path to the first qmake, qmake-qt4, qmake4 that has
// at least version 2.0.0 and thus is a qt4 qmake
static QString findSystemQt(const Environment &env);
static bool hasDebuggingHelperLibrary(const QString &qmakePath);
static QString debuggingHelperLibrary(const QString &qmakePath);
static QString buildDebuggingHelperLibrary(const QString &qmakePath, const QString &make, const Environment &env);
private:
static QString copyDebuggingHelperLibrary(const QString &qtInstallData, const QString &qtdir);
static QString debuggingHelperLibrary(const QString &qtInstallData, const QString &qtpath);
static QString buildDebuggingHelperLibrary(const QString &directory, const QString &makeCommand, const QString &qmakeCommand, const QString &mkspec, const Environment &env);
static QStringList debuggingHelperLibraryDirectories(const QString &qtInstallData, const QString &qtpath);
static QString qtInstallDataDir(const QString &qmakePath);
static QString qtDir(const QString &qmakePath);
signals:
void defaultQtVersionChanged();
void qtVersionsChanged();
......@@ -190,6 +170,31 @@ private:
int m_idcount;
};
class PROJECTEXPLORER_EXPORT DebuggingHelperLibrary
{
public:
// returns the full path to the first qmake, qmake-qt4, qmake4 that has
// at least version 2.0.0 and thus is a qt4 qmake
static QString findSystemQt(const Environment &env);
// returns something like qmake4, qmake, qmake-qt4 or whatever distributions have chosen (used by QtVersion)
static QStringList possibleQMakeCommands();
// return true if the qmake at qmakePath is qt4 (used by QtVersion)
static QString qtVersionForQMake(const QString &qmakePath);
static bool hasDebuggingHelperLibrary(const QString &qmakePath);
static QString debuggingHelperLibrary(const QString &qmakePath);
static QString buildDebuggingHelperLibrary(const QString &qmakePath, const QString &make, const Environment &env);
static QString debuggingHelperLibrary(const QString &qtInstallData, const QString &qtpath);
static QString copyDebuggingHelperLibrary(const QString &qtInstallData, const QString &qtdir);
static QString buildDebuggingHelperLibrary(const QString &directory, const QString &makeCommand, const QString &qmakeCommand, const QString &mkspec, const Environment &env);
private:
static QStringList debuggingHelperLibraryDirectories(const QString &qtInstallData, const QString &qtpath);
static QString qtInstallDataDir(const QString &qmakePath);
static QString qtDir(const QString &qmakePath);
};
} // namespace ProjectExplorer
#endif // QTVERSIONMANAGER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment