1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "qmldebugginglibrary.h"
35 #include "qt4project.h"
36 #include "qt4projectmanagerconstants.h"
37 #include <coreplugin/icore.h>
38 #include <utils/qtcassert.h>
40 #include <projectexplorer/project.h>
41 #include <QDesktopServices>
42 #include <QCoreApplication>
46 namespace Qt4ProjectManager {
49 QString QmlDebuggingLibrary::libraryByInstallData(const QString &qtInstallData, bool debugBuild)
51 if (!Core::ICore::instance())
54 const QStringList directories = installDirectories(qtInstallData);
56 QStringList binFilenames;
58 binFilenames << QLatin1String("QmlJSDebuggerd.lib");
59 binFilenames << QLatin1String("libQmlJSDebuggerd.a"); // mingw
61 binFilenames << QLatin1String("QmlJSDebugger.lib");
63 binFilenames << QLatin1String("libQmlJSDebugger.a");
65 return byInstallDataHelper(sourcePath(), sourceFileNames(), directories, binFilenames);
68 bool QmlDebuggingLibrary::canBuild(const QtVersion *qtVersion)
70 return qtVersion->qtVersion() >= QtVersionNumber(4, 7, 1);
73 bool QmlDebuggingLibrary::build(const QString &directory, const QString &makeCommand,
74 const QString &qmakeCommand, const QString &mkspec,
75 const Utils::Environment &env, const QString &targetMode,
76 const QStringList &qmakeArguments, QString *output, QString *errorMessage)
78 return buildHelper(QCoreApplication::translate("Qt4ProjectManager::QmlDebuggingLibrary", "QML Debugging"),
79 QLatin1String("qmljsdebugger.pro"),
80 directory, makeCommand, qmakeCommand, mkspec, env, targetMode,
81 qmakeArguments, output, errorMessage);
84 static inline bool mkpath(const QString &targetDirectory, QString *errorMessage)
86 if (!QDir().mkpath(targetDirectory)) {
87 *errorMessage = QCoreApplication::translate("Qt4ProjectManager::QmlDebuggingLibrary", "The target directory %1 could not be created.").arg(targetDirectory);
93 QString QmlDebuggingLibrary::copy(const QString &qtInstallData, QString *errorMessage)
95 const QStringList directories = QmlDebuggingLibrary::installDirectories(qtInstallData);
97 // Try to find a writeable directory.
98 foreach (const QString &directory, directories) {
99 if (!mkpath(directory, errorMessage)) {
102 errorMessage->clear();
105 if (copyFiles(sourcePath(), sourceFileNames(),
106 directory, errorMessage))
108 errorMessage->clear();
112 *errorMessage = QCoreApplication::translate("Qt4ProjectManager::QmlDebuggingLibrary",
113 "QML Debugging library could not be built in any of the directories:\n- %1\n\nReason: %2")
114 .arg(directories.join(QLatin1String("\n- ")), *errorMessage);
118 QStringList QmlDebuggingLibrary::recursiveFileList(const QDir &dir, const QString &prefix)
122 QString _prefix = prefix;
123 if (!_prefix.isEmpty() && !_prefix.endsWith('/')) {
124 _prefix = _prefix + '/';
126 foreach (const QString &fileName, dir.entryList(QDir::Files)) {
127 files << _prefix + fileName;
130 foreach (const QString &subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
131 files += recursiveFileList(QDir(dir.absoluteFilePath(subDir)), _prefix + subDir);
136 QStringList QmlDebuggingLibrary::installDirectories(const QString &qtInstallData)
138 const QChar slash = QLatin1Char('/');
139 const uint hash = qHash(qtInstallData);
140 QStringList directories;
142 << (qtInstallData + QLatin1String("/qtc-qmldbg/"))
143 << QDir::cleanPath((QCoreApplication::applicationDirPath() + QLatin1String("/../qtc-qmldbg/") + QString::number(hash))) + slash
144 << (QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/qtc-qmldbg/") + QString::number(hash)) + slash;
148 QString QmlDebuggingLibrary::sourcePath()
150 return Core::ICore::instance()->resourcePath() + QLatin1String("/qml/qmljsdebugger/");
153 QStringList QmlDebuggingLibrary::sourceFileNames()
155 return recursiveFileList(QDir(sourcePath()));