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();
|
||||
}
|
||||
|
||||
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 ClangTools
|
||||
|
||||
@@ -25,12 +25,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "executableinfo.h"
|
||||
|
||||
#include <cpptools/clangdiagnosticconfig.h>
|
||||
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QVersionNumber>
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
@@ -75,10 +78,10 @@ public:
|
||||
void writeSettings();
|
||||
|
||||
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; }
|
||||
void setClazyStandaloneExecutable(const QString &path) { m_clazyStandaloneExecutable = path; }
|
||||
void setClazyStandaloneExecutable(const QString &path);
|
||||
|
||||
CppTools::ClangDiagnosticConfigs diagnosticConfigs() const { return m_diagnosticConfigs; }
|
||||
void setDiagnosticConfigs(const CppTools::ClangDiagnosticConfigs &configs)
|
||||
@@ -87,6 +90,9 @@ public:
|
||||
RunSettings runSettings() const { return m_runSettings; }
|
||||
void setRunSettings(const RunSettings &settings) { m_runSettings = settings; }
|
||||
|
||||
static QVersionNumber clangTidyVersion();
|
||||
static QVersionNumber clazyVersion();
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
@@ -103,6 +109,10 @@ private:
|
||||
|
||||
// Run settings
|
||||
RunSettings m_runSettings;
|
||||
|
||||
// Version info. Ephemeral.
|
||||
QVersionNumber m_clangTidyVersion;
|
||||
QVersionNumber m_clazyVersion;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -43,9 +43,7 @@ using namespace Utils;
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
|
||||
enum class FailSilently { Yes, No };
|
||||
static QString runExecutable(const Utils::CommandLine &commandLine,
|
||||
FailSilently failSilently = FailSilently::No)
|
||||
static QString runExecutable(const Utils::CommandLine &commandLine, QueryFailMode queryFailMode)
|
||||
{
|
||||
if (commandLine.executable().isEmpty() || !commandLine.executable().toFileInfo().isExecutable())
|
||||
return {};
|
||||
@@ -58,7 +56,7 @@ static QString runExecutable(const Utils::CommandLine &commandLine,
|
||||
|
||||
cpp.runBlocking();
|
||||
if (cpp.result() != QtcProcess::FinishedWithSuccess
|
||||
&& (failSilently == FailSilently::No
|
||||
&& (queryFailMode == QueryFailMode::Noisy
|
||||
|| cpp.result() != QtcProcess::FinishedWithError)) {
|
||||
Core::MessageManager::writeFlashing(cpp.exitMessage());
|
||||
Core::MessageManager::writeFlashing(QString::fromUtf8(cpp.allRawOutput()));
|
||||
@@ -76,7 +74,7 @@ static QStringList queryClangTidyChecks(const QString &executable,
|
||||
arguments.prepend(checksArgument);
|
||||
|
||||
const CommandLine commandLine(executable, arguments);
|
||||
QString output = runExecutable(commandLine);
|
||||
QString output = runExecutable(commandLine, QueryFailMode::Noisy);
|
||||
if (output.isEmpty())
|
||||
return {};
|
||||
|
||||
@@ -105,12 +103,14 @@ static QStringList queryClangTidyChecks(const QString &executable,
|
||||
static ClazyChecks querySupportedClazyChecks(const QString &executablePath)
|
||||
{
|
||||
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
|
||||
// option.
|
||||
if (jsonOutput.isEmpty())
|
||||
jsonOutput = runExecutable(CommandLine(executablePath, {queryFlag, "dummy"}));
|
||||
jsonOutput = runExecutable(CommandLine(executablePath, {queryFlag, "dummy"}),
|
||||
QueryFailMode::Noisy);
|
||||
if (jsonOutput.isEmpty())
|
||||
return {};
|
||||
|
||||
@@ -172,7 +172,7 @@ static FilePath queryResourceDir(const FilePath &clangToolPath)
|
||||
{
|
||||
QString output = runExecutable(CommandLine(clangToolPath, {"someFilePath", "--",
|
||||
"-print-resource-dir"}),
|
||||
FailSilently::Yes);
|
||||
QueryFailMode::Silent);
|
||||
|
||||
// Expected output is (clang-tidy 10):
|
||||
// lib/clang/10.0.1
|
||||
@@ -189,9 +189,9 @@ static FilePath queryResourceDir(const FilePath &clangToolPath)
|
||||
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);
|
||||
while (!stream.atEnd()) {
|
||||
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)
|
||||
{
|
||||
const FilePath dynamicResourceDir = queryResourceDir(clangToolPath);
|
||||
const QString dynamicVersion = queryVersion(clangToolPath);
|
||||
const QString dynamicVersion = queryVersion(clangToolPath, QueryFailMode::Noisy);
|
||||
if (dynamicResourceDir.isEmpty() || dynamicVersion.isEmpty())
|
||||
return qMakePair(FilePath::fromString(CLANG_INCLUDE_DIR), QString(CLANG_VERSION));
|
||||
return qMakePair(dynamicResourceDir + "/include", dynamicVersion);
|
||||
|
||||
@@ -36,6 +36,9 @@ namespace Internal {
|
||||
|
||||
QPair<Utils::FilePath, QString> getClangIncludeDirAndVersion(const Utils::FilePath &clangToolPath);
|
||||
|
||||
enum class QueryFailMode{ Silent, Noisy };
|
||||
QString queryVersion(const Utils::FilePath &clangToolPath, QueryFailMode failMode);
|
||||
|
||||
class ClangTidyInfo
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user