forked from qt-creator/qt-creator
Revert "Debugger: Improve the helper build mechanism on the settings page."
This reverts commit debb3961c2
.
Success cannot be properly detected.
This commit is contained in:
@@ -28,15 +28,13 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "debugginghelper.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QDateTime>
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QDesktopServices>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
@@ -46,7 +44,7 @@ QString DebuggingHelperLibrary::findSystemQt(const Environment &env)
|
||||
QStringList paths = env.path();
|
||||
foreach (const QString &path, paths) {
|
||||
foreach (const QString &possibleCommand, possibleQMakeCommands()) {
|
||||
const QFileInfo qmake(path + QLatin1Char('/') + possibleCommand);
|
||||
QFileInfo qmake(path + "/" + possibleCommand);
|
||||
if (qmake.exists()) {
|
||||
if (!qtVersionForQMake(qmake.absoluteFilePath()).isNull()) {
|
||||
return qmake.absoluteFilePath();
|
||||
@@ -64,13 +62,12 @@ bool DebuggingHelperLibrary::hasDebuggingHelperLibrary(const QString &qmakePath)
|
||||
|
||||
QStringList DebuggingHelperLibrary::debuggingHelperLibraryDirectories(const QString &qtInstallData, const QString &qtpath)
|
||||
{
|
||||
const QChar slash = QLatin1Char('/');
|
||||
const uint hash = qHash(qtpath);
|
||||
uint hash = qHash(qtpath);
|
||||
QStringList directories;
|
||||
directories
|
||||
<< (qtInstallData + QLatin1String("/qtc-debugging-helper/"))
|
||||
<< QDir::cleanPath((QCoreApplication::applicationDirPath() + QLatin1String("/../qtc-debugging-helper/") + QString::number(hash))) + slash
|
||||
<< (QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/qtc-debugging-helper/") + QString::number(hash)) + slash;
|
||||
<< (qtInstallData + "/qtc-debugging-helper/")
|
||||
<< QDir::cleanPath((QApplication::applicationDirPath() + "/../qtc-debugging-helper/" + QString::number(hash))) + "/"
|
||||
<< (QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/qtc-debugging-helper/" + QString::number(hash)) + "/";
|
||||
return directories;
|
||||
}
|
||||
|
||||
@@ -87,7 +84,7 @@ QString DebuggingHelperLibrary::debuggingHelperLibrary(const QString &qmakePath)
|
||||
QString DebuggingHelperLibrary::qtInstallDataDir(const QString &qmakePath)
|
||||
{
|
||||
QProcess proc;
|
||||
proc.start(qmakePath, QStringList() << QLatin1String("-query") << QLatin1String("QT_INSTALL_DATA"));
|
||||
proc.start(qmakePath, QStringList() << "-query"<< "QT_INSTALL_DATA");
|
||||
if (proc.waitForFinished())
|
||||
return QString(proc.readAll().trimmed());
|
||||
return QString::null;
|
||||
@@ -102,142 +99,119 @@ QString DebuggingHelperLibrary::qtDir(const QString &qmakePath)
|
||||
|
||||
// Debugging Helper Library
|
||||
|
||||
static inline QString helperFilePath(const QString &directory)
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
return directory + QLatin1String("debug/gdbmacros.dll");
|
||||
#elif defined(Q_OS_MAC)
|
||||
return directory + QLatin1String("libgdbmacros.dylib");
|
||||
#else // generic UNIX
|
||||
return directory + QLatin1String("libgdbmacros.so");
|
||||
#endif
|
||||
}
|
||||
|
||||
QStringList DebuggingHelperLibrary::debuggingHelperLibraryLocations(const QString &qtInstallData, const QString &qtpath)
|
||||
{
|
||||
QStringList result;
|
||||
foreach(const QString &directory, debuggingHelperLibraryDirectories(qtInstallData, qtpath))
|
||||
result << QFileInfo(helperFilePath(directory)).filePath();
|
||||
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
|
||||
result << fi.filePath();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString DebuggingHelperLibrary::debuggingHelperLibrary(const QString &qtInstallData, const QString &qtpath)
|
||||
{
|
||||
foreach(const QString &directory, debuggingHelperLibraryDirectories(qtInstallData, qtpath)) {
|
||||
const QFileInfo fi(helperFilePath(directory));
|
||||
#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 DebuggingHelperLibrary::buildDebuggingHelperLibrary(const QString &qmakePath, const QString &make, const Environment &env)
|
||||
{
|
||||
QString errorMessage;
|
||||
const QString directory = copyDebuggingHelperLibrary(qtInstallDataDir(qmakePath), qtDir(qmakePath), &errorMessage);
|
||||
QString directory = copyDebuggingHelperLibrary(qtInstallDataDir(qmakePath), qtDir(qmakePath));
|
||||
if (directory.isEmpty())
|
||||
return errorMessage;
|
||||
return QString::null;
|
||||
return buildDebuggingHelperLibrary(directory, make, qmakePath, QString::null, env);
|
||||
}
|
||||
|
||||
// Copy helper source files to a target directory, replacing older files.
|
||||
static bool copyDebuggingHelperFiles(const QStringList &files,
|
||||
const QString &targetDirectory,
|
||||
QString *errorMessage)
|
||||
{
|
||||
const QString dumperSourcePath = Core::ICore::instance()->resourcePath() + QLatin1String("/gdbmacros/");
|
||||
if (!QDir().mkpath(targetDirectory)) {
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "The target directory %1 could not be created.").arg(targetDirectory);
|
||||
return false;
|
||||
}
|
||||
foreach (const QString &file, files) {
|
||||
const QString source = dumperSourcePath + file;
|
||||
const QString dest = targetDirectory + file;
|
||||
const QFileInfo destInfo(dest);
|
||||
if (destInfo.exists()) {
|
||||
if (destInfo.lastModified() >= QFileInfo(source).lastModified())
|
||||
continue;
|
||||
if (!QFile::remove(dest)) {
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "The existing file %1 could not be removed.").arg(destInfo.absoluteFilePath());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!QFile::copy(source, dest)) {
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "The file %1 could not be copied to %2.").arg(source, dest);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QString DebuggingHelperLibrary::copyDebuggingHelperLibrary(const QString &qtInstallData,
|
||||
const QString &qtdir,
|
||||
QString *errorMessage)
|
||||
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
|
||||
const QStringList directories = DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData, qtdir);
|
||||
QStringList directories = DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData, qtdir);
|
||||
|
||||
QStringList files;
|
||||
files << QLatin1String("gdbmacros.cpp") << QLatin1String("gdbmacros.pro")
|
||||
<< QLatin1String("LICENSE.LGPL") << QLatin1String("LGPL_EXCEPTION.TXT");
|
||||
// Try to find a writeable directory.
|
||||
foreach(const QString &directory, directories)
|
||||
if (copyDebuggingHelperFiles(files, directory, errorMessage)) {
|
||||
errorMessage->clear();
|
||||
return directory;
|
||||
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);
|
||||
}
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "The debugger helpers could not be built in any of the directories:\n- %1\n\nReason: %2")
|
||||
.arg(directories.join(QLatin1String("\n- ")), *errorMessage);
|
||||
return QString();
|
||||
if (success)
|
||||
return directory;
|
||||
}
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
QString DebuggingHelperLibrary::buildDebuggingHelperLibrary(const QString &directory, const QString &makeCommand, const QString &qmakeCommand, const QString &mkspec, const Environment &env)
|
||||
{
|
||||
QString output;
|
||||
const QChar newline = QLatin1Char('\n');
|
||||
// Setup process
|
||||
QProcess proc;
|
||||
proc.setEnvironment(env.toStringList());
|
||||
proc.setWorkingDirectory(directory);
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
output += QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "Building debugging helper library in %1\n").arg(directory);
|
||||
output += newline;
|
||||
output += QString("Building debugging helper library in %1\n").arg(directory);
|
||||
output += "\n";
|
||||
|
||||
const QString makeFullPath = env.searchInPath(makeCommand);
|
||||
if (QFileInfo(directory + QLatin1String("/Makefile")).exists()) {
|
||||
QString makeFullPath = env.searchInPath(makeCommand);
|
||||
if (QFileInfo(directory + "/Makefile").exists()) {
|
||||
if (!makeFullPath.isEmpty()) {
|
||||
const QString cleanTarget = QLatin1String("distclean");
|
||||
output += QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "Running %1 %2...\n").arg(makeFullPath, cleanTarget);
|
||||
proc.start(makeFullPath, QStringList(cleanTarget));
|
||||
output += QString("Running %1 clean...\n").arg(makeFullPath);
|
||||
proc.start(makeFullPath, QStringList() << "clean");
|
||||
proc.waitForFinished();
|
||||
output += QString::fromLocal8Bit(proc.readAll());
|
||||
output += proc.readAll();
|
||||
} else {
|
||||
output += QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "%1 not found in PATH\n").arg(makeCommand);
|
||||
output += QString("%1 not found in PATH\n").arg(makeCommand);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
output += newline;
|
||||
output += QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "Running %1 ...\n").arg(qmakeCommand);
|
||||
|
||||
QStringList makeArgs;
|
||||
makeArgs << QLatin1String("-spec")<< (mkspec.isEmpty() ? QString(QLatin1String("default")) : mkspec) << QLatin1String("gdbmacros.pro");
|
||||
proc.start(qmakeCommand, makeArgs);
|
||||
output += QString("\nRunning %1 ...\n").arg(qmakeCommand);
|
||||
|
||||
proc.start(qmakeCommand, QStringList()<<"-spec"<< (mkspec.isEmpty() ? "default" : mkspec) <<"gdbmacros.pro");
|
||||
proc.waitForFinished();
|
||||
|
||||
output += proc.readAll();
|
||||
|
||||
output += newline;;
|
||||
output += "\n";
|
||||
if (!makeFullPath.isEmpty()) {
|
||||
output += QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "Running %1 ...\n").arg(makeFullPath);
|
||||
output += QString("Running %1 ...\n").arg(makeFullPath);
|
||||
proc.start(makeFullPath, QStringList());
|
||||
proc.waitForFinished();
|
||||
output += proc.readAll();
|
||||
} else {
|
||||
output += QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "%1 not found in PATH\n").arg(makeCommand);
|
||||
output += QString("%1 not found in PATH\n").arg(makeCommand);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
@@ -245,14 +219,14 @@ QString DebuggingHelperLibrary::buildDebuggingHelperLibrary(const QString &direc
|
||||
QString DebuggingHelperLibrary::qtVersionForQMake(const QString &qmakePath)
|
||||
{
|
||||
QProcess qmake;
|
||||
qmake.start(qmakePath, QStringList(QLatin1String("--version")));
|
||||
qmake.start(qmakePath, QStringList()<<"--version");
|
||||
if (!qmake.waitForFinished())
|
||||
return false;
|
||||
QString output = qmake.readAllStandardOutput();
|
||||
QRegExp regexp(QLatin1String("(QMake version|QMake version:)[\\s]*([\\d.]*)"), Qt::CaseInsensitive);
|
||||
QRegExp regexp("(QMake version|QMake version:)[\\s]*([\\d.]*)", Qt::CaseInsensitive);
|
||||
regexp.indexIn(output);
|
||||
if (regexp.cap(2).startsWith(QLatin1String("2."))) {
|
||||
QRegExp regexp2(QLatin1String("Using Qt version[\\s]*([\\d\\.]*)"), Qt::CaseInsensitive);
|
||||
if (regexp.cap(2).startsWith("2.")) {
|
||||
QRegExp regexp2("Using Qt version[\\s]*([\\d\\.]*)", Qt::CaseInsensitive);
|
||||
regexp2.indexIn(output);
|
||||
return regexp2.cap(1);
|
||||
}
|
||||
@@ -263,11 +237,11 @@ QStringList DebuggingHelperLibrary::possibleQMakeCommands()
|
||||
{
|
||||
// On windows noone has renamed qmake, right?
|
||||
#ifdef Q_OS_WIN
|
||||
return QStringList(QLatin1String("qmake.exe"));
|
||||
return QStringList() << "qmake.exe";
|
||||
#else
|
||||
// On unix some distributions renamed qmake to avoid clashes
|
||||
QStringList result;
|
||||
result << QLatin1String("qmake-qt4") << QLatin1String("qmake4") << QLatin1String("qmake");
|
||||
result << "qmake-qt4" << "qmake4" << "qmake";
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user