Commit 5d985812 authored by Lasse Holmstedt's avatar Lasse Holmstedt
Browse files

Compile qmldump with debugging helpers

Must be compiled during runtime - otherwise, the app may not work
with Qt that is compiled with another compiler.

Reviewed-by: hjk
parent cfe61f64
Nokia Qt LGPL Exception version 1.0
As a special exception to the GNU Lesser General Public License version 2.1, the object code form of a "work that uses the Library" may incorporate material from a header file that is part of the Library. You may distribute such object code under terms of your choice, provided that the incorporated material (i) does not exceed more than 5% of the total size of the Library; and (ii) is limited to numerical parameters, data structure layouts, accessors, macros, inline functions and templates.
\ No newline at end of file
This diff is collapsed.
...@@ -12,10 +12,5 @@ TEMPLATE = app ...@@ -12,10 +12,5 @@ TEMPLATE = app
SOURCES += main.cpp SOURCES += main.cpp
include(../../../../qtcreator.pri)
include(../../../private_headers.pri)
DESTDIR = $$IDE_BIN_PATH
include(../../../rpath.pri)
OTHER_FILES += Info.plist OTHER_FILES += Info.plist
macx:QMAKE_INFO_PLIST = Info.plist macx:QMAKE_INFO_PLIST = Info.plist
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "buildablehelperlibrary.h"
#include <QtCore/QFileInfo>
#include <QtCore/QCoreApplication>
#include <QtCore/QHash>
#include <QtCore/QProcess>
#include <QtCore/QDir>
#include <QtCore/QDateTime>
#include <utils/environment.h>
#include <utils/synchronousprocess.h>
#include <QtGui/QDesktopServices>
#include <QDebug>
namespace Utils {
QString BuildableHelperLibrary::findSystemQt(const Utils::Environment &env)
{
QStringList paths = env.path();
foreach (const QString &path, paths) {
foreach (const QString &possibleCommand, possibleQMakeCommands()) {
const QFileInfo qmake(path + QLatin1Char('/') + possibleCommand);
if (qmake.exists()) {
if (!qtVersionForQMake(qmake.absoluteFilePath()).isNull()) {
return qmake.absoluteFilePath();
}
}
}
}
return QString();
}
QString BuildableHelperLibrary::qtInstallDataDir(const QString &qmakePath)
{
QProcess proc;
proc.start(qmakePath, QStringList() << QLatin1String("-query") << QLatin1String("QT_INSTALL_DATA"));
if (proc.waitForFinished())
return QString(proc.readAll().trimmed());
return QString();
}
QString BuildableHelperLibrary::qtVersionForQMake(const QString &qmakePath)
{
if (qmakePath.isEmpty())
return QString();
QProcess qmake;
qmake.start(qmakePath, QStringList(QLatin1String("--version")));
if (!qmake.waitForStarted()) {
qWarning("Cannot start '%s': %s", qPrintable(qmakePath), qPrintable(qmake.errorString()));
return QString();
}
if (!qmake.waitForFinished()) {
Utils::SynchronousProcess::stopProcess(qmake);
qWarning("Timeout running '%s'.", qPrintable(qmakePath));
return QString();
}
if (qmake.exitStatus() != QProcess::NormalExit) {
qWarning("'%s' crashed.", qPrintable(qmakePath));
return QString();
}
const QString output = QString::fromLocal8Bit(qmake.readAllStandardOutput());
QRegExp regexp(QLatin1String("(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);
regexp2.indexIn(output);
const QString version = regexp2.cap(1);
return version;
}
return QString();
}
QStringList BuildableHelperLibrary::possibleQMakeCommands()
{
// On windows no one has renamed qmake, right?
#ifdef Q_OS_WIN
return QStringList(QLatin1String("qmake.exe"));
#else
// On unix some distributions renamed qmake to avoid clashes
QStringList result;
result << QLatin1String("qmake-qt4") << QLatin1String("qmake4") << QLatin1String("qmake");
return result;
#endif
}
// Copy helper source files to a target directory, replacing older files.
bool BuildableHelperLibrary::copyFiles(const QString &sourcePath,
const QStringList &files,
const QString &targetDirectory,
QString *errorMessage)
{
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 = sourcePath + 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 BuildableHelperLibrary::buildHelper(const QString &helperName, const QString &proFilename,
const QString &directory, const QString &makeCommand,
const QString &qmakeCommand, const QString &mkspec,
const Utils::Environment &env, const QString &targetMode)
{
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::BuildableHelperLibrary",
"Building helper library '%1' in %2\n").arg(helperName, directory);
output += newline;
const QString makeFullPath = env.searchInPath(makeCommand);
if (QFileInfo(directory + QLatin1String("/Makefile")).exists()) {
if (!makeFullPath.isEmpty()) {
const QString cleanTarget = QLatin1String("distclean");
output += QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary",
"Running %1 %2...\n").arg(makeFullPath, cleanTarget);
proc.start(makeFullPath, QStringList(cleanTarget));
proc.waitForFinished();
output += QString::fromLocal8Bit(proc.readAll());
} else {
output += QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary",
"%1 not found in PATH\n").arg(makeCommand);
return output;
}
}
output += newline;
output += QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", "Running %1 ...\n").arg(qmakeCommand);
QStringList makeArgs;
makeArgs << targetMode << QLatin1String("-spec") << (mkspec.isEmpty() ? QString(QLatin1String("default")) : mkspec) << proFilename;
proc.start(qmakeCommand, makeArgs);
proc.waitForFinished();
output += proc.readAll();
output += newline;;
if (!makeFullPath.isEmpty()) {
output += QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", "Running %1 ...\n").arg(makeFullPath);
proc.start(makeFullPath, QStringList());
proc.waitForFinished();
output += proc.readAll();
} else {
output += QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", "%1 not found in PATH\n").arg(makeCommand);
}
return output;
}
bool BuildableHelperLibrary::getHelperFileInfoFor(const QStringList &validBinaryFilenames,
const QString &directory, QFileInfo* info)
{
if (!info)
return false;
foreach(const QString &binaryFilename, validBinaryFilenames) {
info->setFile(directory + binaryFilename);
if (info->exists())
return true;
}
return false;
}
QString BuildableHelperLibrary::byInstallDataHelper(const QString &mainFilename,
const QStringList &installDirectories,
const QStringList &validBinaryFilenames)
{
QDateTime sourcesModified = QFileInfo(mainFilename).lastModified();
// We pretend that the lastmodified of gdbmacros.cpp is 5 minutes before what the file system says
// Because afer a installation from the package the modified dates of gdbmacros.cpp
// and the actual library are close to each other, but not deterministic in one direction
sourcesModified = sourcesModified.addSecs(-300);
// look for the newest helper library in the different locations
QString newestHelper;
QDateTime newestHelperModified = sourcesModified; // prevent using one that's older than the sources
QFileInfo fileInfo;
foreach(const QString &installDirectory, installDirectories) {
if (getHelperFileInfoFor(validBinaryFilenames, installDirectory, &fileInfo)) {
if (fileInfo.lastModified() > newestHelperModified) {
newestHelper = fileInfo.filePath();
newestHelperModified = fileInfo.lastModified();
}
}
}
return newestHelper;
}
} // namespace Utils
#ifndef BUILDABLEHELPERLIBRARY_H
#define BUILDABLEHELPERLIBRARY_H
#include "utils_global.h"
#include <QString>
QT_FORWARD_DECLARE_CLASS(QFileInfo)
namespace Utils {
class Environment;
class QTCREATOR_UTILS_EXPORT BuildableHelperLibrary
{
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 Utils::Environment &env);
// return true if the qmake at qmakePath is qt4 (used by QtVersion)
static QString qtVersionForQMake(const QString &qmakePath);
// returns something like qmake4, qmake, qmake-qt4 or whatever distributions have chosen (used by QtVersion)
static QStringList possibleQMakeCommands();
static QString qtInstallHeadersDir(const QString &qmakePath);
static QString qtInstallDataDir(const QString &qmakePath);
static QString byInstallDataHelper(const QString &mainFilename,
const QStringList &installDirectories,
const QStringList &validBinaryFilenames);
static bool copyFiles(const QString &sourcePath, const QStringList &files,
const QString &targetDirectory, QString *errorMessage);
static QString buildHelper(const QString &helperName, const QString &proFilename,
const QString &directory, const QString &makeCommand,
const QString &qmakeCommand, const QString &mkspec,
const Utils::Environment &env, const QString &targetMode);
static bool getHelperFileInfoFor(const QStringList &validBinaryFilenames,
const QString &directory, QFileInfo* info);
};
}
#endif // BUILDABLEHELPERLIBRARY_H
...@@ -48,7 +48,8 @@ SOURCES += $$PWD/environment.cpp \ ...@@ -48,7 +48,8 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/navigationtreeview.cpp \ $$PWD/navigationtreeview.cpp \
$$PWD/crumblepath.cpp \ $$PWD/crumblepath.cpp \
$$PWD/debuggerlanguagechooser.cpp \ $$PWD/debuggerlanguagechooser.cpp \
$$PWD/historycompleter.cpp $$PWD/historycompleter.cpp \
$$PWD/buildablehelperlibrary.cpp
win32 { win32 {
SOURCES += $$PWD/abstractprocess_win.cpp \ SOURCES += $$PWD/abstractprocess_win.cpp \
...@@ -108,7 +109,8 @@ HEADERS += $$PWD/environment.h \ ...@@ -108,7 +109,8 @@ HEADERS += $$PWD/environment.h \
$$PWD/navigationtreeview.h \ $$PWD/navigationtreeview.h \
$$PWD/crumblepath.h \ $$PWD/crumblepath.h \
$$PWD/debuggerlanguagechooser.h \ $$PWD/debuggerlanguagechooser.h \
$$PWD/historycompleter.h $$PWD/historycompleter.h \
$$PWD/buildablehelperlibrary.h
FORMS += $$PWD/filewizardpage.ui \ FORMS += $$PWD/filewizardpage.ui \
$$PWD/projectintropage.ui \ $$PWD/projectintropage.ui \
......
...@@ -244,7 +244,7 @@ QStringList CMakeRunConfiguration::dumperLibraryLocations() const ...@@ -244,7 +244,7 @@ QStringList CMakeRunConfiguration::dumperLibraryLocations() const
{ {
QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment()); QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath); QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
return ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryLocationsByInstallData(qtInstallData); return ProjectExplorer::DebuggingHelperLibrary::locationsByInstallData(qtInstallData);
} }
Utils::Environment CMakeRunConfiguration::baseEnvironment() const Utils::Environment CMakeRunConfiguration::baseEnvironment() const
......
...@@ -550,7 +550,7 @@ QStringList CustomExecutableRunConfiguration::dumperLibraryLocations() const ...@@ -550,7 +550,7 @@ QStringList CustomExecutableRunConfiguration::dumperLibraryLocations() const
{ {
QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment()); QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath); QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
return ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryLocationsByInstallData(qtInstallData); return ProjectExplorer::DebuggingHelperLibrary::locationsByInstallData(qtInstallData);
} }
ProjectExplorer::ToolChain::ToolChainType CustomExecutableRunConfiguration::toolChainType() const ProjectExplorer::ToolChain::ToolChainType CustomExecutableRunConfiguration::toolChainType() const
......
...@@ -43,20 +43,12 @@ ...@@ -43,20 +43,12 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
QString DebuggingHelperLibrary::findSystemQt(const Utils::Environment &env) static inline QStringList validBinaryFilenames()
{ {
QStringList paths = env.path(); return QStringList()
foreach (const QString &path, paths) { << QLatin1String("debug/gdbmacros.dll")
foreach (const QString &possibleCommand, possibleQMakeCommands()) { << QLatin1String("libgdbmacros.dylib")
const QFileInfo qmake(path + QLatin1Char('/') + possibleCommand); << QLatin1String("libgdbmacros.so");
if (qmake.exists()) {
if (!qtVersionForQMake(qmake.absoluteFilePath()).isNull()) {
return qmake.absoluteFilePath();
}
}
}
}
return QString();
} }
QStringList DebuggingHelperLibrary::debuggingHelperLibraryDirectories(const QString &qtInstallData) QStringList DebuggingHelperLibrary::debuggingHelperLibraryDirectories(const QString &qtInstallData)
...@@ -71,43 +63,13 @@ QStringList DebuggingHelperLibrary::debuggingHelperLibraryDirectories(const QStr ...@@ -71,43 +63,13 @@ QStringList DebuggingHelperLibrary::debuggingHelperLibraryDirectories(const QStr
return directories; return directories;
} }
QString DebuggingHelperLibrary::qtInstallDataDir(const QString &qmakePath) QStringList DebuggingHelperLibrary::locationsByInstallData(const QString &qtInstallData)
{
QProcess proc;
proc.start(qmakePath, QStringList() << QLatin1String("-query") << QLatin1String("QT_INSTALL_DATA"));
if (proc.waitForFinished())
return QString(proc.readAll().trimmed());
return QString();
}
// Debugging Helper Library
static inline bool getHelperFileInfoFor(const QString &directory, QFileInfo* info)
{
if (!info)
return false;
info->setFile(directory + QLatin1String("debug/gdbmacros.dll"));
if (info->exists())
return true;
info->setFile(directory + QLatin1String("libgdbmacros.dylib"));
if (info->exists())
return true;
info->setFile(directory + QLatin1String("libgdbmacros.so"));
if (info->exists())
return true;
return false;
}
QStringList DebuggingHelperLibrary::debuggingHelperLibraryLocationsByInstallData(const QString &qtInstallData)
{ {
QStringList result; QStringList result;
QFileInfo fileInfo; QFileInfo fileInfo;
const QStringList binFilenames = validBinaryFilenames();
foreach(const QString &directory, debuggingHelperLibraryDirectories(qtInstallData)) { foreach(const QString &directory, debuggingHelperLibraryDirectories(qtInstallData)) {
if (getHelperFileInfoFor(directory, &fileInfo)) if (getHelperFileInfoFor(binFilenames, directory, &fileInfo))
result << fileInfo.filePath(); result << fileInfo.filePath();
} }
return result; return result;
...@@ -117,60 +79,17 @@ QString DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(const QStrin ...@@ -117,60 +79,17 @@ QString DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(const QStrin
{ {
if (!Core::ICore::instance()) if (!Core::ICore::instance())
return QString(); return QString();
const QString dumperSourcePath = Core::ICore::instance()->resourcePath() + QLatin1String("/gdbmacros/");
QDateTime sourcesModified = QFileInfo(dumperSourcePath + "gdbmacros.cpp").lastModified();
// We pretend that the lastmodified of gdbmacros.cpp is 5 minutes before what the file system says
// Because afer a installation from the package the modified dates of gdbmacros.cpp
// and the actual library are close to each other, but not deterministic in one direction
sourcesModified = sourcesModified.addSecs(-300);
// look for the newest helper library in the different locations const QString mainFilename = Core::ICore::instance()->resourcePath()
QString newestHelper; + QLatin1String("/gdbmacros/gdbmacros.cpp");
QDateTime newestHelperModified = sourcesModified; // prevent using one that's older than the sources const QStringList directories = DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData);
QFileInfo fileInfo; const QStringList binFilenames = validBinaryFilenames();
foreach(const QString &directory, debuggingHelperLibraryDirectories(qtInstallData)) {
if (getHelperFileInfoFor(directory, &fileInfo)) {
if (fileInfo.lastModified() > newestHelperModified) {
newestHelper = fileInfo.filePath();
newestHelperModified = fileInfo.lastModified();
}
}
}
return newestHelper;
}
// Copy helper source files to a target directory, replacing older files. return byInstallDataHelper(mainFilename, directories, binFilenames);
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, QString DebuggingHelperLibrary::copy(const QString &qtInstallData,
QString *errorMessage) QString *errorMessage)
{ {
// Locations to try: // Locations to try:
// $QTDIR/qtc-debugging-helper // $QTDIR/qtc-debugging-helper
...@@ -179,11 +98,15 @@ QString DebuggingHelperLibrary::copyDebuggingHelperLibrary(const QString &qtInst ...@@ -179,11 +98,15 @@ QString DebuggingHelperLibrary::copyDebuggingHelperLibrary(const QString &qtInst
const QStringList directories = DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData); const QStringList directories = DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData);
QStringList files; QStringList files;
files << QLatin1String("gdbmacros.cpp") << QLatin1String("gdbmacros_p.h") << QLatin1String("gdbmacros.h") << QLatin1String("gdbmacros.pro") files << QLatin1String("gdbmacros.cpp") << QLatin1String("gdbmacros_p.h")
<< QLatin1String("gdbmacros.h") << QLatin1String("gdbmacros.pro")
<< QLatin1String("LICENSE.LGPL") << QLatin1String("LGPL_EXCEPTION.TXT"); << QLatin1String("LICENSE.LGPL") << QLatin1String("LGPL_EXCEPTION.TXT");
QString sourcePath = Core::ICore::instance()->resourcePath() + QLatin1String("/gdbmacros/");
// Try to find a writeable directory. // Try to find a writeable directory.
foreach(const QString &directory, directories) foreach(const QString &directory, directories)
if (copyDebuggingHelperFiles(files, directory, errorMessage)) { if (copyFiles(sourcePath, files, directory, errorMessage)) {
errorMessage->clear(); errorMessage->clear();
return directory; return directory;
} }
...@@ -192,97 +115,10 @@ QString DebuggingHelperLibrary::copyDebuggingHelperLibrary(const QString &qtInst ...@@ -192,97 +115,10 @@ QString DebuggingHelperLibrary::copyDebuggingHelperLibrary(const QString &qtInst
return QString(); return QString();
} }
QString DebuggingHelperLibrary::buildDebuggingHelperLibrary(const QString &directory, const QString &makeCommand, QString DebuggingHelperLibrary::build(const QString &directory, const QString &makeCommand,
const QString &qmakeCommand, const QString &mkspec, const QString &qmakeCommand, const QString &mkspec,
const Utils::Environment &env, const QString &targetMode) const Utils::Environment &env, const QString &targetMode)
{
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;
const QString makeFullPath = env.searchInPath(makeCommand);
if (QFileInfo(directory + QLatin1String("/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));
proc.waitForFinished();
output += QString::fromLocal8Bit(proc.readAll());
} else {
output += QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "%1 not found in PATH\n").arg(makeCommand);