forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
@@ -52,6 +52,14 @@ public:
|
||||
AutoDetection
|
||||
};
|
||||
|
||||
struct Version
|
||||
{
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int patch = 0;
|
||||
QByteArray fullVersion;
|
||||
};
|
||||
|
||||
class Generator
|
||||
{
|
||||
public:
|
||||
@@ -88,6 +96,7 @@ public:
|
||||
QList<Generator> supportedGenerators() const;
|
||||
TextEditor::Keywords keywords();
|
||||
bool hasServerMode() const;
|
||||
Version version() const;
|
||||
|
||||
bool isAutoDetected() const;
|
||||
QString displayName() const;
|
||||
@@ -97,12 +106,20 @@ public:
|
||||
QString mapAllPaths(const ProjectExplorer::Kit *kit, const QString &in) const;
|
||||
|
||||
private:
|
||||
enum class QueryType {
|
||||
GENERATORS,
|
||||
SERVER_MODE,
|
||||
VERSION
|
||||
};
|
||||
void readInformation(QueryType type) const;
|
||||
|
||||
Utils::SynchronousProcessResponse run(const QStringList &args, bool mayFail = false) const;
|
||||
void parseFunctionDetailsOutput(const QString &output);
|
||||
QStringList parseVariableOutput(const QString &output);
|
||||
|
||||
void fetchGeneratorsFromHelp() const;
|
||||
void fetchGeneratorsFromCapabilities() const;
|
||||
void fetchVersionFromVersionOutput() const;
|
||||
void fetchFromCapabilities() const;
|
||||
|
||||
Core::Id m_id;
|
||||
QString m_displayName;
|
||||
@@ -115,10 +132,14 @@ private:
|
||||
mutable bool m_didRun = false;
|
||||
mutable bool m_hasServerMode = false;
|
||||
|
||||
mutable bool m_queriedServerMode = false;
|
||||
mutable bool m_triedCapabilities = false;
|
||||
|
||||
mutable QList<Generator> m_generators;
|
||||
mutable QMap<QString, QStringList> m_functionArgs;
|
||||
mutable QStringList m_variables;
|
||||
mutable QStringList m_functions;
|
||||
mutable Version m_version;
|
||||
|
||||
PathMapper m_pathMapper;
|
||||
};
|
||||
|
Reference in New Issue
Block a user