forked from qt-creator/qt-creator
ClangTools: Make version number available via settings
Change-Id: I9501f5a3234fb995a7ca3192adc1569febb8662e Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -198,5 +198,38 @@ void ClangToolsSettings::writeSettings()
|
|||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClangToolsSettings::setClangTidyExecutable(const QString &path)
|
||||||
|
{
|
||||||
|
m_clangTidyExecutable = path;
|
||||||
|
m_clangTidyVersion = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangTools::Internal::ClangToolsSettings::setClazyStandaloneExecutable(const QString &path)
|
||||||
|
{
|
||||||
|
m_clazyStandaloneExecutable = path;
|
||||||
|
m_clazyVersion = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
static QVersionNumber getVersionNumber(QVersionNumber &version, const QString &toolFilePath)
|
||||||
|
{
|
||||||
|
if (version.isNull() && !toolFilePath.isEmpty()) {
|
||||||
|
version = QVersionNumber::fromString(queryVersion(Utils::FilePath::fromString(toolFilePath),
|
||||||
|
QueryFailMode::Silent));
|
||||||
|
};
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVersionNumber ClangToolsSettings::clangTidyVersion()
|
||||||
|
{
|
||||||
|
return getVersionNumber(instance()->m_clangTidyVersion,
|
||||||
|
ClangTools::Internal::clangTidyExecutable());
|
||||||
|
}
|
||||||
|
|
||||||
|
QVersionNumber ClangToolsSettings::clazyVersion()
|
||||||
|
{
|
||||||
|
return getVersionNumber(instance()->m_clazyVersion,
|
||||||
|
ClangTools::Internal::clazyStandaloneExecutable());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ClangTools
|
} // namespace ClangTools
|
||||||
|
|||||||
@@ -25,12 +25,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "executableinfo.h"
|
||||||
|
|
||||||
#include <cpptools/clangdiagnosticconfig.h>
|
#include <cpptools/clangdiagnosticconfig.h>
|
||||||
|
|
||||||
#include <utils/id.h>
|
#include <utils/id.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
namespace ClangTools {
|
namespace ClangTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -75,10 +78,10 @@ public:
|
|||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
QString clangTidyExecutable() const { return m_clangTidyExecutable; }
|
QString clangTidyExecutable() const { return m_clangTidyExecutable; }
|
||||||
void setClangTidyExecutable(const QString &path) { m_clangTidyExecutable = path; }
|
void setClangTidyExecutable(const QString &path);
|
||||||
|
|
||||||
QString clazyStandaloneExecutable() const { return m_clazyStandaloneExecutable; }
|
QString clazyStandaloneExecutable() const { return m_clazyStandaloneExecutable; }
|
||||||
void setClazyStandaloneExecutable(const QString &path) { m_clazyStandaloneExecutable = path; }
|
void setClazyStandaloneExecutable(const QString &path);
|
||||||
|
|
||||||
CppTools::ClangDiagnosticConfigs diagnosticConfigs() const { return m_diagnosticConfigs; }
|
CppTools::ClangDiagnosticConfigs diagnosticConfigs() const { return m_diagnosticConfigs; }
|
||||||
void setDiagnosticConfigs(const CppTools::ClangDiagnosticConfigs &configs)
|
void setDiagnosticConfigs(const CppTools::ClangDiagnosticConfigs &configs)
|
||||||
@@ -87,6 +90,9 @@ public:
|
|||||||
RunSettings runSettings() const { return m_runSettings; }
|
RunSettings runSettings() const { return m_runSettings; }
|
||||||
void setRunSettings(const RunSettings &settings) { m_runSettings = settings; }
|
void setRunSettings(const RunSettings &settings) { m_runSettings = settings; }
|
||||||
|
|
||||||
|
static QVersionNumber clangTidyVersion();
|
||||||
|
static QVersionNumber clazyVersion();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void changed();
|
||||||
|
|
||||||
@@ -103,6 +109,10 @@ private:
|
|||||||
|
|
||||||
// Run settings
|
// Run settings
|
||||||
RunSettings m_runSettings;
|
RunSettings m_runSettings;
|
||||||
|
|
||||||
|
// Version info. Ephemeral.
|
||||||
|
QVersionNumber m_clangTidyVersion;
|
||||||
|
QVersionNumber m_clazyVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ using namespace Utils;
|
|||||||
namespace ClangTools {
|
namespace ClangTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
enum class FailSilently { Yes, No };
|
static QString runExecutable(const Utils::CommandLine &commandLine, QueryFailMode queryFailMode)
|
||||||
static QString runExecutable(const Utils::CommandLine &commandLine,
|
|
||||||
FailSilently failSilently = FailSilently::No)
|
|
||||||
{
|
{
|
||||||
if (commandLine.executable().isEmpty() || !commandLine.executable().toFileInfo().isExecutable())
|
if (commandLine.executable().isEmpty() || !commandLine.executable().toFileInfo().isExecutable())
|
||||||
return {};
|
return {};
|
||||||
@@ -58,7 +56,7 @@ static QString runExecutable(const Utils::CommandLine &commandLine,
|
|||||||
|
|
||||||
cpp.runBlocking();
|
cpp.runBlocking();
|
||||||
if (cpp.result() != QtcProcess::FinishedWithSuccess
|
if (cpp.result() != QtcProcess::FinishedWithSuccess
|
||||||
&& (failSilently == FailSilently::No
|
&& (queryFailMode == QueryFailMode::Noisy
|
||||||
|| cpp.result() != QtcProcess::FinishedWithError)) {
|
|| cpp.result() != QtcProcess::FinishedWithError)) {
|
||||||
Core::MessageManager::writeFlashing(cpp.exitMessage());
|
Core::MessageManager::writeFlashing(cpp.exitMessage());
|
||||||
Core::MessageManager::writeFlashing(QString::fromUtf8(cpp.allRawOutput()));
|
Core::MessageManager::writeFlashing(QString::fromUtf8(cpp.allRawOutput()));
|
||||||
@@ -76,7 +74,7 @@ static QStringList queryClangTidyChecks(const QString &executable,
|
|||||||
arguments.prepend(checksArgument);
|
arguments.prepend(checksArgument);
|
||||||
|
|
||||||
const CommandLine commandLine(executable, arguments);
|
const CommandLine commandLine(executable, arguments);
|
||||||
QString output = runExecutable(commandLine);
|
QString output = runExecutable(commandLine, QueryFailMode::Noisy);
|
||||||
if (output.isEmpty())
|
if (output.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
@@ -105,12 +103,14 @@ static QStringList queryClangTidyChecks(const QString &executable,
|
|||||||
static ClazyChecks querySupportedClazyChecks(const QString &executablePath)
|
static ClazyChecks querySupportedClazyChecks(const QString &executablePath)
|
||||||
{
|
{
|
||||||
static const QString queryFlag = "-supported-checks-json";
|
static const QString queryFlag = "-supported-checks-json";
|
||||||
QString jsonOutput = runExecutable(CommandLine(executablePath, {queryFlag}));
|
QString jsonOutput = runExecutable(CommandLine(executablePath, {queryFlag}),
|
||||||
|
QueryFailMode::Noisy);
|
||||||
|
|
||||||
// Some clazy 1.6.x versions have a bug where they expect an argument after the
|
// Some clazy 1.6.x versions have a bug where they expect an argument after the
|
||||||
// option.
|
// option.
|
||||||
if (jsonOutput.isEmpty())
|
if (jsonOutput.isEmpty())
|
||||||
jsonOutput = runExecutable(CommandLine(executablePath, {queryFlag, "dummy"}));
|
jsonOutput = runExecutable(CommandLine(executablePath, {queryFlag, "dummy"}),
|
||||||
|
QueryFailMode::Noisy);
|
||||||
if (jsonOutput.isEmpty())
|
if (jsonOutput.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ static FilePath queryResourceDir(const FilePath &clangToolPath)
|
|||||||
{
|
{
|
||||||
QString output = runExecutable(CommandLine(clangToolPath, {"someFilePath", "--",
|
QString output = runExecutable(CommandLine(clangToolPath, {"someFilePath", "--",
|
||||||
"-print-resource-dir"}),
|
"-print-resource-dir"}),
|
||||||
FailSilently::Yes);
|
QueryFailMode::Silent);
|
||||||
|
|
||||||
// Expected output is (clang-tidy 10):
|
// Expected output is (clang-tidy 10):
|
||||||
// lib/clang/10.0.1
|
// lib/clang/10.0.1
|
||||||
@@ -189,9 +189,9 @@ static FilePath queryResourceDir(const FilePath &clangToolPath)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString queryVersion(const FilePath &clangToolPath)
|
QString queryVersion(const FilePath &clangToolPath, QueryFailMode failMode)
|
||||||
{
|
{
|
||||||
QString output = runExecutable(CommandLine(clangToolPath, {"--version"}));
|
QString output = runExecutable(CommandLine(clangToolPath, {"--version"}), failMode);
|
||||||
QTextStream stream(&output);
|
QTextStream stream(&output);
|
||||||
while (!stream.atEnd()) {
|
while (!stream.atEnd()) {
|
||||||
static const QStringList versionPrefixes{"LLVM version ", "clang version: "};
|
static const QStringList versionPrefixes{"LLVM version ", "clang version: "};
|
||||||
@@ -207,7 +207,7 @@ static QString queryVersion(const FilePath &clangToolPath)
|
|||||||
QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolPath)
|
QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolPath)
|
||||||
{
|
{
|
||||||
const FilePath dynamicResourceDir = queryResourceDir(clangToolPath);
|
const FilePath dynamicResourceDir = queryResourceDir(clangToolPath);
|
||||||
const QString dynamicVersion = queryVersion(clangToolPath);
|
const QString dynamicVersion = queryVersion(clangToolPath, QueryFailMode::Noisy);
|
||||||
if (dynamicResourceDir.isEmpty() || dynamicVersion.isEmpty())
|
if (dynamicResourceDir.isEmpty() || dynamicVersion.isEmpty())
|
||||||
return qMakePair(FilePath::fromString(CLANG_INCLUDE_DIR), QString(CLANG_VERSION));
|
return qMakePair(FilePath::fromString(CLANG_INCLUDE_DIR), QString(CLANG_VERSION));
|
||||||
return qMakePair(dynamicResourceDir + "/include", dynamicVersion);
|
return qMakePair(dynamicResourceDir + "/include", dynamicVersion);
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ namespace Internal {
|
|||||||
|
|
||||||
QPair<Utils::FilePath, QString> getClangIncludeDirAndVersion(const Utils::FilePath &clangToolPath);
|
QPair<Utils::FilePath, QString> getClangIncludeDirAndVersion(const Utils::FilePath &clangToolPath);
|
||||||
|
|
||||||
|
enum class QueryFailMode{ Silent, Noisy };
|
||||||
|
QString queryVersion(const Utils::FilePath &clangToolPath, QueryFailMode failMode);
|
||||||
|
|
||||||
class ClangTidyInfo
|
class ClangTidyInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user