Permalink
Browse files

Add a gammaray helper.

This helper will copy share/qtcreator/gammaray into the Qt directory, and compiles it for the Qt version.
It's working like the QML debugger and other helpers.
On Windows, it's only available for MSVC

Most of the work has been done by Milian Wolff
  • Loading branch information...
1 parent 2fba9ba commit beb7722b0383be20c6639aa76c4e9fd1b1f490ed @narnaud narnaud committed Oct 18, 2011
@@ -38,7 +38,8 @@ DATA_DIRS = \
qml \
qml-type-descriptions \
generic-highlighter \
- glsl
+ glsl \
+ gammaray
macx: DATA_DIRS += scripts
# conditionally deployed data
@@ -34,6 +34,7 @@
#include "qmlobservertool.h"
#include "qmldumptool.h"
#include "qmldebugginglibrary.h"
+#include "gammaraytool.h"
#include "qtversionmanager.h"
#include "profilereader.h"
@@ -168,6 +169,7 @@ BaseQtVersion::BaseQtVersion(const QString &qmakeCommand, bool isAutodetected, c
m_hasQmlDump(false),
m_hasQmlDebuggingLibrary(false),
m_hasQmlObserver(false),
+ m_hasGammaray(false),
m_mkspecUpToDate(false),
m_mkspecReadUpToDate(false),
m_defaultConfigIsDebug(true),
@@ -189,6 +191,7 @@ BaseQtVersion::BaseQtVersion()
m_hasQmlDump(false),
m_hasQmlDebuggingLibrary(false),
m_hasQmlObserver(false),
+ m_hasGammaray(false),
m_mkspecUpToDate(false),
m_mkspecReadUpToDate(false),
m_defaultConfigIsDebug(true),
@@ -699,6 +702,7 @@ void BaseQtVersion::updateVersionInfo() const
m_hasQmlDump = false;
m_hasQmlDebuggingLibrary = false;
m_hasQmlObserver = false;
+ m_hasGammaray = false;
if (!queryQMakeVariables(qmakeCommand(), &m_versionInfo, &m_qmakeIsExecutable))
return;
@@ -717,6 +721,7 @@ void BaseQtVersion::updateVersionInfo() const
= !QmlDebuggingLibrary::libraryByInstallData(qtInstallData, false).isEmpty()
|| !QmlDebuggingLibrary::libraryByInstallData(qtInstallData, true).isEmpty();
m_hasQmlObserver = !QmlObserverTool::toolByInstallData(qtInstallData).isEmpty();
+ m_hasGammaray = !GammarayTool::toolByInstallData(qtInstallData).isEmpty();
}
}
@@ -847,6 +852,12 @@ bool BaseQtVersion::hasQmlObserver() const
return m_hasQmlObserver;
}
+bool BaseQtVersion::hasGammaray() const
+{
+ updateVersionInfo();
+ return m_hasGammaray;
+}
+
Utils::Environment BaseQtVersion::qmlToolsEnvironment() const
{
// FIXME: This seems broken!
@@ -895,6 +906,14 @@ QString BaseQtVersion::qmlObserverTool() const
return QmlObserverTool::toolByInstallData(qtInstallData);
}
+QString BaseQtVersion::gammarayTool() const
+{
+ QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
+ if (qtInstallData.isEmpty())
+ return QString();
+ return GammarayTool::toolByInstallData(qtInstallData);
+}
+
QStringList BaseQtVersion::debuggingHelperLibraryLocations() const
{
QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
@@ -188,13 +188,15 @@ class QTSUPPORT_EXPORT BaseQtVersion
virtual QString qmlDebuggingHelperLibrary(bool debugVersion) const;
virtual QString qmlDumpTool(bool debugVersion) const;
virtual QString qmlObserverTool() const;
+ virtual QString gammarayTool() const;
virtual QStringList debuggingHelperLibraryLocations() const;
virtual bool hasGdbDebuggingHelper() const;
virtual bool hasQmlDump() const;
virtual bool hasQmlDebuggingLibrary() const;
virtual bool needsQmlDebuggingLibrary() const;
virtual bool hasQmlObserver() const;
+ virtual bool hasGammaray() const;
Utils::Environment qmlToolsEnvironment() const;
virtual QtConfigWidget *createConfigurationWidget() const;
@@ -235,6 +237,7 @@ class QTSUPPORT_EXPORT BaseQtVersion
mutable bool m_hasQmlDump; // controlled by m_versionInfoUpToDate
mutable bool m_hasQmlDebuggingLibrary; // controlled by m_versionInfoUpdate
mutable bool m_hasQmlObserver; // controlled by m_versionInfoUpToDate
+ mutable bool m_hasGammaray;
mutable bool m_mkspecUpToDate;
mutable QString m_mkspec;
@@ -161,6 +161,40 @@
</property>
</widget>
</item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="gammarayLabel">
+ <property name="text">
+ <string>GammaRay:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QLabel" name="gammarayStatus">
+ <property name="text">
+ <string>TextLabel</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="2">
+ <spacer name="horizontalSpacer_6">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="5" column="4">
+ <widget class="QPushButton" name="gammarayBuildButton">
+ <property name="text">
+ <string>Build</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item>
@@ -34,6 +34,7 @@
#include "qmldumptool.h"
#include "qmlobservertool.h"
#include "qmldebugginglibrary.h"
+#include "gammaraytool.h"
#include "baseqtversion.h"
#include "qtversionmanager.h"
#include <coreplugin/messagemanager.h>
@@ -138,6 +139,9 @@ DebuggingHelperBuildTask::Tools DebuggingHelperBuildTask::availableTools(const B
if (QmlObserverTool::canBuild(version))
tools |= QmlObserver; // requires QML debugging.
}
+ if (GammarayTool::canBuild(version)) {
+ tools |= GammaRay;
+ }
return tools;
}
@@ -148,7 +152,7 @@ void DebuggingHelperBuildTask::showOutputOnError(bool show)
void DebuggingHelperBuildTask::run(QFutureInterface<void> &future)
{
- future.setProgressRange(0, 5);
+ future.setProgressRange(0, 6);
future.setProgressValue(1);
if (m_invalidQt || !buildDebuggingHelper(future)) {
@@ -247,6 +251,19 @@ bool DebuggingHelperBuildTask::buildDebuggingHelper(QFutureInterface<void> &futu
}
}
future.setProgressValue(5);
+ if (m_tools & GammaRay) {
+ QString output, error;
+ bool success = true;
+
+ arguments.directory = GammarayTool::copy(m_qtInstallData, &error);
+ if (arguments.directory.isEmpty()
+ || !GammarayTool::build(arguments, &output, &error))
+ success = false;
+ log(output, error);
+ if (!success)
+ return false;
+ }
+ future.setProgressValue(6);
return true;
}
@@ -53,7 +53,8 @@ class QTSUPPORT_EXPORT DebuggingHelperBuildTask : public QObject {
QmlDebugging = 0x02,
QmlObserver = 0x04,
QmlDump = 0x08,
- AllTools = GdbDebugging | QmlDebugging | QmlObserver | QmlDump
+ GammaRay = 0x10,
+ AllTools = GdbDebugging | QmlDebugging | QmlObserver | QmlDump | GammaRay
};
Q_DECLARE_FLAGS(Tools, DebuggingHelper)
@@ -0,0 +1,175 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 KDAB.
+**
+** Contact: KDAB (info@kdab.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "gammaraytool.h"
+
+#include <coreplugin/icore.h>
+
+#include <utils/synchronousprocess.h>
+#include <utils/qtcassert.h>
+
+#include <projectexplorer/projectexplorerconstants.h>
+
+#include <QtCore/QFileInfo>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QHash>
+#include <QtCore/QProcess>
+#include <QtCore/QDir>
+#include <QtCore/QDateTime>
+#include <QtCore/QStringList>
+#include <QtCore/QQueue>
+
+#include <QtGui/QDesktopServices>
+
+#include "baseqtversion.h"
+
+using namespace QtSupport;
+
+static inline QStringList validBinaryFilenames()
+{
+ return QStringList()
+ << QLatin1String("debug/gammaray.exe")
+ << QLatin1String("gammaray")
+ << QLatin1String("gammaray.app/Contents/MacOS/gammaray");
+}
+
+static QString sourcePath()
+{
+ return Core::ICore::instance()->resourcePath() + QLatin1String("/gammaray/");
+}
+
+static QStringList sourceFileNames()
+{
+ QStringList ret;
+
+ QQueue<QString> paths;
+ paths << sourcePath();
+
+ QDir baseDir(sourcePath());
+ QTC_ASSERT(baseDir.exists(), return ret);
+
+ while(!paths.isEmpty()) {
+ QDir dir(paths.dequeue());
+ QTC_ASSERT(dir.exists(), return ret);
+
+ foreach(const QFileInfo &entry, dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)) {
+ if (entry.isDir()) {
+ paths << entry.absoluteFilePath();
+ } else {
+ ret << baseDir.relativeFilePath(entry.absoluteFilePath());
+ }
+ }
+ }
+
+ return ret;
+}
+
+QString GammarayTool::toolByInstallData(const QString &qtInstallData)
+{
+ if (!Core::ICore::instance())
+ return QString();
+
+ const QStringList directories = installDirectories(qtInstallData);
+ const QStringList binFilenames = validBinaryFilenames();
+
+ return byInstallDataHelper(sourcePath(), sourceFileNames(), directories, binFilenames, false);
+}
+
+QStringList GammarayTool::locationsByInstallData(const QString &qtInstallData)
+{
+ QStringList result;
+ QFileInfo fileInfo;
+ const QStringList binFilenames = validBinaryFilenames();
+ foreach(const QString &directory, installDirectories(qtInstallData)) {
+ if (getHelperFileInfoFor(binFilenames, directory, &fileInfo))
+ result << fileInfo.filePath();
+ }
+ return result;
+}
+
+bool GammarayTool::canBuild(const BaseQtVersion *qtVersion, QString *reason)
+{
+ foreach (const ProjectExplorer::Abi &abi, qtVersion->qtAbis()) {
+ if (abi.os() == ProjectExplorer::Abi::WindowsOS) {
+ // windows version, we only support msvc
+ if (abi.osFlavor() != ProjectExplorer::Abi::WindowsMsvc2005Flavor &&
+ abi.osFlavor() != ProjectExplorer::Abi::WindowsMsvc2008Flavor &&
+ abi.osFlavor() != ProjectExplorer::Abi::WindowsMsvc2010Flavor)
+ {
+ *reason = QCoreApplication::translate("Analyzer::GammarayTool",
+ "Only available for Qt built with MSVC.");
+ return false;
+ }
+ return true;
+ }
+ }
+
+ // assume we can build it everywhere else
+ return true;
+}
+
+QString GammarayTool::copy(const QString &qtInstallData,
+ QString *errorMessage)
+{
+ const QStringList directories = GammarayTool::installDirectories(qtInstallData);
+
+ // Try to find a writeable directory.
+ foreach(const QString &directory, directories) {
+ if (copyFiles(sourcePath(), sourceFileNames(), directory, errorMessage)) {
+ return directory;
+ }
+ }
+ *errorMessage = QCoreApplication::translate("Analyzer::GammarayTool",
+ "gammaray could not be built in any of the directories:\n- %1\n\nReason: %2")
+ .arg(directories.join(QLatin1String("\n- ")), *errorMessage);
+ return QString();
+}
+
+bool GammarayTool::build(BuildHelperArguments arguments, QString *log, QString *errorMessage)
+{
+ arguments.proFilename = QLatin1String("gammaray.pro");
+ arguments.helperName = QCoreApplication::translate("Analyzer::GammarayTool",
+ "GammaRay");
+ return buildHelper(arguments, log, errorMessage);
+}
+
+QStringList GammarayTool::installDirectories(const QString &qtInstallData)
+{
+ const QChar slash = QLatin1Char('/');
+ const uint hash = qHash(qtInstallData);
+ QStringList directories;
+ directories
+ << (qtInstallData + QLatin1String("/qtc-gammaray/"))
+ << QDir::cleanPath((QCoreApplication::applicationDirPath() + QLatin1String("/../qtc-gammaray/") + QString::number(hash))) + slash
+ << (QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/qtc-gammaray/") + QString::number(hash)) + slash;
+ return directories;
+}
Oops, something went wrong.

0 comments on commit beb7722

Please sign in to comment.