Refactoring: Use one common code to find the debugging helper library

Remove duplicated code from cmakeprojectmanager.
This commit is contained in:
dt
2009-04-24 14:59:47 +02:00
parent 55cc9fed5c
commit b419403b0f
5 changed files with 184 additions and 194 deletions

View File

@@ -156,81 +156,7 @@ QString CMakeManager::qtVersionForQMake(const QString &qmakePath)
return QString();
}
// this is mostly a copy from qt4versionmanager
// TODO refactor this code
// returns QPair< QTDIR, QT_INSTALL_DATA >
QPair<QString, QString> CMakeManager::findQtDir(const ProjectExplorer::Environment &env)
{
QStringList possibleCommands;
// On windows noone has renamed qmake, right?
#ifdef Q_OS_WIN
possibleCommands << "qmake.exe";
#endif
// On unix some distributions renamed qmake to avoid clashes
possibleCommands << "qmake-qt4" << "qmake4" << "qmake";
QStringList paths = env.path();
foreach (const QString &path, paths) {
foreach (const QString &possibleCommand, possibleCommands) {
QFileInfo qmake(path + "/" + possibleCommand);
if (qmake.exists()) {
if (!qtVersionForQMake(qmake.absoluteFilePath()).isNull()) {
QDir qtDir = qmake.absoluteDir();
qtDir.cdUp();
QProcess proc;
proc.start(qmake.absoluteFilePath(), QStringList() << "-query" << "QT_INSTALL_DATA");
if (proc.waitForFinished()) {
return qMakePair(qtDir.absolutePath(), QString(proc.readAll().trimmed()));
} else {
proc.kill();
QDir dir(qmake.absoluteDir());
dir.cdUp();
return qMakePair(qtDir.absolutePath(), dir.absolutePath());
}
}
}
}
}
return qMakePair(QString(), QString());
}
// This code is more or less duplicated in qtversionmanager
QString CMakeManager::findDumperLibrary(const ProjectExplorer::Environment &env)
{
static ProjectExplorer::Environment lastenv;
static QString lastpath;
if (lastenv == env)
return lastpath;
QPair<QString, QString> pair = findQtDir(env);
QString qtInstallDataDir = pair.second;
if (qtInstallDataDir.isEmpty())
return QString();
uint hash = qHash(pair.first);
QStringList directories;
directories
<< (qtInstallDataDir + "/qtc-debugging-helper/")
<< (QApplication::applicationDirPath() + "/../qtc-debugging-helper/" + QString::number(hash)) + "/"
<< (QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/qtc-debugging-helper/" + QString::number(hash)) + "/";
foreach(const QString &directory, directories) {
#if defined(Q_OS_WIN)
QFileInfo fi(directory + "debug/gdbmacros.dll");
#elif defined(Q_OS_MAC)
QFileInfo fi(directory + "libgdbmacros.dylib");
#else // generic UNIX
QFileInfo fi(directory + "libgdbmacros.so");
#endif
if (fi.exists()) {
lastpath = fi.filePath();
return lastpath;
}
}
lastpath = QString();
return lastpath;
}
/////
////
// CMakeRunner
////
// TODO give a better name, what this class is to update cached information