diff --git a/src/plugins/qnx/qnxutils.cpp b/src/plugins/qnx/qnxutils.cpp index f7a7104b6aa3254a68226e721aacd7cee8975f69..64eff9cea1563b7bc3193714cbb24d45b760153b 100644 --- a/src/plugins/qnx/qnxutils.cpp +++ b/src/plugins/qnx/qnxutils.cpp @@ -36,6 +36,7 @@ #include #include +#include using namespace Qnx; using namespace Qnx::Internal; @@ -99,6 +100,12 @@ QMultiMap QnxUtils::parseEnvironmentFile(const QString &fileNa QString value = line.mid(equalIndex + 1); + // BASE_DIR variable is evaluated when souring the bbnk-env script + // BASE_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" + // We already know the NDK path so we can set the variable value + if (var == QLatin1String("BASE_DIR")) + value = QFileInfo(fileName).dir().absolutePath(); + if (Utils::HostOsInfo::isWindowsHost()) { QRegExp systemVarRegExp(QLatin1String("IF NOT DEFINED ([\\w\\d]+)\\s+set ([\\w\\d]+)=([\\w\\d]+)")); if (line.contains(systemVarRegExp)) { @@ -187,6 +194,14 @@ QString QnxUtils::envFilePath(const QString &ndkPath) else if (Utils::HostOsInfo::isAnyUnixHost()) envFile = ndkPath + QLatin1String("/bbndk-env.sh"); + if (!QFileInfo(envFile).exists()) { + QString version = ndkVersion(ndkPath); + version = version.replace(QLatin1Char('.'), QLatin1Char('_')); + if (Utils::HostOsInfo::isWindowsHost()) + envFile = ndkPath + QLatin1String("/bbndk-env_") + version + QLatin1String(".bat"); + else if (Utils::HostOsInfo::isAnyUnixHost()) + envFile = ndkPath + QLatin1String("/bbndk-env_") + version + QLatin1String(".sh"); + } return envFile; } @@ -237,3 +252,45 @@ QString QnxUtils::dataDirPath() return QString(); } +QString QnxUtils::qConfigPath() +{ + if (Utils::HostOsInfo::isMacHost() || Utils::HostOsInfo::isWindowsHost()) { + return dataDirPath() + QLatin1String("/BlackBerry Native SDK/qconfig"); + } else { + return dataDirPath() + QLatin1String("/bbndk/qconfig"); + } +} + +QString QnxUtils::ndkVersion(const QString &ndkPath) +{ + QString ndkConfigPath = qConfigPath(); + if (!QDir(ndkConfigPath).exists()) + return QString(); + + QFileInfoList ndkfileList = QDir(ndkConfigPath).entryInfoList(QStringList() << QLatin1String("*.xml"), + QDir::Files, QDir::Time); + foreach (const QFileInfo &ndkFile, ndkfileList) { + QFile xmlFile(ndkFile.absoluteFilePath()); + if (!xmlFile.open(QIODevice::ReadOnly)) + continue; + + QDomDocument doc; + if (!doc.setContent(&xmlFile)) // Skip error message + continue; + + QDomElement docElt = doc.documentElement(); + if (docElt.tagName() != QLatin1String("qnxSystemDefinition")) + continue; + + QDomElement childElt = docElt.firstChildElement(QLatin1String("installation")); + // The file contains only one installation node + if (!childElt.isNull()) { + // The file contains only one base node + QDomElement elt = childElt.firstChildElement(QLatin1String("base")); + if (!elt.text().compare(ndkPath, Utils::HostOsInfo::fileNameCaseSensitivity())) + return childElt.firstChildElement(QLatin1String("version")).text(); + } + } + + return QString(); +} diff --git a/src/plugins/qnx/qnxutils.h b/src/plugins/qnx/qnxutils.h index 571a11f64415959050520b64ad613b7000f5ca0e..f12518fd31236e61861e039834e1cf35ffe47dd6 100644 --- a/src/plugins/qnx/qnxutils.h +++ b/src/plugins/qnx/qnxutils.h @@ -58,6 +58,8 @@ public: static void prependQnxMapToEnvironment(const QMultiMap &qnxMap, Utils::Environment &env); static Utils::FileName executableWithExtension(const Utils::FileName &fileName); static QString dataDirPath(); + static QString qConfigPath(); + static QString ndkVersion(const QString& ndkPath); }; } // namespace Internal