diff --git a/src/plugins/clangtools/clangtoolssettings.cpp b/src/plugins/clangtools/clangtoolssettings.cpp index 2342e12b1db..fe7acf43b93 100644 --- a/src/plugins/clangtools/clangtoolssettings.cpp +++ b/src/plugins/clangtools/clangtoolssettings.cpp @@ -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 diff --git a/src/plugins/clangtools/clangtoolssettings.h b/src/plugins/clangtools/clangtoolssettings.h index ac2a6b41856..73dbc83bb26 100644 --- a/src/plugins/clangtools/clangtoolssettings.h +++ b/src/plugins/clangtools/clangtoolssettings.h @@ -25,12 +25,15 @@ #pragma once +#include "executableinfo.h" + #include #include #include #include +#include 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 diff --git a/src/plugins/clangtools/executableinfo.cpp b/src/plugins/clangtools/executableinfo.cpp index 850be6ef59d..d904334ece4 100644 --- a/src/plugins/clangtools/executableinfo.cpp +++ b/src/plugins/clangtools/executableinfo.cpp @@ -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 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); diff --git a/src/plugins/clangtools/executableinfo.h b/src/plugins/clangtools/executableinfo.h index aa297dcb5ef..7ce1eccde6b 100644 --- a/src/plugins/clangtools/executableinfo.h +++ b/src/plugins/clangtools/executableinfo.h @@ -36,6 +36,9 @@ namespace Internal { QPair getClangIncludeDirAndVersion(const Utils::FilePath &clangToolPath); +enum class QueryFailMode{ Silent, Noisy }; +QString queryVersion(const Utils::FilePath &clangToolPath, QueryFailMode failMode); + class ClangTidyInfo { public: