2009-04-28 12:43:04 +02:00
/**************************************************************************
* *
* * This file is part of Qt Creator
* *
2010-03-05 11:25:49 +01:00
* * Copyright ( c ) 2010 Nokia Corporation and / or its subsidiary ( - ies ) .
2009-04-28 12:43:04 +02:00
* *
2009-06-17 00:01:27 +10:00
* * Contact : Nokia Corporation ( qt - info @ nokia . com )
2009-04-28 12:43:04 +02:00
* *
* * 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
2009-08-14 09:30:56 +02:00
* * contact the sales department at http : //qt.nokia.com/contact.
2009-04-28 12:43:04 +02:00
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "debugginghelper.h"
2009-08-07 15:20:05 +02:00
2009-04-28 12:43:04 +02:00
# include <coreplugin/icore.h>
# include <QtCore/QFileInfo>
2009-08-07 15:20:05 +02:00
# include <QtCore/QCoreApplication>
2009-04-28 12:43:04 +02:00
# include <QtCore/QHash>
# include <QtCore/QProcess>
# include <QtCore/QDir>
# include <QtCore/QDateTime>
2009-08-07 15:20:05 +02:00
2010-09-08 15:22:58 +02:00
# include <utils/synchronousprocess.h>
2009-04-28 12:43:04 +02:00
# include <QtGui/QDesktopServices>
using namespace ProjectExplorer ;
2010-09-27 15:51:49 +02:00
static inline QStringList validBinaryFilenames ( )
2009-04-28 12:43:04 +02:00
{
2010-09-27 15:51:49 +02:00
return QStringList ( )
< < QLatin1String ( " debug/gdbmacros.dll " )
< < QLatin1String ( " libgdbmacros.dylib " )
< < QLatin1String ( " libgdbmacros.so " ) ;
2009-04-28 12:43:04 +02:00
}
2009-09-03 19:16:22 +02:00
QStringList DebuggingHelperLibrary : : debuggingHelperLibraryDirectories ( const QString & qtInstallData )
2009-04-28 12:43:04 +02:00
{
2009-08-07 15:20:05 +02:00
const QChar slash = QLatin1Char ( ' / ' ) ;
2009-09-03 19:16:22 +02:00
const uint hash = qHash ( qtInstallData ) ;
2009-04-28 12:43:04 +02:00
QStringList directories ;
directories
2009-08-07 15:20:05 +02:00
< < ( 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 ;
2009-04-28 12:43:04 +02:00
return directories ;
}
2010-09-27 15:51:49 +02:00
QStringList DebuggingHelperLibrary : : locationsByInstallData ( const QString & qtInstallData )
2009-08-07 15:20:05 +02:00
{
QStringList result ;
2009-10-29 12:04:43 +01:00
QFileInfo fileInfo ;
2010-09-27 15:51:49 +02:00
const QStringList binFilenames = validBinaryFilenames ( ) ;
2009-10-29 12:04:43 +01:00
foreach ( const QString & directory , debuggingHelperLibraryDirectories ( qtInstallData ) ) {
2010-09-27 15:51:49 +02:00
if ( getHelperFileInfoFor ( binFilenames , directory , & fileInfo ) )
2009-10-29 12:04:43 +01:00
result < < fileInfo . filePath ( ) ;
}
2009-07-15 17:41:45 +02:00
return result ;
}
2009-09-03 19:16:22 +02:00
QString DebuggingHelperLibrary : : debuggingHelperLibraryByInstallData ( const QString & qtInstallData )
2009-04-28 12:43:04 +02:00
{
2010-06-08 13:55:50 +02:00
if ( ! Core : : ICore : : instance ( ) )
return QString ( ) ;
2009-09-17 15:47:28 +02:00
2010-09-27 15:51:49 +02:00
const QString mainFilename = Core : : ICore : : instance ( ) - > resourcePath ( )
+ QLatin1String ( " /gdbmacros/gdbmacros.cpp " ) ;
const QStringList directories = DebuggingHelperLibrary : : debuggingHelperLibraryDirectories ( qtInstallData ) ;
const QStringList binFilenames = validBinaryFilenames ( ) ;
2009-04-28 12:43:04 +02:00
2010-09-27 15:51:49 +02:00
return byInstallDataHelper ( mainFilename , directories , binFilenames ) ;
2009-08-07 15:20:05 +02:00
}
2010-09-27 15:51:49 +02:00
QString DebuggingHelperLibrary : : copy ( const QString & qtInstallData ,
QString * errorMessage )
2009-04-28 12:43:04 +02:00
{
// Locations to try:
// $QTDIR/qtc-debugging-helper
// $APPLICATION-DIR/qtc-debugging-helper/$hash
// $USERDIR/qtc-debugging-helper/$hash
2009-09-03 19:16:22 +02:00
const QStringList directories = DebuggingHelperLibrary : : debuggingHelperLibraryDirectories ( qtInstallData ) ;
2009-04-28 12:43:04 +02:00
QStringList files ;
2010-09-27 15:51:49 +02:00
files < < QLatin1String ( " gdbmacros.cpp " ) < < QLatin1String ( " gdbmacros_p.h " )
< < QLatin1String ( " gdbmacros.h " ) < < QLatin1String ( " gdbmacros.pro " )
2009-08-07 15:20:05 +02:00
< < QLatin1String ( " LICENSE.LGPL " ) < < QLatin1String ( " LGPL_EXCEPTION.TXT " ) ;
2010-09-27 15:51:49 +02:00
QString sourcePath = Core : : ICore : : instance ( ) - > resourcePath ( ) + QLatin1String ( " /gdbmacros/ " ) ;
2009-08-07 15:20:05 +02:00
// Try to find a writeable directory.
foreach ( const QString & directory , directories )
2010-09-27 15:51:49 +02:00
if ( copyFiles ( sourcePath , files , directory , errorMessage ) ) {
2009-08-07 15:20:05 +02:00
errorMessage - > clear ( ) ;
2009-08-07 14:20:27 +02:00
return directory ;
2009-08-07 15:20:05 +02:00
}
* errorMessage = QCoreApplication : : translate ( " ProjectExplorer::DebuggingHelperLibrary " , " The debugger helpers could not be built in any of the directories: \n - %1 \n \n Reason: %2 " )
. arg ( directories . join ( QLatin1String ( " \n - " ) ) , * errorMessage ) ;
return QString ( ) ;
2009-04-28 12:43:04 +02:00
}
2010-09-27 15:51:49 +02:00
QString DebuggingHelperLibrary : : build ( const QString & directory , const QString & makeCommand ,
const QString & qmakeCommand , const QString & mkspec ,
const Utils : : Environment & env , const QString & targetMode )
2009-04-28 12:43:04 +02:00
{
2010-09-27 15:51:49 +02:00
return buildHelper ( QCoreApplication : : tr ( " GDB helper " ) , QLatin1String ( " gdbmacros.pro " ) , directory ,
makeCommand , qmakeCommand , mkspec , env , targetMode ) ;
2009-04-28 12:43:04 +02:00
}