forked from qt-creator/qt-creator
Refactoring: Use one common code to find the debugging helper library
Remove duplicated code from cmakeprojectmanager.
This commit is contained in:
@@ -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
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include "cmakeprojectconstants.h"
|
||||
|
||||
#include <projectexplorer/environment.h>
|
||||
#include <projectexplorer/qtversionmanager.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <QtGui/QFormLayout>
|
||||
#include <QtGui/QLineEdit>
|
||||
@@ -140,7 +141,9 @@ void CMakeRunConfiguration::setArguments(const QString &newText)
|
||||
|
||||
QString CMakeRunConfiguration::dumperLibrary() const
|
||||
{
|
||||
return CMakeManager::findDumperLibrary(environment());
|
||||
QString qmakePath = ProjectExplorer::QtVersionManager::findSystemQt(environment());
|
||||
QString dhl = ProjectExplorer::QtVersionManager::debuggingHelperLibrary(qmakePath);
|
||||
return dhl;
|
||||
}
|
||||
|
||||
// Factory
|
||||
|
@@ -428,32 +428,7 @@ void QtVersion::setPath(const QString &path)
|
||||
m_mkspecUpToDate = false;
|
||||
m_qmakeCommand = QString::null;
|
||||
// TODO do i need to optimize this?
|
||||
m_hasDebuggingHelper = !dumperLibrary().isEmpty();
|
||||
}
|
||||
|
||||
QString QtVersion::dumperLibrary() const
|
||||
{
|
||||
uint hash = qHash(path());
|
||||
QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
|
||||
if (qtInstallData.isEmpty())
|
||||
qtInstallData = path();
|
||||
QStringList directories;
|
||||
directories
|
||||
<< (qtInstallData + "/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())
|
||||
return fi.filePath();
|
||||
}
|
||||
return QString();
|
||||
m_hasDebuggingHelper = !debuggingHelperLibrary().isEmpty();
|
||||
}
|
||||
|
||||
void QtVersion::updateSourcePath()
|
||||
@@ -928,61 +903,27 @@ bool QtVersion::hasDebuggingHelper() const
|
||||
return m_hasDebuggingHelper;
|
||||
}
|
||||
|
||||
|
||||
// TODO buildDebuggingHelperLibrary needs to be accessible outside of the
|
||||
// qt4versionmanager
|
||||
// That probably means moving qt4version management into either the projectexplorer
|
||||
// (The Projectexplorer plugin probably needs some splitting up, most of the stuff
|
||||
// could be in a plugin shared by qt4projectmanager, cmakemanager and debugger.)
|
||||
QString QtVersion::buildDebuggingHelperLibrary()
|
||||
QString QtVersion::debuggingHelperLibrary() const
|
||||
{
|
||||
// Locations to try:
|
||||
// $QTDIR/qtc-debugging-helper
|
||||
// $APPLICATION-DIR/qtc-debugging-helper/$hash
|
||||
// $USERDIR/qtc-debugging-helper/$hash
|
||||
|
||||
QString output;
|
||||
uint hash = qHash(path());
|
||||
QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
|
||||
if (qtInstallData.isEmpty())
|
||||
qtInstallData = path();
|
||||
QStringList directories;
|
||||
directories
|
||||
<< qtInstallData + "/qtc-debugging-helper/"
|
||||
<< QApplication::applicationDirPath() + "/../qtc-debugging-helper/" + QString::number(hash) +"/"
|
||||
<< QDesktopServices::storageLocation (QDesktopServices::DataLocation) + "/qtc-debugging-helper/" + QString::number(hash) +"/";
|
||||
|
||||
QStringList files;
|
||||
files << "gdbmacros.cpp" << "gdbmacros.pro"
|
||||
<< "LICENSE.LGPL" << "LGPL_EXCEPTION.TXT";
|
||||
|
||||
foreach(const QString &directory, directories) {
|
||||
QString dumperPath = Core::ICore::instance()->resourcePath() + "/gdbmacros/";
|
||||
bool success = true;
|
||||
QDir().mkpath(directory);
|
||||
foreach (const QString &file, files) {
|
||||
QString source = dumperPath + file;
|
||||
QString dest = directory + file;
|
||||
QFileInfo destInfo(dest);
|
||||
if (destInfo.exists()) {
|
||||
if (destInfo.lastModified() >= QFileInfo(source).lastModified())
|
||||
continue;
|
||||
success &= QFile::remove(dest);
|
||||
return QtVersionManager::debuggingHelperLibrary(qtInstallData, path());
|
||||
}
|
||||
success &= QFile::copy(source, dest);
|
||||
}
|
||||
if (!success)
|
||||
continue;
|
||||
|
||||
// Setup process
|
||||
QProcess proc;
|
||||
|
||||
QString QtVersion::buildDebuggingHelperLibrary()
|
||||
{
|
||||
QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
|
||||
if (qtInstallData.isEmpty())
|
||||
qtInstallData = path();
|
||||
ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
|
||||
addToEnvironment(env);
|
||||
|
||||
// TODO this is a hack to get, to be removed and rewritten for 1.2
|
||||
// For MSVC and MINGW, we need a toolchain to get the right environment
|
||||
ProjectExplorer::ToolChain *toolChain = 0;
|
||||
ProjectExplorer::ToolChain::ToolChainType t = toolchainType();
|
||||
ProjectExplorer::ToolChain *toolChain = 0;
|
||||
if (t == ProjectExplorer::ToolChain::MinGW)
|
||||
toolChain = ProjectExplorer::ToolChain::createMinGWToolChain("g++", mingwDirectory());
|
||||
else if(t == ProjectExplorer::ToolChain::MSVC)
|
||||
@@ -993,13 +934,6 @@ QString QtVersion::buildDebuggingHelperLibrary()
|
||||
toolChain = 0;
|
||||
}
|
||||
|
||||
proc.setEnvironment(env.toStringList());
|
||||
proc.setWorkingDirectory(directory);
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
output += QString("Building debugging helper library in %1\n").arg(directory);
|
||||
output += "\n";
|
||||
|
||||
QString make;
|
||||
// TODO this is butt ugly
|
||||
// only qt4projects have a toolchain() method. (Reason mostly, that in order to create
|
||||
@@ -1014,20 +948,138 @@ QString QtVersion::buildDebuggingHelperLibrary()
|
||||
else if (t == ProjectExplorer::ToolChain::GCC || t == ProjectExplorer::ToolChain::LinuxICC)
|
||||
make = "make";
|
||||
|
||||
QString makeFullPath = env.searchInPath(make);
|
||||
QString directory = QtVersionManager::copyDebuggingHelperLibrary(qtInstallData, path());
|
||||
QString output = QtVersionManager::buildDebuggingHelperLibrary(directory, make, qmakeCommand(), mkspec(), env);
|
||||
m_hasDebuggingHelper = !debuggingHelperLibrary().isEmpty();
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
// Helper functions for building, checking for existance and finding the debugging helper library
|
||||
///
|
||||
|
||||
bool QtVersionManager::hasDebuggingHelperLibrary(const QString &qmakePath)
|
||||
{
|
||||
return !debuggingHelperLibrary(qmakePath).isNull();
|
||||
}
|
||||
|
||||
QStringList QtVersionManager::debuggingHelperLibraryDirectories(const QString &qtInstallData, const QString &qtpath)
|
||||
{
|
||||
uint hash = qHash(qtpath);
|
||||
QStringList directories;
|
||||
directories
|
||||
<< (qtInstallData + "/qtc-debugging-helper/")
|
||||
<< (QApplication::applicationDirPath() + "/../qtc-debugging-helper/" + QString::number(hash)) + "/"
|
||||
<< (QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/qtc-debugging-helper/" + QString::number(hash)) + "/";
|
||||
return directories;
|
||||
}
|
||||
|
||||
QString QtVersionManager::debuggingHelperLibrary(const QString &qmakePath)
|
||||
{
|
||||
return debuggingHelperLibrary(qtInstallDataDir(qmakePath), qtDir(qmakePath));
|
||||
}
|
||||
|
||||
QString QtVersionManager::qtInstallDataDir(const QString &qmakePath)
|
||||
{
|
||||
QProcess proc;
|
||||
proc.start(qmakePath, QStringList() << "-query"<< "QT_INSTALL_DATA");
|
||||
if (proc.waitForFinished())
|
||||
return QString(proc.readAll().trimmed());
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
QString QtVersionManager::qtDir(const QString &qmakePath)
|
||||
{
|
||||
QDir dir = QFileInfo(qmakePath).absoluteDir();
|
||||
dir.cdUp();
|
||||
return dir.absolutePath();
|
||||
}
|
||||
|
||||
// Debugging Helper Library
|
||||
|
||||
QString QtVersionManager::debuggingHelperLibrary(const QString &qtInstallData, const QString &qtpath)
|
||||
{
|
||||
foreach(const QString &directory, debuggingHelperLibraryDirectories(qtInstallData, qtpath)) {
|
||||
#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())
|
||||
return fi.filePath();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
QString QtVersionManager::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)
|
||||
{
|
||||
// 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 files;
|
||||
files << "gdbmacros.cpp" << "gdbmacros.pro"
|
||||
<< "LICENSE.LGPL" << "LGPL_EXCEPTION.TXT";
|
||||
foreach(const QString &directory, directories) {
|
||||
QString dumperPath = Core::ICore::instance()->resourcePath() + "/gdbmacros/";
|
||||
bool success = true;
|
||||
QDir().mkpath(directory);
|
||||
foreach (const QString &file, files) {
|
||||
QString source = dumperPath + file;
|
||||
QString dest = directory + file;
|
||||
QFileInfo destInfo(dest);
|
||||
if (destInfo.exists()) {
|
||||
if (destInfo.lastModified() >= QFileInfo(source).lastModified())
|
||||
continue;
|
||||
success &= QFile::remove(dest);
|
||||
}
|
||||
success &= QFile::copy(source, dest);
|
||||
}
|
||||
if (success)
|
||||
return directory;
|
||||
}
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
QString QtVersionManager::buildDebuggingHelperLibrary(const QString &directory, const QString &makeCommand, const QString &qmakeCommand, const QString &mkspec, const Environment &env)
|
||||
{
|
||||
QString output;
|
||||
// Setup process
|
||||
QProcess proc;
|
||||
proc.setEnvironment(env.toStringList());
|
||||
proc.setWorkingDirectory(directory);
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
output += QString("Building debugging helper library in %1\n").arg(directory);
|
||||
output += "\n";
|
||||
|
||||
QString makeFullPath = env.searchInPath(makeCommand);
|
||||
if (!makeFullPath.isEmpty()) {
|
||||
output += QString("Running %1 clean...\n").arg(makeFullPath);
|
||||
proc.start(makeFullPath, QStringList() << "clean");
|
||||
proc.waitForFinished();
|
||||
output += proc.readAll();
|
||||
} else {
|
||||
output += QString("%1 not found in PATH\n").arg(make);
|
||||
break;
|
||||
output += QString("%1 not found in PATH\n").arg(makeCommand);
|
||||
return output;
|
||||
}
|
||||
|
||||
output += QString("\nRunning %1 ...\n").arg(qmakeCommand());
|
||||
output += QString("\nRunning %1 ...\n").arg(qmakeCommand);
|
||||
|
||||
proc.start(qmakeCommand(), QStringList()<<"-spec"<< mkspec() <<"gdbmacros.pro");
|
||||
proc.start(qmakeCommand, QStringList()<<"-spec"<< (mkspec.isEmpty() ? "default" : mkspec) <<"gdbmacros.pro");
|
||||
proc.waitForFinished();
|
||||
|
||||
output += proc.readAll();
|
||||
@@ -1039,10 +1091,7 @@ QString QtVersion::buildDebuggingHelperLibrary()
|
||||
proc.waitForFinished();
|
||||
output += proc.readAll();
|
||||
} else {
|
||||
output += QString("%1 not found in PATH\n").arg(make);
|
||||
output += QString("%1 not found in PATH\n").arg(makeCommand);
|
||||
}
|
||||
break;
|
||||
}
|
||||
m_hasDebuggingHelper = !dumperLibrary().isEmpty();
|
||||
return output;
|
||||
}
|
||||
|
@@ -78,7 +78,7 @@ public:
|
||||
void addToEnvironment(ProjectExplorer::Environment &env);
|
||||
|
||||
bool hasDebuggingHelper() const;
|
||||
QString dumperLibrary() const;
|
||||
QString debuggingHelperLibrary() const;
|
||||
// Builds a debugging library
|
||||
// returns the output of the commands
|
||||
QString buildDebuggingHelperLibrary();
|
||||
@@ -155,6 +155,18 @@ 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);
|
||||
|
||||
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();
|
||||
|
@@ -422,7 +422,7 @@ QString Qt4RunConfiguration::dumperLibrary() const
|
||||
{
|
||||
Qt4Project *pro = qobject_cast<Qt4Project *>(project());
|
||||
QtVersion *version = pro->qtVersion(pro->activeBuildConfiguration());
|
||||
return version->dumperLibrary();
|
||||
return version->debuggingHelperLibrary();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user