Commit 4e78a952 authored by El Mehdi Fekari's avatar El Mehdi Fekari Committed by Mehdi Fekari

Qnx: Refactor BlackBerryApiLevelConfiguration class

Add a QnxBaseConfiguration class as base class for
the BlackBerryApiLevelConfiguration and the new
QnxConfiguarion classes.

The split of the BlackBerryApiLevelConfiguration logic
makes the code more flexible to add support for
the user's SDP/Qnx configurations.

Upcoming patches adding support for the SDP/Qnx configuration
will depend on this change.

Change-Id: I44258d9a9f0dc44bb196f4178974ad04d4caf70a
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent ec94e042
......@@ -34,6 +34,7 @@
#include "qnxutils.h"
#include "blackberryversionnumber.h"
#include "qnxbaseconfiguration.h"
#include "qnxconstants.h"
#include <utils/environment.h>
......@@ -54,7 +55,7 @@ namespace Internal {
class QnxAbstractQtVersion;
class QnxToolChain;
class BlackBerryApiLevelConfiguration
class BlackBerryApiLevelConfiguration : public QnxBaseConfiguration
{
Q_DECLARE_TR_FUNCTIONS(Qnx::Internal::BlackBerryApiLevelConfiguration)
public:
......@@ -66,20 +67,14 @@ public:
QString ndkPath() const;
QString displayName() const;
QString targetName() const;
QString qnxHost() const;
BlackBerryVersionNumber version() const;
bool isAutoDetected() const;
Utils::FileName autoDetectionSource() const;
bool isActive() const;
bool isValid() const;
Utils::FileName ndkEnvFile() const;
Utils::FileName qmake4BinaryFile() const;
Utils::FileName qmake5BinaryFile() const;
Utils::FileName gccCompiler() const;
Utils::FileName deviceDebuger() const;
Utils::FileName simulatorDebuger() const;
Utils::FileName sysRoot() const;
QList<Utils::EnvironmentItem> qnxEnv() const;
QVariantMap toMap() const;
#ifdef WITH_TESTS
......@@ -87,33 +82,24 @@ public:
static bool fakeConfig();
#endif
protected:
QnxAbstractQtVersion *createQtVersion(
const Utils::FileName &qmakePath, Qnx::QnxArchitecture arch, const QString &versionName);
ProjectExplorer::Kit *createKit(
QnxAbstractQtVersion *version, QnxToolChain *armToolChain, const QVariant &debuggerItemId);
QStringList validationErrors() const;
private:
QString m_displayName;
QString m_targetName;
QString m_qnxHost;
BlackBerryVersionNumber m_version;
Utils::FileName m_autoDetectionSource;
Utils::FileName m_ndkEnvFile;
Utils::FileName m_qmake4BinaryFile;
Utils::FileName m_qmake5BinaryFile;
Utils::FileName m_gccCompiler;
Utils::FileName m_deviceDebugger;
Utils::FileName m_simulatorDebugger;
Utils::FileName m_sysRoot;
QList<Utils::EnvironmentItem> m_qnxEnv;
void ctor();
QnxAbstractQtVersion* createQtVersion(
const Utils::FileName &qmakePath, Qnx::QnxArchitecture arch, const QString &versionName);
QnxToolChain* createToolChain(
ProjectExplorer::Abi abi, const QString &versionName);
QVariant createDebuggerItem(
QList<ProjectExplorer::Abi> abis, Qnx::QnxArchitecture arch, const QString &versionName);
ProjectExplorer::Kit* createKit(
QnxAbstractQtVersion* version, QnxToolChain* toolChain,
const QVariant &debuggerItemId);
#ifdef WITH_TESTS
static bool m_fakeConfig;
#endif
......
......@@ -126,7 +126,7 @@ void BlackBerryConfigurationManager::saveConfigurations()
data.insert(QLatin1String(BBConfigCountKey), count);
const QString newestConfig = (newestApiLevelEnabled())
? NewestConfigurationValue : defaultApiLevel()->ndkEnvFile().toString();
? NewestConfigurationValue : defaultApiLevel()->envFile().toString();
//save default configuration
data.insert(QLatin1String(DefaultConfigurationKey), newestConfig);
......@@ -167,7 +167,7 @@ void BlackBerryConfigurationManager::restoreConfigurations()
BlackBerryApiLevelConfiguration *apiLevel = new BlackBerryApiLevelConfiguration(dMap);
insertApiLevelByVersion(apiLevel);
if (!useNewestConfiguration && (apiLevel->ndkEnvFile().toString() == ndkEnvFile))
if (!useNewestConfiguration && (apiLevel->envFile().toString() == ndkEnvFile))
setDefaultConfiguration(apiLevel);
}
}
......@@ -240,7 +240,7 @@ void BlackBerryConfigurationManager::setDefaultConfiguration(
if (config && !m_apiLevels.contains(config)) {
qWarning() << "BlackBerryConfigurationManager::setDefaultConfiguration -"
" configuration does not belong to this instance: "
<< config->ndkEnvFile().toString();
<< config->envFile().toString();
return;
}
......@@ -269,7 +269,7 @@ void BlackBerryConfigurationManager::setKitsAutoDetectionSource()
if ((version &&
(version->qmakeCommand() == config->qmake4BinaryFile() || version->qmakeCommand() == config->qmake5BinaryFile()))
&& (SysRootKitInformation::sysRoot(kit) == config->sysRoot())) {
kit->setAutoDetectionSource(config->ndkEnvFile().toString());
kit->setAutoDetectionSource(config->envFile().toString());
// Set stickyness since not necessary saved for those kits
kit->setSticky(QtSupport::QtKitInformation::id(), true);
kit->setSticky(ToolChainKitInformation::id(), true);
......@@ -306,7 +306,7 @@ void BlackBerryConfigurationManager::checkToolChainConfiguration()
{
foreach (BlackBerryApiLevelConfiguration *config, m_apiLevels) {
foreach (ToolChain *tc, ToolChainManager::toolChains()) {
if (tc->compilerCommand() == config->gccCompiler()
if (tc->compilerCommand() == config->qccCompilerPath()
&& !tc->id().startsWith(QLatin1String(Constants::QNX_TOOLCHAIN_ID))) {
if (config->isActive()) {
// reset
......@@ -322,7 +322,7 @@ void BlackBerryConfigurationManager::checkToolChainConfiguration()
bool BlackBerryConfigurationManager::addApiLevel(BlackBerryApiLevelConfiguration *config)
{
foreach (BlackBerryApiLevelConfiguration *c, m_apiLevels) {
if (config->ndkEnvFile() == c->ndkEnvFile()) {
if (config->envFile() == c->envFile()) {
if (!config->isAutoDetected())
QMessageBox::warning(Core::ICore::mainWindow(), tr("NDK Already Known"),
tr("The NDK already has a configuration."), QMessageBox::Ok);
......@@ -416,7 +416,7 @@ BlackBerryApiLevelConfiguration *BlackBerryConfigurationManager::apiLevelFromEnv
return 0;
foreach (BlackBerryApiLevelConfiguration *config, m_apiLevels) {
if (config->ndkEnvFile() == envFile)
if (config->envFile() == envFile)
return config;
}
......
......@@ -155,9 +155,9 @@ void BlackBerryNDKSettingsWidget::updateInfoTable(QTreeWidgetItem* currentItem)
BlackBerryApiLevelConfiguration *config = static_cast<BlackBerryApiLevelConfiguration*>(
currentItem->data(0, Qt::UserRole).value<void*>());
m_ui->path->setText(config->ndkEnvFile().toString());
m_ui->path->setText(config->envFile().toString());
m_ui->baseName->setText(config->displayName());
m_ui->host->setText(QDir::toNativeSeparators(config->qnxHost()));
m_ui->host->setText(QDir::toNativeSeparators(config->qnxHost().toString()));
m_ui->target->setText(QDir::toNativeSeparators(config->sysRoot().toString()));
m_ui->version->setText(config->version().toString());
}
......@@ -189,20 +189,20 @@ void BlackBerryNDKSettingsWidget::updateConfigurationList()
if (config->isAutoDetected() && !config->autoDetectionSource().toFileInfo().exists())
toolTip += QLatin1Char('\n') + tr("- Target no longer installed.");
if (!config->ndkEnvFile().toFileInfo().exists())
if (!config->envFile().toFileInfo().exists())
toolTip += QLatin1Char('\n') + tr("- No NDK environment file found.");
if (config->qmake4BinaryFile().isEmpty()
&& config->qmake5BinaryFile().isEmpty())
toolTip += QLatin1Char('\n') + tr("- No Qt version found.");
if (config->gccCompiler().isEmpty())
if (config->qccCompilerPath().isEmpty())
toolTip += QLatin1Char('\n') + tr("- No compiler found.");
if (config->deviceDebuger().isEmpty())
if (config->armDebuggerPath().isEmpty())
toolTip += QLatin1Char('\n') + tr("- No debugger found for device.");
if (config->simulatorDebuger().isEmpty())
if (config->x86DebuggerPath().isEmpty())
toolTip += QLatin1Char('\n') + tr("- No debugger found for simulator.");
item->setToolTip(0, toolTip);
......
......@@ -112,7 +112,7 @@ QList<Utils::EnvironmentItem> BlackBerryQtVersion::environment() const
return QList<Utils::EnvironmentItem>();
QString envFile = m_ndkEnvFile.isEmpty() ? QnxUtils::envFilePath(sdkPath()) : m_ndkEnvFile;
QList<Utils::EnvironmentItem> env = QnxUtils::qnxEnvironmentFromNdkFile(envFile);
QList<Utils::EnvironmentItem> env = QnxUtils::qnxEnvironmentFromEnvFile(envFile);
// BB NDK Host is having qmake executable which is using qt.conf file to specify
// base information. The qt.conf file is using 'CPUVARDIR' environment variable
......
......@@ -106,7 +106,9 @@ SOURCES += qnxplugin.cpp \
blackberryapilevelconfiguration.cpp \
blackberrypotentialkit.cpp \
bardescriptorfilenode.cpp \
bardescriptorfilenodemanager.cpp
bardescriptorfilenodemanager.cpp \
qnxconfiguration.cpp \
qnxbaseconfiguration.cpp
HEADERS += qnxplugin.h\
qnxconstants.h \
......@@ -212,7 +214,9 @@ HEADERS += qnxplugin.h\
blackberryapilevelconfiguration.h \
blackberrypotentialkit.h \
bardescriptorfilenode.h \
bardescriptorfilenodemanager.h
bardescriptorfilenodemanager.h \
qnxconfiguration.h \
qnxbaseconfiguration.h
FORMS += \
blackberrydeviceconfigurationwizardsetuppage.ui \
......
......@@ -211,10 +211,14 @@ QtcPlugin {
"qnxattachdebugsupport.h",
"qnxattachdebugdialog.cpp",
"qnxattachdebugdialog.h",
"qnxbaseconfiguration.cpp",
"qnxbaseconfiguration.h",
"qnxbaseqtconfigwidget.cpp",
"qnxbaseqtconfigwidget.h",
"qnxbaseqtconfigwidget.ui",
"qnxconstants.h",
"qnxconfiguration.cpp",
"qnxconfiguration.h",
"qnxabstractrunsupport.cpp",
"qnxabstractrunsupport.h",
"qnxanalyzesupport.cpp",
......
/**************************************************************************
**
** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
**
** Contact: BlackBerry (qt@blackberry.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "qnxbaseconfiguration.h"
#include <qnxutils.h>
#include <qnxtoolchain.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/toolchainmanager.h>
#include <debugger/debuggerkitinformation.h>
#include <coreplugin/icore.h>
#include <QVariantMap>
#include <QFileInfo>
#include <QMessageBox>
namespace Qnx {
namespace Internal {
const QLatin1String QNXEnvFileKey("EnvFile");
// For backward compatibility
const QLatin1String NDKEnvFileKey("NDKEnvFile");
using namespace Utils;
using namespace ProjectExplorer;
QnxBaseConfiguration::QnxBaseConfiguration()
{
}
QnxBaseConfiguration::QnxBaseConfiguration(const FileName &envFile)
{
ctor(envFile);
}
QnxBaseConfiguration::QnxBaseConfiguration(const QVariantMap &data)
{
QString envFilePath = data.value(QNXEnvFileKey).toString();
if (envFilePath.isEmpty())
envFilePath = data.value(NDKEnvFileKey).toString();
ctor(FileName::fromString(envFilePath));
}
QnxBaseConfiguration::~QnxBaseConfiguration()
{
}
Utils::FileName QnxBaseConfiguration::envFile() const
{
return m_envFile;
}
Utils::FileName QnxBaseConfiguration::qnxTarget() const
{
return m_qnxTarget;
}
Utils::FileName QnxBaseConfiguration::qnxHost() const
{
return m_qnxHost;
}
Utils::FileName QnxBaseConfiguration::qccCompilerPath() const
{
return m_qccCompiler;
}
Utils::FileName QnxBaseConfiguration::armDebuggerPath() const
{
return m_armlev7Debugger;
}
Utils::FileName QnxBaseConfiguration::x86DebuggerPath() const
{
return m_x86Debugger;
}
QList<EnvironmentItem> QnxBaseConfiguration::qnxEnv() const
{
return m_qnxEnv;
}
QVariantMap QnxBaseConfiguration::toMap() const
{
QVariantMap data;
data.insert(QLatin1String(QNXEnvFileKey), m_envFile.toString());
return data;
}
bool QnxBaseConfiguration::isValid() const
{
return !m_qccCompiler.isEmpty()
&& !m_armlev7Debugger.isEmpty()
&& !m_x86Debugger.isEmpty();
}
void QnxBaseConfiguration::ctor(const FileName &envScript)
{
QTC_ASSERT(!envScript.isEmpty() && envScript.toFileInfo().exists(), return);
m_envFile = envScript;
m_qnxEnv = QnxUtils::qnxEnvironmentFromEnvFile(m_envFile.toString());
foreach (const Utils::EnvironmentItem &item, m_qnxEnv) {
if (item.name == QLatin1String("QNX_TARGET"))
m_qnxTarget = Utils::FileName::fromString(item.value);
else if (item.name == QLatin1String("QNX_HOST"))
m_qnxHost = Utils::FileName::fromString(item.value);
}
FileName qccPath = QnxUtils::executableWithExtension(
FileName::fromString(m_qnxHost.toString() + QLatin1String("/usr/bin/qcc")));
FileName armlev7GdbPath = QnxUtils::executableWithExtension(
FileName::fromString(m_qnxHost.toString() + QLatin1String("/usr/bin/ntoarm-gdb")));
if (!armlev7GdbPath.toFileInfo().exists())
armlev7GdbPath = QnxUtils::executableWithExtension(
FileName::fromString(m_qnxHost.toString() + QLatin1String("/usr/bin/ntoarmv7-gdb")));
FileName x86GdbPath = QnxUtils::executableWithExtension(
FileName::fromString(m_qnxHost.toString() + QLatin1String("/usr/bin/ntox86-gdb")));
if (qccPath.toFileInfo().exists())
m_qccCompiler = qccPath;
if (armlev7GdbPath.toFileInfo().exists())
m_armlev7Debugger = armlev7GdbPath;
if (x86GdbPath.toFileInfo().exists())
m_x86Debugger = x86GdbPath;
}
QVariant QnxBaseConfiguration::createDebuggerItem(QnxArchitecture arch,
const QString &displayName)
{
Utils::FileName command = (arch == X86) ? x86DebuggerPath() : armDebuggerPath();
Debugger::DebuggerItem debugger;
debugger.setCommand(command);
debugger.setEngineType(Debugger::GdbEngineType);
debugger.setAbi(Abi(arch == Qnx::ArmLeV7 ? Abi::ArmArchitecture : Abi::X86Architecture,
Abi::LinuxOS, Abi::GenericLinuxFlavor, Abi::ElfFormat, 32));
debugger.setAutoDetected(true);
debugger.setDisplayName(displayName);
return Debugger::DebuggerItemManager::registerDebugger(debugger);
}
QnxToolChain *QnxBaseConfiguration::createToolChain(QnxArchitecture arch,
const QString &displayName,
const QString &ndkPath)
{
QnxToolChain *toolChain = new QnxToolChain(ProjectExplorer::ToolChain::AutoDetection);
toolChain->setCompilerCommand(m_qccCompiler);
toolChain->setTargetAbi(Abi((arch == Qnx::ArmLeV7) ? Abi::ArmArchitecture : Abi::X86Architecture,
Abi::LinuxOS, Abi::GenericLinuxFlavor, Abi::ElfFormat, 32));
toolChain->setDisplayName(displayName);
toolChain->setNdkPath(ndkPath);
ProjectExplorer::ToolChainManager::registerToolChain(toolChain);
return toolChain;
}
QStringList QnxBaseConfiguration::validationErrors() const
{
QStringList errorStrings;
if (m_qccCompiler.isEmpty())
errorStrings << tr("- No GCC compiler found.");
if (m_armlev7Debugger.isEmpty())
errorStrings << tr("- No GDB debugger found for armvle7.");
if (m_x86Debugger.isEmpty())
errorStrings << tr("- No GDB debugger found for x86.");
return errorStrings;
}
}
}
/**************************************************************************
**
** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
**
** Contact: BlackBerry (qt@blackberry.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QNXBASECONFIGURATION_H
#define QNXBASECONFIGURATION_H
#include <qnxconstants.h>
#include <qnxutils.h>
#include <utils/fileutils.h>
#include <utils/environment.h>
#include <projectexplorer/abi.h>
#include <debugger/debuggeritemmanager.h>
#include <qvariant.h>
namespace Qnx {
namespace Internal {
class QnxToolChain;
class QnxBaseConfiguration
{
Q_DECLARE_TR_FUNCTIONS(Qnx::Internal::QnxBaseConfiguration)
public:
QnxBaseConfiguration();
QnxBaseConfiguration(const Utils::FileName &envFile);
QnxBaseConfiguration(const QVariantMap &data);
virtual ~QnxBaseConfiguration();
Utils::FileName envFile() const;
Utils::FileName qnxTarget() const;
Utils::FileName qnxHost() const;
Utils::FileName qccCompilerPath() const;
Utils::FileName armDebuggerPath() const;
Utils::FileName x86DebuggerPath() const;
QList<Utils::EnvironmentItem> qnxEnv() const;
QVariantMap toMap() const;
virtual bool isValid() const;
virtual bool isActive() const = 0;
virtual bool activate() = 0;
virtual void deactivate() = 0;
protected:
QVariant createDebuggerItem(Qnx::QnxArchitecture arch,
const QString &displayName);
QnxToolChain* createToolChain(Qnx::QnxArchitecture arch,
const QString &displayName,
const QString &ndkPath);
virtual QStringList validationErrors() const;
private:
Utils::FileName m_envFile;
Utils::FileName m_qnxTarget;
Utils::FileName m_qnxHost;
Utils::FileName m_qccCompiler;
Utils::FileName m_armlev7Debugger;
Utils::FileName m_x86Debugger;
QList<Utils::EnvironmentItem> m_qnxEnv;
void ctor(const Utils::FileName &envFile);
};
}
}
#endif // QNXBASECONFIGURATION_H
/**************************************************************************
**
** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
**
** Contact: BlackBerry (qt@blackberry.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "qnxconfiguration.h"
#include "qnxutils.h"
#include "qnxtoolchain.h"
#include "debugger/debuggeritem.h"
#include <projectexplorer/toolchainmanager.h>
#include <coreplugin/icore.h>
#include <QMessageBox>
#include <QFileInfo>
namespace Qnx {
namespace Internal {
QnxConfiguration::QnxConfiguration(const Utils::FileName &sdpEnvFile)
: QnxBaseConfiguration(sdpEnvFile)
{
}
bool QnxConfiguration::activate()
{
if (isActive())
return true;
if (!isValid()) {
QString errorMessage = tr("The following errors occurred while activating the QNX configuration:");
foreach (const QString &error, validationErrors())
errorMessage += QLatin1String("\n") + error;
QMessageBox::warning(Core::ICore::mainWindow(), tr("Cannot Set Up QNX Configuration"),
errorMessage, QMessageBox::Ok);
return false;
}
// Create and register toolchain
createToolChain(QnxArchitecture::ArmLeV7,
tr("QCC for QNX armlev7"),
sdpPath().toString());
createToolChain(QnxArchitecture::X86,
tr("QCC for QNX x86"),
sdpPath().toString());
// Create and register debuggers
createDebuggerItem(QnxArchitecture::ArmLeV7,
tr("Debugger for QNX armlev7"));
createDebuggerItem(QnxArchitecture::X86,
tr("Debugger for QNX x86"));
return true;
}
void QnxConfiguration::deactivate()
{
if (!isActive())
return;
foreach (ProjectExplorer::ToolChain *tc,
ProjectExplorer::ToolChainManager::toolChains()) {
if (tc->compilerCommand() == qccCompilerPath())
ProjectExplorer::ToolChainManager::deregisterToolChain(tc);
}
foreach (Debugger::DebuggerItem debuggerItem,
Debugger::DebuggerItemManager::debuggers()) {
if (debuggerItem.command() == armDebuggerPath() ||
debuggerItem.command() == x86DebuggerPath())