1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "debugginghelper.h"
36 #include <coreplugin/icore.h>
37 #include <QtCore/QFileInfo>
38 #include <QtCore/QCoreApplication>
39 #include <QtCore/QHash>
40 #include <QtCore/QProcess>
41 #include <QtCore/QDir>
42 #include <QtCore/QDateTime>
44 #include <utils/synchronousprocess.h>
46 #include <QtGui/QDesktopServices>
48 using namespace ProjectExplorer;
50 static inline QStringList validBinaryFilenames()
53 << QLatin1String("debug/gdbmacros.dll")
54 << QLatin1String("libgdbmacros.dylib")
55 << QLatin1String("libgdbmacros.so");
58 QStringList DebuggingHelperLibrary::debuggingHelperLibraryDirectories(const QString &qtInstallData)
60 const QChar slash = QLatin1Char('/');
61 const uint hash = qHash(qtInstallData);
62 QStringList directories;
64 << (qtInstallData + QLatin1String("/qtc-debugging-helper/"))
65 << QDir::cleanPath((QCoreApplication::applicationDirPath() + QLatin1String("/../qtc-debugging-helper/") + QString::number(hash))) + slash
66 << (QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/qtc-debugging-helper/") + QString::number(hash)) + slash;
70 QStringList DebuggingHelperLibrary::locationsByInstallData(const QString &qtInstallData)
74 const QStringList binFilenames = validBinaryFilenames();
75 foreach(const QString &directory, debuggingHelperLibraryDirectories(qtInstallData)) {
76 if (getHelperFileInfoFor(binFilenames, directory, &fileInfo))
77 result << fileInfo.filePath();
82 QString DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(const QString &qtInstallData)
84 if (!Core::ICore::instance())
87 const QString mainFilename = Core::ICore::instance()->resourcePath()
88 + QLatin1String("/gdbmacros/gdbmacros.cpp");
89 const QStringList directories = DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData);
90 const QStringList binFilenames = validBinaryFilenames();
92 return byInstallDataHelper(mainFilename, directories, binFilenames);
95 QString DebuggingHelperLibrary::copy(const QString &qtInstallData,
96 QString *errorMessage)
99 // $QTDIR/qtc-debugging-helper
100 // $APPLICATION-DIR/qtc-debugging-helper/$hash
101 // $USERDIR/qtc-debugging-helper/$hash
102 const QStringList directories = DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData);
105 files << QLatin1String("gdbmacros.cpp") << QLatin1String("gdbmacros_p.h")
106 << QLatin1String("gdbmacros.h") << QLatin1String("gdbmacros.pro")
107 << QLatin1String("LICENSE.LGPL") << QLatin1String("LGPL_EXCEPTION.TXT");
109 QString sourcePath = Core::ICore::instance()->resourcePath() + QLatin1String("/gdbmacros/");
111 // Try to find a writeable directory.
112 foreach(const QString &directory, directories)
113 if (copyFiles(sourcePath, files, directory, errorMessage)) {
114 errorMessage->clear();
117 *errorMessage = QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary",
118 "The debugger helpers could not be built in any of the directories:\n- %1\n\nReason: %2")
119 .arg(directories.join(QLatin1String("\n- ")), *errorMessage);
123 bool DebuggingHelperLibrary::build(const QString &directory, const QString &makeCommand,
124 const QString &qmakeCommand, const QString &mkspec,
125 const Utils::Environment &env, const QString &targetMode,
126 QString *output, QString *errorMessage)
128 return buildHelper(QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary",
129 "GDB helper"), QLatin1String("gdbmacros.pro"), directory,
130 makeCommand, qmakeCommand, mkspec, env, targetMode, output, errorMessage);