Commit ab4207ac authored by Mehdi Fekari's avatar Mehdi Fekari
Browse files

Qnx: Use Utils::Environment for qnx environment



Change-Id: I499ca9be0abc15fc0c57847ff288e80612a536fe
Reviewed-by: default avatarTobias Nätterlund <tobias.naetterlund@kdab.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 295c6884
......@@ -32,6 +32,7 @@
#include "blackberrycertificate.h"
#include "blackberryconfiguration.h"
#include "blackberryconfigurationmanager.h"
#include "blackberryndkprocess.h"
#include <utils/hostosinfo.h>
......@@ -182,18 +183,7 @@ void BlackBerryCertificate::processError()
QString BlackBerryCertificate::command() const
{
QString command;
// TOOD: Give user choice to select NDK from where to get commands
QMultiMap<QString, QString> qnxEnv = BlackBerryConfigurationManager::instance().defaultQnxEnv();
if (!qnxEnv.isEmpty()) {
command = qnxEnv.value(QLatin1String("QNX_HOST"))
+ QLatin1String("/usr/bin/blackberry-keytool");
if (Utils::HostOsInfo::isWindowsHost())
command += QLatin1String(".bat");
}
return command;
return BlackBerryNdkProcess::resolveNdkToolPath(QLatin1String("blackberry-keytool"));
}
} // namespace Internal
......
......@@ -67,16 +67,25 @@ BlackBerryConfiguration::BlackBerryConfiguration(const FileName &ndkEnvFile, boo
m_isAutoDetected = isAutoDetected;
QString ndkPath = ndkEnvFile.parentDir().toString();
m_displayName = displayName.isEmpty() ? ndkPath.split(QDir::separator()).last() : displayName;
m_qnxEnv = QnxUtils::parseEnvironmentFile(m_ndkEnvFile.toString());
m_qnxEnv = QnxUtils::qnxEnvironmentFromNdkFile(m_ndkEnvFile.toString());
QString ndkTarget;
QString qnxHost;
foreach (const Utils::EnvironmentItem &item, m_qnxEnv) {
if (item.name == QLatin1String("QNX_TARGET"))
ndkTarget = item.value;
else if (item.name == QLatin1String("QNX_HOST"))
qnxHost = item.value;
}
QString ndkTarget = m_qnxEnv.value(QLatin1String("QNX_TARGET"));
QString sep = QString::fromLatin1("%1qnx6").arg(QDir::separator());
m_targetName = ndkTarget.split(sep).first().split(QDir::separator()).last();
if (QDir(ndkTarget).exists())
m_sysRoot = FileName::fromString(ndkTarget);
QString qnxHost = m_qnxEnv.value(QLatin1String("QNX_HOST"));
FileName qmake4Path = QnxUtils::executableWithExtension(FileName::fromString(qnxHost + QLatin1String("/usr/bin/qmake")));
FileName qmake5Path = QnxUtils::executableWithExtension(FileName::fromString(qnxHost + QLatin1String("/usr/bin/qt5/qmake")));
FileName gccPath = QnxUtils::executableWithExtension(FileName::fromString(qnxHost + QLatin1String("/usr/bin/qcc")));
......@@ -165,7 +174,7 @@ FileName BlackBerryConfiguration::sysRoot() const
return m_sysRoot;
}
QMultiMap<QString, QString> BlackBerryConfiguration::qnxEnv() const
QList<Utils::EnvironmentItem> BlackBerryConfiguration::qnxEnv() const
{
return m_qnxEnv;
}
......
......@@ -72,7 +72,7 @@ public:
Utils::FileName deviceDebuger() const;
Utils::FileName simulatorDebuger() const;
Utils::FileName sysRoot() const;
QMultiMap<QString, QString> qnxEnv() const;
QList<Utils::EnvironmentItem> qnxEnv() const;
private:
QString m_displayName;
......@@ -85,7 +85,7 @@ private:
Utils::FileName m_deviceDebugger;
Utils::FileName m_simulatorDebugger;
Utils::FileName m_sysRoot;
QMultiMap<QString, QString> m_qnxEnv;
QList<Utils::EnvironmentItem> m_qnxEnv;
void createConfigurationPerQtVersion(
const Utils::FileName &qmakePath, Qnx::QnxArchitecture arch);
......
......@@ -281,16 +281,16 @@ BlackBerryConfiguration *BlackBerryConfigurationManager::configurationFromEnvFil
return 0;
}
// Returns a valid qnxEnv map from a valid configuration;
// Returns a valid qnxEnv from a valid configuration;
// Needed by other classes to get blackberry process path (keys registration, debug token...)
QMultiMap<QString, QString> BlackBerryConfigurationManager::defaultQnxEnv()
QList<Utils::EnvironmentItem> BlackBerryConfigurationManager::defaultQnxEnv()
{
foreach (BlackBerryConfiguration *config, m_configs) {
if (config->isActive() && !config->qnxEnv().isEmpty())
if (config->isActive() && config->qnxEnv().size())
return config->qnxEnv();
}
return QMultiMap<QString, QString>();
return QList<Utils::EnvironmentItem>();
}
void BlackBerryConfigurationManager::loadSettings()
......
......@@ -63,7 +63,7 @@ public:
QString defaultDebugTokenPath() const;
void clearConfigurationSettings(BlackBerryConfiguration *config);
QMultiMap<QString, QString> defaultQnxEnv();
QList<Utils::EnvironmentItem> defaultQnxEnv();
void loadAutoDetectedConfigurations();
......
......@@ -62,10 +62,8 @@ BlackBerryDeviceConnection::BlackBerryDeviceConnection() :
void BlackBerryDeviceConnection::connectDevice(const ProjectExplorer::IDevice::ConstPtr &device)
{
Utils::Environment env = Utils::Environment::systemEnvironment();
QMultiMap<QString, QString> qnxEnv = BlackBerryConfigurationManager::instance().defaultQnxEnv();
if (!qnxEnv.isEmpty())
QnxUtils::prependQnxMapToEnvironment(qnxEnv, env);
foreach (const Utils::EnvironmentItem &item, BlackBerryConfigurationManager::instance().defaultQnxEnv())
env.appendOrSet(item.name, item.value);
m_process->setEnvironment(env.toStringList());
......
......@@ -56,13 +56,17 @@ BlackBerryNdkProcess::BlackBerryNdkProcess(const QString &command, QObject *pare
const QString BlackBerryNdkProcess::resolveNdkToolPath(const QString &tool)
{
QString toolPath;
QMultiMap<QString, QString> qnxEnv = BlackBerryConfigurationManager::instance().defaultQnxEnv();
if (!qnxEnv.isEmpty()) {
toolPath = qnxEnv.value(QLatin1String("QNX_HOST"))
+ (QLatin1String("/usr/bin/")) + tool;
QList<Utils::EnvironmentItem> qnxEnv = BlackBerryConfigurationManager::instance().defaultQnxEnv();
foreach (const Utils::EnvironmentItem &item, qnxEnv) {
if (item.name == QLatin1String("QNX_HOST") && !item.value.isEmpty()) {
toolPath = item.value
+ (QLatin1String("/usr/bin/")) + tool;
if (Utils::HostOsInfo::isWindowsHost())
toolPath += QLatin1String(".bat");
if (Utils::HostOsInfo::isWindowsHost())
toolPath += QLatin1String(".bat");
break;
}
}
return toolPath;
......
......@@ -103,14 +103,15 @@ void BlackBerryQtVersion::fromMap(const QVariantMap &map)
m_ndkEnvFile = map.value(NndkEnvFile).toString();
}
QMultiMap<QString, QString> BlackBerryQtVersion::environment() const
QList<Utils::EnvironmentItem> BlackBerryQtVersion::environment() const
{
QTC_CHECK(!sdkPath().isEmpty());
if (sdkPath().isEmpty())
return QMultiMap<QString, QString>();
return QList<Utils::EnvironmentItem>();
QString envFile = m_ndkEnvFile.isEmpty() ? QnxUtils::envFilePath(sdkPath()) : m_ndkEnvFile;
QMultiMap<QString,QString> result = QnxUtils::parseEnvironmentFile(envFile);
QList<Utils::EnvironmentItem> env = QnxUtils::qnxEnvironmentFromNdkFile(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
// to provide correct information for both x86 and armle-v7 architectures.
......@@ -119,9 +120,11 @@ QMultiMap<QString, QString> BlackBerryQtVersion::environment() const
// CPUVARDIR to match expected architecture() otherwise qmake environment is
// always resolved to be for armle-v7 architecture only as it is specified
// BB NDK environment file.
result.replace(QLatin1String("CPUVARDIR"),
architecture() == X86 ? QLatin1String("x86") : QLatin1String("armle-v7"));
return result;
env.append(Utils::EnvironmentItem(QLatin1String("CPUVARDIR"),
architecture() == X86 ? QLatin1String("x86") : QLatin1String("armle-v7")));
return env;
}
void BlackBerryQtVersion::setDefaultSdkPath()
......
......@@ -64,7 +64,7 @@ public:
QString sdkDescription() const;
private:
QMultiMap<QString, QString> environment() const;
QList<Utils::EnvironmentItem> environment() const;
void setDefaultSdkPath();
QString m_ndkEnvFile;
......
......@@ -97,7 +97,8 @@ void QnxAbstractQtVersion::addToEnvironment(const ProjectExplorer::Kit *k, Utils
{
QtSupport::BaseQtVersion::addToEnvironment(k, env);
updateEnvironment();
QnxUtils::prependQnxMapToEnvironment(m_envMap, env);
env.modify(m_qnxEnv);
env.prependOrSetLibrarySearchPath(versionInfo().value(QLatin1String("QT_INSTALL_LIBS")));
}
......@@ -107,7 +108,7 @@ Utils::Environment QnxAbstractQtVersion::qmakeRunEnvironment() const
updateEnvironment();
Utils::Environment env = Utils::Environment::systemEnvironment();
QnxUtils::prependQnxMapToEnvironment(m_envMap, env);
env.modify(m_qnxEnv);
return env;
}
......@@ -129,7 +130,7 @@ void QnxAbstractQtVersion::setSdkPath(const QString &sdkPath)
void QnxAbstractQtVersion::updateEnvironment() const
{
if (!m_environmentUpToDate) {
m_envMap = environment();
m_qnxEnv = environment();
m_environmentUpToDate = true;
}
}
......@@ -139,7 +140,12 @@ QString QnxAbstractQtVersion::qnxHost() const
if (!m_environmentUpToDate)
updateEnvironment();
return m_envMap.value(QLatin1String(Constants::QNX_HOST_KEY));
foreach (const Utils::EnvironmentItem &item, m_qnxEnv) {
if (item.name == QLatin1String(Constants::QNX_HOST_KEY))
return item.value;
}
return QString();
}
QString QnxAbstractQtVersion::qnxTarget() const
......@@ -147,7 +153,12 @@ QString QnxAbstractQtVersion::qnxTarget() const
if (!m_environmentUpToDate)
updateEnvironment();
return m_envMap.value(QLatin1String(Constants::QNX_TARGET_KEY));
foreach (const Utils::EnvironmentItem &item, m_qnxEnv) {
if (item.name == QLatin1String(Constants::QNX_TARGET_KEY))
return item.value;
}
return QString();
}
QtSupport::QtConfigWidget *QnxAbstractQtVersion::createConfigurationWidget() const
......
......@@ -36,6 +36,8 @@
#include <qtsupport/baseqtversion.h>
#include <utils/environment.h>
#include <QCoreApplication>
namespace Qnx {
......@@ -78,13 +80,13 @@ protected:
private:
void updateEnvironment() const;
virtual QMultiMap<QString, QString> environment() const = 0;
virtual QList<Utils::EnvironmentItem> environment() const = 0;
QnxArchitecture m_arch;
QString m_sdkPath;
mutable bool m_environmentUpToDate;
mutable QMultiMap<QString, QString> m_envMap;
mutable QList<Utils::EnvironmentItem> m_qnxEnv;
};
} // namespace Internal
......
......@@ -33,6 +33,8 @@
#include "qnxconstants.h"
#include "qnxutils.h"
#include <coreplugin/featureprovider.h>
#include <utils/hostosinfo.h>
......@@ -92,35 +94,7 @@ QString QnxQtVersion::sdkDescription() const
return tr("QNX Software Development Platform:");
}
QMultiMap<QString, QString> QnxQtVersion::environment() const
QList<Utils::EnvironmentItem> QnxQtVersion::environment() const
{
// Mimic what the SDP installer puts into the system environment
QMultiMap<QString, QString> environment;
if (Utils::HostOsInfo::isWindowsHost()) {
// TODO:
//environment.insert(QLatin1String("QNX_CONFIGURATION"), QLatin1String("/etc/qnx"));
environment.insert(QLatin1String(Constants::QNX_TARGET_KEY), sdkPath() + QLatin1String("/target/qnx6"));
environment.insert(QLatin1String(Constants::QNX_HOST_KEY), sdkPath() + QLatin1String("/host/win32/x86"));
environment.insert(QLatin1String("PATH"), sdkPath() + QLatin1String("/host/win32/x86/usr/bin"));
// TODO:
//environment.insert(QLatin1String("PATH"), QLatin1String("/etc/qnx/bin"));
} else if (Utils::HostOsInfo::isAnyUnixHost()) {
environment.insert(QLatin1String("QNX_CONFIGURATION"), QLatin1String("/etc/qnx"));
environment.insert(QLatin1String(Constants::QNX_TARGET_KEY), sdkPath() + QLatin1String("/target/qnx6"));
environment.insert(QLatin1String(Constants::QNX_HOST_KEY), sdkPath() + QLatin1String("/host/linux/x86"));
environment.insert(QLatin1String("PATH"), sdkPath() + QLatin1String("/host/linux/x86/usr/bin"));
environment.insert(QLatin1String("PATH"), QLatin1String("/etc/qnx/bin"));
environment.insert(QLatin1String("LD_LIBRARY_PATH"), sdkPath() + QLatin1String("/host/linux/x86/usr/lib"));
}
environment.insert(QLatin1String("QNX_JAVAHOME"), sdkPath() + QLatin1String("/_jvm"));
environment.insert(QLatin1String("MAKEFLAGS"), QLatin1String("-I") + sdkPath() + QLatin1String("/target/qnx6/usr/include"));
return environment;
return QnxUtils::qnxEnvironment(sdkPath());
}
......@@ -60,7 +60,7 @@ public:
QString sdkDescription() const;
private:
QMultiMap<QString, QString> environment() const;
QList<Utils::EnvironmentItem> environment() const;
};
} // namespace Internal
......
......@@ -77,13 +77,13 @@ QStringList QnxUtils::searchPaths(QnxAbstractQtVersion *qtVersion)
return searchPaths;
}
QMultiMap<QString, QString> QnxUtils::parseEnvironmentFile(const QString &fileName)
QList<Utils::EnvironmentItem> QnxUtils::qnxEnvironmentFromNdkFile(const QString &fileName)
{
QMultiMap<QString, QString> result;
QList <Utils::EnvironmentItem> items;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
return result;
return items;
QTextStream str(&file);
QMap<QString, QString> fileContent;
......@@ -171,15 +171,17 @@ QMultiMap<QString, QString> QnxUtils::parseEnvironmentFile(const QString &fileNa
val.replace(keyAsUnixVar, replaceIt.value());
}
}
result.insert(key, val);
// This variable will be properly set based on the qt version architecture
if (key == QLatin1String("CPUVARDIR"))
continue;
items.append(Utils::EnvironmentItem(key, val));
}
}
}
if (!result.contains(QLatin1String("CPUVARDIR")))
result.insert(QLatin1String("CPUVARDIR"), QLatin1String("armle-v7"));
return result;
return items;
}
bool QnxUtils::isValidNdkPath(const QString &ndkPath)
......@@ -206,23 +208,6 @@ QString QnxUtils::envFilePath(const QString &ndkPath, const QString &targetVersi
return envFile;
}
void QnxUtils::prependQnxMapToEnvironment(const QMultiMap<QString, QString> &qnxMap, Utils::Environment &env)
{
QMultiMap<QString, QString>::const_iterator it;
QMultiMap<QString, QString>::const_iterator end(qnxMap.constEnd());
for (it = qnxMap.constBegin(); it != end; ++it) {
const QString key = it.key();
const QString value = it.value();
if (key == QLatin1String("PATH"))
env.prependOrSetPath(value);
else if (key == QLatin1String("LD_LIBRARY_PATH"))
env.prependOrSetLibrarySearchPath(value);
else
env.set(key, value);
}
}
Utils::FileName QnxUtils::executableWithExtension(const Utils::FileName &fileName)
{
Utils::FileName result = fileName;
......@@ -336,3 +321,36 @@ QString QnxUtils::qdeInstallProcess(const QString &ndkPath, const QString &optio
return QString::fromLatin1("%1 -nosplash -application com.qnx.tools.ide.sdk.manager.core.SDKInstallerApplication "
"%2 %3 -vmargs -Dosgi.console=:none").arg(installerPath, option, version);
}
QList<Utils::EnvironmentItem> QnxUtils::qnxEnvironment(const QString &sdkPath)
{
// Mimic what the SDP installer puts into the system environment
QList<Utils::EnvironmentItem> environmentItems;
if (Utils::HostOsInfo::isWindowsHost()) {
// TODO:
//environment.insert(QLatin1String("QNX_CONFIGURATION"), QLatin1String("/etc/qnx"));
environmentItems.append(Utils::EnvironmentItem(QLatin1String(Constants::QNX_TARGET_KEY), sdkPath + QLatin1String("/target/qnx6")));
environmentItems.append(Utils::EnvironmentItem(QLatin1String(Constants::QNX_HOST_KEY), sdkPath + QLatin1String("/host/win32/x86")));
environmentItems.append(Utils::EnvironmentItem(QLatin1String("PATH"), sdkPath + QLatin1String("/host/win32/x86/usr/bin")));
// TODO:
//environment.insert(QLatin1String("PATH"), QLatin1String("/etc/qnx/bin"));
} else if (Utils::HostOsInfo::isAnyUnixHost()) {
environmentItems.append(Utils::EnvironmentItem(QLatin1String("QNX_CONFIGURATION"), QLatin1String("/etc/qnx")));
environmentItems.append(Utils::EnvironmentItem(QLatin1String(Constants::QNX_TARGET_KEY), sdkPath + QLatin1String("/target/qnx6")));
environmentItems.append(Utils::EnvironmentItem(QLatin1String(Constants::QNX_HOST_KEY), sdkPath + QLatin1String("/host/linux/x86")));
environmentItems.append(Utils::EnvironmentItem(QLatin1String("PATH"), sdkPath + QLatin1String("/host/linux/x86/usr/bin")));
environmentItems.append(Utils::EnvironmentItem(QLatin1String("PATH"), QLatin1String("/etc/qnx/bin")));
environmentItems.append(Utils::EnvironmentItem(QLatin1String("LD_LIBRARY_PATH"), sdkPath + QLatin1String("/host/linux/x86/usr/lib")));
}
environmentItems.append(Utils::EnvironmentItem(QLatin1String("QNX_JAVAHOME"), sdkPath + QLatin1String("/_jvm")));
environmentItems.append(Utils::EnvironmentItem(QLatin1String("MAKEFLAGS"), QLatin1String("-I") + sdkPath + QLatin1String("/target/qnx6/usr/include")));
return environmentItems;
}
......@@ -62,10 +62,9 @@ public:
static QString addQuotes(const QString &string);
static Qnx::QnxArchitecture cpudirToArch(const QString &cpuDir);
static QStringList searchPaths(QnxAbstractQtVersion *qtVersion);
static QMultiMap<QString, QString> parseEnvironmentFile(const QString &fileName);
static QList<Utils::EnvironmentItem> qnxEnvironmentFromNdkFile(const QString &fileName);
static bool isValidNdkPath(const QString & ndkPath);
static QString envFilePath(const QString & ndkPath, const QString& targetVersion = QString());
static void prependQnxMapToEnvironment(const QMultiMap<QString, QString> &qnxMap, Utils::Environment &env);
static Utils::FileName executableWithExtension(const Utils::FileName &fileName);
static QString dataDirPath();
static QString qConfigPath();
......@@ -73,6 +72,7 @@ public:
static QList<NdkInstallInformation> installedNdks();
static QString sdkInstallerPath(const QString& ndkPath);
static QString qdeInstallProcess(const QString& ndkPath, const QString &option, const QString &version = QString());
static QList<Utils::EnvironmentItem> qnxEnvironment(const QString &ndk);
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment