Qnx: Fix discovery of host and target for remote build devices

Change-Id: I9fa65f0e2a0708888d1fc4ca19c932560ee4af68
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-02-21 16:17:17 +01:00
parent c43911022b
commit c18ebe1fda
2 changed files with 63 additions and 49 deletions

View File

@@ -358,11 +358,11 @@ void QnxConfiguration::setDefaultConfiguration(const FilePath &envScript)
m_qnxEnv = QnxUtils::qnxEnvironmentFromEnvFile(m_envFile);
for (const EnvironmentItem &item : std::as_const(m_qnxEnv)) {
if (item.name == QNXConfiguration)
m_qnxConfiguration = FilePath::fromString(item.value).canonicalPath();
m_qnxConfiguration = envScript.withNewPath(item.value).canonicalPath();
else if (item.name == QNXTarget)
m_qnxTarget = FilePath::fromString(item.value).canonicalPath();
m_qnxTarget = envScript.withNewPath(item.value).canonicalPath();
else if (item.name == QNXHost)
m_qnxHost = FilePath::fromString(item.value).canonicalPath();
m_qnxHost = envScript.withNewPath(item.value).canonicalPath();
}
const FilePath qccPath = m_qnxHost.pathAppended("usr/bin/qcc").withExecutableSuffix();
@@ -383,9 +383,9 @@ void QnxConfiguration::setDefaultConfiguration(const FilePath &envScript)
EnvironmentItems QnxConfiguration::qnxEnvironmentItems() const
{
Utils::EnvironmentItems envList;
envList.push_back(EnvironmentItem(QNXConfiguration, m_qnxConfiguration.toString()));
envList.push_back(EnvironmentItem(QNXTarget, m_qnxTarget.toString()));
envList.push_back(EnvironmentItem(QNXHost, m_qnxHost.toString()));
envList.push_back(EnvironmentItem(QNXConfiguration, m_qnxConfiguration.path()));
envList.push_back(EnvironmentItem(QNXTarget, m_qnxTarget.path()));
envList.push_back(EnvironmentItem(QNXHost, m_qnxHost.path()));
return envList;
}
@@ -401,17 +401,20 @@ const QnxConfiguration::Target *QnxConfiguration::findTargetByDebuggerPath(
void QnxConfiguration::updateTargets()
{
m_targets.clear();
QList<QnxTarget> targets = QnxUtils::findTargets(m_qnxTarget);
for (const auto &target : targets)
const QList<QnxTarget> targets = QnxUtils::findTargets(m_qnxTarget);
for (const QnxTarget &target : targets)
m_targets.append(Target(target.m_abi, target.m_path));
}
void QnxConfiguration::assignDebuggersToTargets()
{
const FilePath hostUsrBinDir = m_qnxHost.pathAppended("usr/bin");
const FilePaths debuggerNames = hostUsrBinDir.dirEntries(
{{HostOsInfo::withExecutableSuffix("nto*-gdb")}, QDir::Files});
Environment sysEnv = Environment::systemEnvironment();
QString pattern = "nto*-gdb";
if (m_qnxHost.osType() == Utils::OsTypeWindows)
pattern += ".exe";
const FilePaths debuggerNames = hostUsrBinDir.dirEntries({{pattern}, QDir::Files});
Environment sysEnv = m_qnxHost.deviceEnvironment();
sysEnv.modify(qnxEnvironmentItems());
for (const FilePath &debuggerPath : debuggerNames) {

View File

@@ -21,11 +21,6 @@ using namespace Utils;
namespace Qnx::Internal {
const char *EVAL_ENV_VARS[] = {
"QNX_TARGET", "QNX_HOST", "QNX_CONFIGURATION", "QNX_CONFIGURATION_EXCLUSIVE",
"MAKEFLAGS", "LD_LIBRARY_PATH", "PATH", "QDE", "CPUVARDIR", "PYTHONPATH"
};
QString QnxUtils::cpuDirFromAbi(const Abi &abi)
{
if (abi.os() != Abi::OS::QnxOS)
@@ -64,30 +59,46 @@ EnvironmentItems QnxUtils::qnxEnvironmentFromEnvFile(const FilePath &filePath)
const bool isWindows = filePath.osType() == Utils::OsTypeWindows;
// locking creating sdp-env file wrapper script
TemporaryFile tmpFile("sdp-env-eval-XXXXXX" + QString::fromLatin1(isWindows ? ".bat" : ".sh"));
if (!tmpFile.open())
return items;
tmpFile.setTextModeEnabled(true);
const expected_str<FilePath> tmpPath = filePath.tmpDir();
if (!tmpPath)
return {}; // make_unexpected(tmpPath.error());
// writing content to wrapper script
QTextStream fileContent(&tmpFile);
const QString tmpName = "sdp-env-eval-XXXXXX" + QLatin1String(isWindows ? ".bat" : "");
const FilePath pattern = *tmpPath / tmpName;
const expected_str<FilePath> tmpFile = pattern.createTempFile();
if (!tmpFile)
return {}; // make_unexpected(tmpFile.error());
QStringList fileContent;
// writing content to wrapper script.
// this has to use bash as qnxsdp-env.sh requires this
if (isWindows)
fileContent << "@echo off\n"
<< "call " << filePath.path() << '\n';
fileContent << "@echo off" << "call " + filePath.path();
else
fileContent << "#!/bin/bash\n"
<< ". " << filePath.path() << '\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();
fileContent << "#!/bin/bash" << ". " + filePath.path();
QLatin1String linePattern(isWindows ? "echo %1=%%1%" : "echo %1=$%1");
static const char *envVars[] = {
"QNX_TARGET", "QNX_HOST", "QNX_CONFIGURATION", "QNX_CONFIGURATION_EXCLUSIVE",
"MAKEFLAGS", "LD_LIBRARY_PATH", "PATH", "QDE", "CPUVARDIR", "PYTHONPATH"
};
for (const char *envVar : envVars)
fileContent << linePattern.arg(QLatin1String(envVar));
QString content = fileContent.join(QLatin1String(isWindows ? "\r\n" : "\n"));
tmpFile->writeFileContents(content.toUtf8());
// running wrapper script
QtcProcess process;
if (isWindows)
process.setCommand({"cmd.exe", {"/C", tmpFile.fileName()}});
process.setCommand({filePath.withNewPath("cmd.exe"), {"/C", tmpFile->path()}});
else
process.setCommand({"/bin/bash", {tmpFile.fileName()}});
process.setCommand({filePath.withNewPath("/bin/bash"), {tmpFile->path()}});
process.start();
// waiting for finish
@@ -190,25 +201,25 @@ QList<QnxTarget> QnxUtils::findTargets(const FilePath &basePath)
{
QList<QnxTarget> result;
QDirIterator iterator(basePath.toString());
while (iterator.hasNext()) {
iterator.next();
const FilePath libc = FilePath::fromString(iterator.filePath()).pathAppended("lib/libc.so");
basePath.iterateDirectory(
[&result](const FilePath &filePath) {
const FilePath libc = filePath / "lib/libc.so";
if (libc.exists()) {
auto abis = Abi::abisOfBinary(libc);
const Abis abis = Abi::abisOfBinary(libc);
if (abis.isEmpty()) {
qWarning() << libc << "has no ABIs ... discarded";
continue;
return IterationPolicy::Continue;
}
if (abis.count() > 1)
qWarning() << libc << "has more than one ABI ... processing all";
FilePath path = FilePath::fromString(iterator.filePath());
for (const Abi &abi : abis)
result.append(QnxTarget(path, QnxUtils::convertAbi(abi)));
}
result.append(QnxTarget(filePath, QnxUtils::convertAbi(abi)));
}
return IterationPolicy::Continue;
},
{{}, QDir::Dirs});
return result;
}