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();
|
|
|
|
|
|
2016-12-13 14:43:24 -05:00
|
|
|
// locking creating sdp-env file wrapper script
|
|
|
|
|
Utils::TemporaryFile tmpFile(QString::fromLatin1("sdp-env-eval-XXXXXX")
|
2017-01-19 16:44:22 +01:00
|
|
|
+ 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
|
|
|
}
|
|
|
|
|
|
2016-12-13 14:43:24 -05:00
|
|
|
QString QnxUtils::envFilePath(const QString &sdpPath)
|
2013-01-09 09:23:37 -05:00
|
|
|
{
|
2016-12-13 14:43:24 -05:00
|
|
|
QDir sdp(sdpPath);
|
2015-10-09 18:02:43 +03:00
|
|
|
QStringList entries;
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
2016-12-13 14:43:24 -05:00
|
|
|
entries = sdp.entryList(QStringList(QLatin1String("*-env.bat")));
|
2015-10-09 18:02:43 +03:00
|
|
|
else
|
2016-12-13 14:43:24 -05:00
|
|
|
entries = sdp.entryList(QStringList(QLatin1String("*-env.sh")));
|
2015-10-09 18:02:43 +03:00
|
|
|
|
|
|
|
|
if (!entries.isEmpty())
|
2016-12-13 14:43:24 -05:00
|
|
|
return sdp.absoluteFilePath(entries.first());
|
2013-06-12 14:09:01 +02:00
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-13 14:43:24 -05:00
|
|
|
QString QnxUtils::defaultTargetVersion(const QString &sdpPath)
|
2013-06-12 14:40:30 +02:00
|
|
|
{
|
2016-12-13 14:43:24 -05:00
|
|
|
foreach (const ConfigInstallInformation &sdpInfo, installedConfigs()) {
|
|
|
|
|
if (!sdpInfo.path.compare(sdpPath, Utils::HostOsInfo::fileNameCaseSensitivity()))
|
|
|
|
|
return sdpInfo.version;
|
2013-07-04 16:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-12-13 14:43:24 -05:00
|
|
|
QList<ConfigInstallInformation> sdpList;
|
|
|
|
|
QString sdpConfigPath = configPath;
|
|
|
|
|
|
|
|
|
|
if (!QDir(sdpConfigPath).exists())
|
|
|
|
|
return sdpList;
|
|
|
|
|
|
|
|
|
|
QFileInfoList sdpfileList =
|
|
|
|
|
QDir(sdpConfigPath).entryInfoList(QStringList() << QLatin1String("*.xml"),
|
|
|
|
|
QDir::Files, QDir::Time);
|
|
|
|
|
foreach (const QFileInfo &sdpFile, sdpfileList) {
|
|
|
|
|
QFile xmlFile(sdpFile.absoluteFilePath());
|
2013-06-12 14:40:30 +02:00
|
|
|
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
|
2016-12-13 14:43:24 -05:00
|
|
|
ConfigInstallInformation sdpInfo;
|
|
|
|
|
sdpInfo.path = childElt.firstChildElement(QLatin1String("base")).text();
|
|
|
|
|
sdpInfo.name = childElt.firstChildElement(QLatin1String("name")).text();
|
|
|
|
|
sdpInfo.host = childElt.firstChildElement(QLatin1String("host")).text();
|
|
|
|
|
sdpInfo.target = childElt.firstChildElement(QLatin1String("target")).text();
|
|
|
|
|
sdpInfo.version = childElt.firstChildElement(QLatin1String("version")).text();
|
|
|
|
|
sdpInfo.installationXmlFilePath = sdpFile.absoluteFilePath();
|
|
|
|
|
|
|
|
|
|
sdpList.append(sdpInfo);
|
2013-06-12 14:40:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-13 14:43:24 -05:00
|
|
|
return sdpList;
|
2013-09-12 18:35:41 +02:00
|
|
|
}
|
2013-10-12 19:20:37 +02:00
|
|
|
|
2016-12-13 14:43:24 -05:00
|
|
|
QList<Utils::EnvironmentItem> QnxUtils::qnxEnvironment(const QString &sdpPath)
|
2013-10-12 19:20:37 +02:00
|
|
|
{
|
2016-12-13 14:43:24 -05:00
|
|
|
return qnxEnvironmentFromEnvFile(envFilePath(sdpPath));
|
2013-10-12 19:20:37 +02:00
|
|
|
}
|