CMake: Report version information on cmake tool

Improve data retrieval from cmake while at it.

Change-Id: I0329804b800bb9c3b7e734246f795cfd6ae361fe
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Tobias Hunger
2016-09-28 17:25:29 +02:00
parent 8d608d2a74
commit 38b21ad04d
2 changed files with 84 additions and 11 deletions

View File

@@ -34,6 +34,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QProcess>
#include <QRegularExpression>
#include <QSet>
#include <QTextDocument>
#include <QUuid>
@@ -163,12 +164,7 @@ bool CMakeTool::isAutoRun() const
QList<CMakeTool::Generator> CMakeTool::supportedGenerators() const
{
if (m_generators.isEmpty())
fetchGeneratorsFromCapabilities();
if (m_generators.isEmpty()) {
fetchGeneratorsFromHelp();
}
readInformation(QueryType::GENERATORS);
return m_generators;
}
@@ -201,12 +197,16 @@ TextEditor::Keywords CMakeTool::keywords()
bool CMakeTool::hasServerMode() const
{
supportedGenerators(); // server mode is queried from the output of -E capabilities,
// just like the generators
readInformation(QueryType::SERVER_MODE);
return m_hasServerMode;
}
CMakeTool::Version CMakeTool::version() const
{
readInformation(QueryType::VERSION);
return m_version;
}
bool CMakeTool::isAutoDetected() const
{
return m_isAutoDetected;
@@ -235,6 +235,32 @@ QString CMakeTool::mapAllPaths(const ProjectExplorer::Kit *kit, const QString &i
return in;
}
void CMakeTool::readInformation(CMakeTool::QueryType type) const
{
if ((type == QueryType::GENERATORS && !m_generators.isEmpty())
|| (type == QueryType::SERVER_MODE && m_queriedServerMode)
|| (type == QueryType::VERSION && !m_version.fullVersion.isEmpty()))
return;
if (!m_triedCapabilities) {
fetchFromCapabilities();
m_triedCapabilities = true;
m_queriedServerMode = true; // Got added after "-E capabilities" support!
if (type == QueryType::GENERATORS && !m_generators.isEmpty())
return;
}
if (type == QueryType::GENERATORS) {
fetchGeneratorsFromHelp();
} else if (type == QueryType::SERVER_MODE) {
// Nothing to do...
} else if (type == QueryType::VERSION) {
fetchVersionFromVersionOutput();
} else {
QTC_ASSERT(false, return);
}
}
static QStringList parseDefinition(const QString &definition)
{
QStringList result;
@@ -378,7 +404,27 @@ void CMakeTool::fetchGeneratorsFromHelp() const
m_generators.append(Generator(it.key(), it.value()));
}
void CMakeTool::fetchGeneratorsFromCapabilities() const
void CMakeTool::fetchVersionFromVersionOutput() const
{
Utils::SynchronousProcessResponse response = run({ "--version" });
if (response.result != Utils::SynchronousProcessResponse::Finished)
return;
QRegularExpression versionLine("^cmake version ((\\d+).(\\d+).(\\d+).*)$");
for (const QString &line : response.stdOut().split('\n')) {
QRegularExpressionMatch match = versionLine.match(line);
if (!match.hasMatch())
continue;
m_version.major = match.captured(2).toInt();
m_version.minor = match.captured(3).toInt();
m_version.patch = match.captured(4).toInt();
m_version.fullVersion = match.captured(1).toUtf8();
break;
}
}
void CMakeTool::fetchFromCapabilities() const
{
Utils::SynchronousProcessResponse response = run({ "-E", "capabilities" }, true);
if (response.result != Utils::SynchronousProcessResponse::Finished)
@@ -398,6 +444,12 @@ void CMakeTool::fetchGeneratorsFromCapabilities() const
gen.value("platformSupport").toBool(),
gen.value("toolsetSupport").toBool()));
}
const QVariantMap versionInfo = data.value("version").toMap();
m_version.major = versionInfo.value("major").toInt();
m_version.minor = versionInfo.value("minor").toInt();
m_version.patch = versionInfo.value("patch").toInt();
m_version.fullVersion = versionInfo.value("string").toByteArray();
}
} // namespace CMakeProjectManager