2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2012-06-29 07:23:13 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BlackBerry Limited. All rights reserved
|
2012-06-29 07:23:13 +02:00
|
|
|
** Contact: KDAB (info@kdab.com)
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-06-29 07:23:13 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-06-29 07:23:13 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
#include "qnxutils.h"
|
2015-04-24 10:31:27 +02:00
|
|
|
#include "qnxqtversion.h"
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2013-01-09 09:23:37 -05:00
|
|
|
#include <utils/hostosinfo.h>
|
2013-11-05 10:05:03 +01:00
|
|
|
#include <utils/synchronousprocess.h>
|
2017-01-19 16:44:22 +01:00
|
|
|
#include <utils/temporaryfile.h>
|
2013-01-09 09:23:37 -05:00
|
|
|
|
2012-06-29 07:23:13 +02:00
|
|
|
#include <QDir>
|
2013-06-12 14:40:30 +02:00
|
|
|
#include <QDomDocument>
|
2013-11-05 10:05:03 +01:00
|
|
|
#include <QProcess>
|
2014-08-28 17:33:47 +02:00
|
|
|
#include <QStandardPaths>
|
2013-11-05 10:05:03 +01:00
|
|
|
#include <QApplication>
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2016-12-06 08:35:51 -05:00
|
|
|
using namespace ProjectExplorer;
|
2012-06-29 07:23:13 +02:00
|
|
|
using namespace Qnx;
|
|
|
|
|
using namespace Qnx::Internal;
|
|
|
|
|
|
2013-11-05 10:05:03 +01:00
|
|
|
namespace {
|
|
|
|
|
const char *EVAL_ENV_VARS[] = {
|
|
|
|
|
"QNX_TARGET", "QNX_HOST", "QNX_CONFIGURATION", "MAKEFLAGS", "LD_LIBRARY_PATH",
|
|
|
|
|
"PATH", "QDE", "CPUVARDIR", "PYTHONPATH"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-29 07:23:13 +02:00
|
|
|
QString QnxUtils::addQuotes(const QString &string)
|
|
|
|
|
{
|
|
|
|
|
return QLatin1Char('"') + string + QLatin1Char('"');
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 08:35:51 -05:00
|
|
|
QString QnxUtils::cpuDirShortDescription(const QString &cpuDir)
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
2016-12-06 08:35:51 -05:00
|
|
|
if (cpuDir == "armle-v7")
|
|
|
|
|
return QLatin1String("32-bit ARM");
|
|
|
|
|
|
|
|
|
|
if (cpuDir == "aarch64le")
|
|
|
|
|
return QLatin1String("64-bit ARM");
|
|
|
|
|
|
|
|
|
|
if (cpuDir == "x86")
|
|
|
|
|
return QLatin1String("32-bit x86");
|
|
|
|
|
|
|
|
|
|
if (cpuDir == "x86_64")
|
|
|
|
|
return QLatin1String("64-bit x86");
|
|
|
|
|
|
|
|
|
|
return cpuDir;
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-24 10:31:27 +02:00
|
|
|
QStringList QnxUtils::searchPaths(QnxQtVersion *qtVersion)
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
|
|
|
|
const QDir pluginDir(qtVersion->versionInfo().value(QLatin1String("QT_INSTALL_PLUGINS")));
|
|
|
|
|
const QStringList pluginSubDirs = pluginDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
|
|
QStringList searchPaths;
|
|
|
|
|
|
|
|
|
|
Q_FOREACH (const QString &dir, pluginSubDirs) {
|
|
|
|
|
searchPaths << qtVersion->versionInfo().value(QLatin1String("QT_INSTALL_PLUGINS"))
|
|
|
|
|
+ QLatin1Char('/') + dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchPaths << qtVersion->versionInfo().value(QLatin1String("QT_INSTALL_LIBS"));
|
2016-12-06 08:35:51 -05:00
|
|
|
searchPaths << qtVersion->qnxTarget() + QLatin1Char('/') + qtVersion->cpuDir()
|
2012-06-29 07:23:13 +02:00
|
|
|
+ QLatin1String("/lib");
|
2016-12-06 08:35:51 -05:00
|
|
|
searchPaths << qtVersion->qnxTarget() + QLatin1Char('/') + qtVersion->cpuDir()
|
2012-06-29 07:23:13 +02:00
|
|
|
+ QLatin1String("/usr/lib");
|
|
|
|
|
|
|
|
|
|
return searchPaths;
|
|
|
|
|
}
|
2013-01-09 09:23:37 -05:00
|
|
|
|
2014-03-12 17:43:26 +01:00
|
|
|
QList<Utils::EnvironmentItem> QnxUtils::qnxEnvironmentFromEnvFile(const QString &fileName)
|
2013-01-09 09:23:37 -05:00
|
|
|
{
|
2013-10-12 19:20:37 +02:00
|
|
|
QList <Utils::EnvironmentItem> items;
|
2013-01-09 09:23:37 -05:00
|
|
|
|
2014-10-24 10:28:28 +02:00
|
|
|
if (!QFileInfo::exists(fileName))
|
2013-11-05 10:05:03 +01:00
|
|
|
return items;
|
|
|
|
|
|
|
|
|
|
const bool isWindows = Utils::HostOsInfo::isWindowsHost();
|
|
|
|
|
|
|
|
|
|
// locking creating bbndk-env file wrapper script
|
2017-01-19 16:44:22 +01:00
|
|
|
Utils::TemporaryFile tmpFile(QString::fromLatin1("bbndk-env-eval-XXXXXX")
|
|
|
|
|
+ QString::fromLatin1(isWindows ? ".bat" : ".sh"));
|
2013-11-05 10:05:03 +01:00
|
|
|
if (!tmpFile.open())
|
|
|
|
|
return items;
|
|
|
|
|
tmpFile.setTextModeEnabled(true);
|
|
|
|
|
|
|
|
|
|
// writing content to wrapper script
|
|
|
|
|
QTextStream fileContent(&tmpFile);
|
|
|
|
|
if (isWindows)
|
|
|
|
|
fileContent << QLatin1String("@echo off\n")
|
|
|
|
|
<< QLatin1String("call ") << fileName << QLatin1Char('\n');
|
|
|
|
|
else
|
|
|
|
|
fileContent << QLatin1String("#!/bin/bash\n")
|
|
|
|
|
<< QLatin1String(". ") << fileName << QLatin1Char('\n');
|
|
|
|
|
QString linePattern = QString::fromLatin1(isWindows ? "echo %1=%%1%" : "echo %1=$%1");
|
|
|
|
|
for (int i = 0, len = sizeof(EVAL_ENV_VARS) / sizeof(const char *); i < len; ++i)
|
|
|
|
|
fileContent << linePattern.arg(QLatin1String(EVAL_ENV_VARS[i])) << QLatin1Char('\n');
|
|
|
|
|
tmpFile.close();
|
|
|
|
|
|
|
|
|
|
// running wrapper script
|
|
|
|
|
QProcess process;
|
|
|
|
|
if (isWindows)
|
|
|
|
|
process.start(QLatin1String("cmd.exe"),
|
|
|
|
|
QStringList() << QLatin1String("/C") << tmpFile.fileName());
|
|
|
|
|
else
|
|
|
|
|
process.start(QLatin1String("/bin/bash"),
|
|
|
|
|
QStringList() << tmpFile.fileName());
|
|
|
|
|
|
|
|
|
|
// waiting for finish
|
|
|
|
|
QApplication::setOverrideCursor(Qt::BusyCursor);
|
2016-04-29 16:52:58 +02:00
|
|
|
bool waitResult = process.waitForFinished(10000) || process.state() == QProcess::NotRunning;
|
2013-11-05 10:05:03 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
if (!waitResult) {
|
|
|
|
|
Utils::SynchronousProcess::stopProcess(process);
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (process.exitStatus() != QProcess::NormalExit || process.exitCode() != 0)
|
2013-10-12 19:20:37 +02:00
|
|
|
return items;
|
2013-01-09 09:23:37 -05:00
|
|
|
|
2013-11-05 10:05:03 +01:00
|
|
|
// parsing process output
|
|
|
|
|
QTextStream str(&process);
|
2013-01-09 09:23:37 -05:00
|
|
|
while (!str.atEnd()) {
|
|
|
|
|
QString line = str.readLine();
|
|
|
|
|
int equalIndex = line.indexOf(QLatin1Char('='));
|
2013-11-05 10:05:03 +01:00
|
|
|
if (equalIndex < 0)
|
|
|
|
|
continue;
|
2013-01-09 09:23:37 -05:00
|
|
|
QString var = line.left(equalIndex);
|
|
|
|
|
QString value = line.mid(equalIndex + 1);
|
2013-11-05 10:05:03 +01:00
|
|
|
items.append(Utils::EnvironmentItem(var, value));
|
2013-01-09 09:23:37 -05:00
|
|
|
}
|
|
|
|
|
|
2013-10-12 19:20:37 +02:00
|
|
|
return items;
|
2013-01-09 09:23:37 -05:00
|
|
|
}
|
|
|
|
|
|
2013-08-22 17:00:58 +02:00
|
|
|
QString QnxUtils::envFilePath(const QString &ndkPath, const QString &targetVersion)
|
2013-01-09 09:23:37 -05:00
|
|
|
{
|
2015-10-09 18:02:43 +03:00
|
|
|
QDir ndk(ndkPath);
|
|
|
|
|
QStringList entries;
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
|
|
|
|
entries = ndk.entryList(QStringList(QLatin1String("*-env.bat")));
|
|
|
|
|
else
|
|
|
|
|
entries = ndk.entryList(QStringList(QLatin1String("*-env.sh")));
|
|
|
|
|
|
|
|
|
|
if (!entries.isEmpty())
|
|
|
|
|
return ndk.absoluteFilePath(entries.first());
|
|
|
|
|
|
2013-01-09 09:23:37 -05:00
|
|
|
QString envFile;
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
|
|
|
|
envFile = ndkPath + QLatin1String("/bbndk-env.bat");
|
|
|
|
|
else if (Utils::HostOsInfo::isAnyUnixHost())
|
|
|
|
|
envFile = ndkPath + QLatin1String("/bbndk-env.sh");
|
|
|
|
|
|
2014-10-24 10:28:28 +02:00
|
|
|
if (!QFileInfo::exists(envFile)) {
|
2013-08-22 17:00:58 +02:00
|
|
|
QString version = targetVersion.isEmpty() ? defaultTargetVersion(ndkPath) : targetVersion;
|
2013-06-12 14:40:30 +02:00
|
|
|
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");
|
|
|
|
|
}
|
2013-01-09 09:23:37 -05:00
|
|
|
return envFile;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 19:33:27 +02:00
|
|
|
QString QnxUtils::bbDataDirPath()
|
2013-06-12 14:09:01 +02:00
|
|
|
{
|
|
|
|
|
const QString homeDir = QDir::homePath();
|
|
|
|
|
|
|
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
|
|
|
|
return homeDir + QLatin1String("/Library/Research in Motion");
|
|
|
|
|
|
|
|
|
|
if (Utils::HostOsInfo::isAnyUnixHost())
|
|
|
|
|
return homeDir + QLatin1String("/.rim");
|
|
|
|
|
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
|
// Get the proper storage location on Windows using QDesktopServices,
|
|
|
|
|
// to not hardcode "AppData/Local", as it might refer to "AppData/Roaming".
|
2014-08-28 17:33:47 +02:00
|
|
|
QString dataDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
|
|
|
|
|
+ QLatin1String("/data");
|
2013-06-12 14:09:01 +02:00
|
|
|
dataDir = dataDir.left(dataDir.indexOf(QCoreApplication::organizationName()));
|
2014-09-01 16:56:31 +02:00
|
|
|
dataDir.append(QLatin1String("/Research in Motion"));
|
2013-06-12 14:09:01 +02:00
|
|
|
return dataDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 19:33:27 +02:00
|
|
|
QString QnxUtils::bbqConfigPath()
|
2013-06-12 14:40:30 +02:00
|
|
|
{
|
2013-11-11 22:20:47 +02:00
|
|
|
if (Utils::HostOsInfo::isMacHost() || Utils::HostOsInfo::isWindowsHost())
|
2014-04-08 19:33:27 +02:00
|
|
|
return bbDataDirPath() + QLatin1String("/BlackBerry Native SDK/qconfig");
|
2013-11-11 22:20:47 +02:00
|
|
|
else
|
2014-04-08 19:33:27 +02:00
|
|
|
return bbDataDirPath() + QLatin1String("/bbndk/qconfig");
|
2013-06-12 14:40:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-22 17:00:58 +02:00
|
|
|
QString QnxUtils::defaultTargetVersion(const QString &ndkPath)
|
2013-06-12 14:40:30 +02:00
|
|
|
{
|
2014-04-08 19:33:27 +02:00
|
|
|
foreach (const ConfigInstallInformation &ndkInfo, installedConfigs()) {
|
2013-07-04 16:21:33 +02:00
|
|
|
if (!ndkInfo.path.compare(ndkPath, Utils::HostOsInfo::fileNameCaseSensitivity()))
|
|
|
|
|
return ndkInfo.version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 19:33:27 +02:00
|
|
|
QList<ConfigInstallInformation> QnxUtils::installedConfigs(const QString &configPath)
|
2013-07-04 16:21:33 +02:00
|
|
|
{
|
2014-04-08 19:33:27 +02:00
|
|
|
QList<ConfigInstallInformation> ndkList;
|
|
|
|
|
QString ndkConfigPath = configPath;
|
|
|
|
|
if (ndkConfigPath.isEmpty())
|
|
|
|
|
ndkConfigPath = bbqConfigPath();
|
|
|
|
|
|
2013-06-12 14:40:30 +02:00
|
|
|
if (!QDir(ndkConfigPath).exists())
|
2013-07-04 16:21:33 +02:00
|
|
|
return ndkList;
|
2013-06-12 14:40:30 +02:00
|
|
|
|
|
|
|
|
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
|
2014-04-08 19:33:27 +02:00
|
|
|
ConfigInstallInformation ndkInfo;
|
2013-07-04 16:21:33 +02:00
|
|
|
ndkInfo.path = childElt.firstChildElement(QLatin1String("base")).text();
|
|
|
|
|
ndkInfo.name = childElt.firstChildElement(QLatin1String("name")).text();
|
|
|
|
|
ndkInfo.host = childElt.firstChildElement(QLatin1String("host")).text();
|
|
|
|
|
ndkInfo.target = childElt.firstChildElement(QLatin1String("target")).text();
|
|
|
|
|
ndkInfo.version = childElt.firstChildElement(QLatin1String("version")).text();
|
2013-12-05 18:24:08 +01:00
|
|
|
ndkInfo.installationXmlFilePath = ndkFile.absoluteFilePath();
|
2013-07-04 16:21:33 +02:00
|
|
|
|
|
|
|
|
ndkList.append(ndkInfo);
|
2013-06-12 14:40:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 16:21:33 +02:00
|
|
|
return ndkList;
|
2013-06-12 14:40:30 +02:00
|
|
|
}
|
2013-09-12 18:35:41 +02:00
|
|
|
|
|
|
|
|
QString QnxUtils::sdkInstallerPath(const QString &ndkPath)
|
|
|
|
|
{
|
2014-06-12 13:33:51 +02:00
|
|
|
QString sdkinstallPath = Utils::HostOsInfo::withExecutableSuffix(ndkPath + QLatin1String("/qde"));
|
2013-09-12 18:35:41 +02:00
|
|
|
|
2014-10-24 10:28:28 +02:00
|
|
|
if (QFileInfo::exists(sdkinstallPath))
|
2013-09-12 18:35:41 +02:00
|
|
|
return sdkinstallPath;
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The resulting process when launching sdkinstall
|
2014-01-22 18:55:11 +01:00
|
|
|
QString QnxUtils::qdeInstallProcess(const QString &ndkPath, const QString &target,
|
|
|
|
|
const QString &option, const QString &version)
|
2013-09-12 18:35:41 +02:00
|
|
|
{
|
|
|
|
|
QString installerPath = sdkInstallerPath(ndkPath);
|
2013-11-15 15:12:33 +01:00
|
|
|
if (installerPath.isEmpty())
|
2013-09-12 18:35:41 +02:00
|
|
|
return QString();
|
|
|
|
|
|
2013-12-03 17:02:07 +01:00
|
|
|
const QDir pluginDir(ndkPath + QLatin1String("/plugins"));
|
|
|
|
|
const QStringList installerPlugins = pluginDir.entryList(QStringList() << QLatin1String("com.qnx.tools.ide.sdk.installer.app_*.jar"));
|
|
|
|
|
const QString installerApplication = installerPlugins.size() >= 1 ? QLatin1String("com.qnx.tools.ide.sdk.installer.app.SDKInstallerApplication")
|
|
|
|
|
: QLatin1String("com.qnx.tools.ide.sdk.manager.core.SDKInstallerApplication");
|
|
|
|
|
return QString::fromLatin1("%1 -nosplash -application %2 "
|
2014-01-22 18:55:11 +01:00
|
|
|
"%3 %4 %5 -vmargs -Dosgi.console=:none").arg(installerPath, installerApplication, target, option, version);
|
2013-09-12 18:35:41 +02:00
|
|
|
}
|
2013-10-12 19:20:37 +02:00
|
|
|
|
|
|
|
|
QList<Utils::EnvironmentItem> QnxUtils::qnxEnvironment(const QString &sdkPath)
|
|
|
|
|
{
|
2016-12-16 12:43:16 -05:00
|
|
|
return qnxEnvironmentFromEnvFile(envFilePath(sdkPath));
|
2013-10-12 19:20:37 +02:00
|
|
|
}
|