ClangToolsUtils: Reuse ClangToolType enum

Change-Id: Iee95a014d634a99c6e10582f8e942a12ebf1bd74
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Jarek Kobus
2023-01-10 16:36:59 +01:00
parent 0ba3dbf1be
commit c4882a5a7a
8 changed files with 46 additions and 69 deletions

View File

@@ -67,7 +67,7 @@ ClangTidyRunner::ClangTidyRunner(const ClangDiagnosticConfig &config, QObject *p
: ClangToolRunner(parent) : ClangToolRunner(parent)
{ {
setName(tr("Clang-Tidy")); setName(tr("Clang-Tidy"));
setExecutable(clangTidyExecutable()); setExecutable(toolExecutable(ClangToolType::Tidy));
setArgsCreator([this, config](const QStringList &baseOptions) { setArgsCreator([this, config](const QStringList &baseOptions) {
return QStringList() << tidyChecksArguments(config) return QStringList() << tidyChecksArguments(config)
<< mainToolArguments() << mainToolArguments()
@@ -80,7 +80,7 @@ ClazyStandaloneRunner::ClazyStandaloneRunner(const ClangDiagnosticConfig &config
: ClangToolRunner(parent) : ClangToolRunner(parent)
{ {
setName(tr("Clazy")); setName(tr("Clazy"));
setExecutable(clazyStandaloneExecutable()); setExecutable(toolExecutable(ClangToolType::Clazy));
setArgsCreator([this, config](const QStringList &baseOptions) { setArgsCreator([this, config](const QStringList &baseOptions) {
return QStringList() << clazyChecksArguments(config) return QStringList() << clazyChecksArguments(config)
<< mainToolArguments() << mainToolArguments()

View File

@@ -860,12 +860,14 @@ static CheckResult canAnalyze()
{ {
const ClangDiagnosticConfig config = diagnosticConfig(runSettings().diagnosticConfigId()); const ClangDiagnosticConfig config = diagnosticConfig(runSettings().diagnosticConfigId());
if (config.isEnabled(ClangToolType::Tidy) && !clangTidyExecutable().isExecutableFile()) { if (config.isEnabled(ClangToolType::Tidy)
&& !toolExecutable(ClangToolType::Tidy).isExecutableFile()) {
return {CheckResult::InvalidTidyExecutable, return {CheckResult::InvalidTidyExecutable,
ClangTool::tr("Set a valid Clang-Tidy executable.")}; ClangTool::tr("Set a valid Clang-Tidy executable.")};
} }
if (config.isEnabled(ClangToolType::Clazy) && !clazyStandaloneExecutable().isExecutableFile()) { if (config.isEnabled(ClangToolType::Clazy)
&& !toolExecutable(ClangToolType::Clazy).isExecutableFile()) {
return {CheckResult::InvalidClazyExecutable, return {CheckResult::InvalidClazyExecutable,
ClangTool::tr("Set a valid Clazy-Standalone executable.")}; ClangTool::tr("Set a valid Clazy-Standalone executable.")};
} }

View File

@@ -203,12 +203,13 @@ static VersionAndSuffix getVersionNumber(VersionAndSuffix &version, const FilePa
VersionAndSuffix ClangToolsSettings::clangTidyVersion() VersionAndSuffix ClangToolsSettings::clangTidyVersion()
{ {
return getVersionNumber(instance()->m_clangTidyVersion, Internal::clangTidyExecutable()); return getVersionNumber(instance()->m_clangTidyVersion,
Internal::toolExecutable(ClangToolType::Tidy));
} }
QVersionNumber ClangToolsSettings::clazyVersion() QVersionNumber ClangToolsSettings::clazyVersion()
{ {
return ClazyStandaloneInfo::getInfo(Internal::clazyStandaloneExecutable()).version; return ClazyStandaloneInfo::getInfo(Internal::toolExecutable(ClangToolType::Clazy)).version;
} }
} // namespace Internal } // namespace Internal

View File

@@ -145,22 +145,6 @@ void showHintAboutBuildBeforeAnalysis()
"ClangToolsDisablingBuildBeforeAnalysisHint"); "ClangToolsDisablingBuildBeforeAnalysisHint");
} }
FilePath shippedClangTidyExecutable()
{
const FilePath shippedExecutable = Core::ICore::clangTidyExecutable(CLANG_BINDIR);
if (shippedExecutable.isExecutableFile())
return shippedExecutable;
return {};
}
FilePath shippedClazyStandaloneExecutable()
{
const FilePath shippedExecutable = Core::ICore::clazyStandaloneExecutable(CLANG_BINDIR);
if (shippedExecutable.isExecutableFile())
return shippedExecutable;
return {};
}
FilePath fullPath(const FilePath &executable) FilePath fullPath(const FilePath &executable)
{ {
FilePath candidate = executable; FilePath candidate = executable;
@@ -190,36 +174,30 @@ static FilePath findValidExecutable(const FilePaths &candidates)
return {}; return {};
} }
FilePath clangTidyFallbackExecutable() FilePath toolShippedExecutable(ClangToolType tool)
{ {
return findValidExecutable({ const FilePath shippedExecutable = tool == ClangToolType::Tidy
shippedClangTidyExecutable(), ? Core::ICore::clangTidyExecutable(CLANG_BINDIR)
Constants::CLANG_TIDY_EXECUTABLE_NAME, : Core::ICore::clazyStandaloneExecutable(CLANG_BINDIR);
}); if (shippedExecutable.isExecutableFile())
return shippedExecutable;
return {};
} }
FilePath clangTidyExecutable() FilePath toolExecutable(ClangToolType tool)
{ {
const FilePath fromSettings = ClangToolsSettings::instance()->executable(ClangToolType::Tidy); const FilePath fromSettings = ClangToolsSettings::instance()->executable(tool);
if (!fromSettings.isEmpty()) if (!fromSettings.isEmpty())
return fullPath(fromSettings); return fullPath(fromSettings);
return clangTidyFallbackExecutable(); return toolFallbackExecutable(tool);
} }
FilePath clazyStandaloneFallbackExecutable() FilePath toolFallbackExecutable(ClangToolType tool)
{ {
return findValidExecutable({ const FilePath fallback = tool == ClangToolType::Tidy
shippedClazyStandaloneExecutable(), ? FilePath(Constants::CLANG_TIDY_EXECUTABLE_NAME)
Constants::CLAZY_STANDALONE_EXECUTABLE_NAME, : FilePath(Constants::CLAZY_STANDALONE_EXECUTABLE_NAME);
}); return findValidExecutable({toolShippedExecutable(tool), fallback});
}
FilePath clazyStandaloneExecutable()
{
const FilePath fromSettings = ClangToolsSettings::instance()->executable(ClangToolType::Clazy);
if (!fromSettings.isEmpty())
return fullPath(fromSettings);
return clazyStandaloneFallbackExecutable();
} }
static void addBuiltinConfigs(ClangDiagnosticConfigsModel &model) static void addBuiltinConfigs(ClangDiagnosticConfigsModel &model)

View File

@@ -43,13 +43,9 @@ QString createFullLocationString(const Debugger::DiagnosticLocation &location);
QString hintAboutBuildBeforeAnalysis(); QString hintAboutBuildBeforeAnalysis();
void showHintAboutBuildBeforeAnalysis(); void showHintAboutBuildBeforeAnalysis();
Utils::FilePath shippedClazyStandaloneExecutable(); Utils::FilePath toolShippedExecutable(CppEditor::ClangToolType tool);
Utils::FilePath clazyStandaloneExecutable(); Utils::FilePath toolExecutable(CppEditor::ClangToolType tool);
Utils::FilePath clazyStandaloneFallbackExecutable(); Utils::FilePath toolFallbackExecutable(CppEditor::ClangToolType tool);
Utils::FilePath shippedClangTidyExecutable();
Utils::FilePath clangTidyExecutable();
Utils::FilePath clangTidyFallbackExecutable();
Utils::FilePath fullPath(const Utils::FilePath &executable); Utils::FilePath fullPath(const Utils::FilePath &executable);

View File

@@ -1265,7 +1265,7 @@ void DiagnosticConfigsWidget::syncClazyChecksGroupBox()
QString removeClangTidyCheck(const QString &checks, const QString &check) QString removeClangTidyCheck(const QString &checks, const QString &check)
{ {
const ClangTidyInfo tidyInfo(clangTidyExecutable()); const ClangTidyInfo tidyInfo(toolExecutable(ClangToolType::Tidy));
TidyChecksTreeModel model(tidyInfo.supportedChecks); TidyChecksTreeModel model(tidyInfo.supportedChecks);
model.selectChecks(checks); model.selectChecks(checks);
const QModelIndex index = model.indexForName(check); const QModelIndex index = model.indexForName(check);
@@ -1277,7 +1277,7 @@ QString removeClangTidyCheck(const QString &checks, const QString &check)
QString removeClazyCheck(const QString &checks, const QString &check) QString removeClazyCheck(const QString &checks, const QString &check)
{ {
const ClazyStandaloneInfo clazyInfo = ClazyStandaloneInfo::getInfo(clazyStandaloneExecutable()); const ClazyStandaloneInfo clazyInfo = ClazyStandaloneInfo::getInfo(toolExecutable(ClangToolType::Clazy));
ClazyChecksTreeModel model(clazyInfo.supportedChecks); ClazyChecksTreeModel model(clazyInfo.supportedChecks);
model.enableChecks(checks.split(',', Qt::SkipEmptyParts)); model.enableChecks(checks.split(',', Qt::SkipEmptyParts));
const QModelIndex index = model.indexForName(check.mid(QString("clazy-").length())); const QModelIndex index = model.indexForName(check.mid(QString("clazy-").length()));
@@ -1328,7 +1328,7 @@ void disableChecks(const QList<Diagnostic> &diagnostics)
if (config.clazyMode() == ClangDiagnosticConfig::ClazyMode::UseDefaultChecks) { if (config.clazyMode() == ClangDiagnosticConfig::ClazyMode::UseDefaultChecks) {
config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks); config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks);
const ClazyStandaloneInfo clazyInfo const ClazyStandaloneInfo clazyInfo
= ClazyStandaloneInfo::getInfo(clazyStandaloneExecutable()); = ClazyStandaloneInfo::getInfo(toolExecutable(ClangToolType::Clazy));
config.setChecks(ClangToolType::Clazy, clazyInfo.defaultChecks.join(',')); config.setChecks(ClangToolType::Clazy, clazyInfo.defaultChecks.join(','));
} }
config.setChecks(ClangToolType::Clazy, config.setChecks(ClangToolType::Clazy,
@@ -1336,7 +1336,7 @@ void disableChecks(const QList<Diagnostic> &diagnostics)
} else if (config.clangTidyMode() != ClangDiagnosticConfig::TidyMode::UseConfigFile) { } else if (config.clangTidyMode() != ClangDiagnosticConfig::TidyMode::UseConfigFile) {
if (config.clangTidyMode() == ClangDiagnosticConfig::TidyMode::UseDefaultChecks) { if (config.clangTidyMode() == ClangDiagnosticConfig::TidyMode::UseDefaultChecks) {
config.setClangTidyMode(ClangDiagnosticConfig::TidyMode::UseCustomChecks); config.setClangTidyMode(ClangDiagnosticConfig::TidyMode::UseCustomChecks);
const ClangTidyInfo tidyInfo(clangTidyExecutable()); const ClangTidyInfo tidyInfo(toolExecutable(ClangToolType::Tidy));
config.setChecks(ClangToolType::Tidy, tidyInfo.defaultChecks.join(',')); config.setChecks(ClangToolType::Tidy, tidyInfo.defaultChecks.join(','));
} }
config.setChecks(ClangToolType::Tidy, config.setChecks(ClangToolType::Tidy,

View File

@@ -19,6 +19,7 @@
#include <QSpinBox> #include <QSpinBox>
#include <QThread> #include <QThread>
using namespace CppEditor;
using namespace Utils; using namespace Utils;
namespace ClangTools::Internal { namespace ClangTools::Internal {
@@ -28,7 +29,7 @@ RunSettingsWidget::RunSettingsWidget(QWidget *parent)
{ {
resize(383, 125); resize(383, 125);
m_diagnosticWidget = new CppEditor::ClangDiagnosticConfigsSelectionWidget; m_diagnosticWidget = new ClangDiagnosticConfigsSelectionWidget;
m_buildBeforeAnalysis = new QCheckBox(tr("Build the project before analysis")); m_buildBeforeAnalysis = new QCheckBox(tr("Build the project before analysis"));
@@ -55,13 +56,13 @@ RunSettingsWidget::RunSettingsWidget(QWidget *parent)
RunSettingsWidget::~RunSettingsWidget() = default; RunSettingsWidget::~RunSettingsWidget() = default;
CppEditor::ClangDiagnosticConfigsSelectionWidget *RunSettingsWidget::diagnosticSelectionWidget() ClangDiagnosticConfigsSelectionWidget *RunSettingsWidget::diagnosticSelectionWidget()
{ {
return m_diagnosticWidget; return m_diagnosticWidget;
} }
static CppEditor::ClangDiagnosticConfigsWidget *createEditWidget( static ClangDiagnosticConfigsWidget *createEditWidget(const ClangDiagnosticConfigs &configs,
const CppEditor::ClangDiagnosticConfigs &configs, const Id &configToSelect) const Id &configToSelect)
{ {
// Determine executable paths // Determine executable paths
FilePath clangTidyPath; FilePath clangTidyPath;
@@ -69,16 +70,17 @@ static CppEditor::ClangDiagnosticConfigsWidget *createEditWidget(
if (auto settingsWidget = SettingsWidget::instance()) { if (auto settingsWidget = SettingsWidget::instance()) {
// Global settings case; executables might not yet applied to settings // Global settings case; executables might not yet applied to settings
clangTidyPath = settingsWidget->clangTidyPath(); clangTidyPath = settingsWidget->clangTidyPath();
clangTidyPath = clangTidyPath.isEmpty() ? clangTidyFallbackExecutable() clangTidyPath = clangTidyPath.isEmpty() ? toolFallbackExecutable(ClangToolType::Tidy)
: fullPath(clangTidyPath); : fullPath(clangTidyPath);
clazyStandalonePath = settingsWidget->clazyStandalonePath(); clazyStandalonePath = settingsWidget->clazyStandalonePath();
clazyStandalonePath = clazyStandalonePath.isEmpty() ? clazyStandaloneFallbackExecutable() clazyStandalonePath = clazyStandalonePath.isEmpty()
: fullPath(clazyStandalonePath); ? toolFallbackExecutable(ClangToolType::Clazy)
: fullPath(clazyStandalonePath);
} else { } else {
// "Projects Mode > Clang Tools" case, check settings // "Projects Mode > Clang Tools" case, check settings
clangTidyPath = clangTidyExecutable(); clangTidyPath = toolExecutable(ClangToolType::Tidy);
clazyStandalonePath = clazyStandaloneExecutable(); clazyStandalonePath = toolExecutable(ClangToolType::Clazy);
} }
return new DiagnosticConfigsWidget(configs, return new DiagnosticConfigsWidget(configs,
@@ -93,10 +95,8 @@ void RunSettingsWidget::fromSettings(const RunSettings &s)
m_diagnosticWidget->refresh(diagnosticConfigsModel(), m_diagnosticWidget->refresh(diagnosticConfigsModel(),
s.diagnosticConfigId(), s.diagnosticConfigId(),
createEditWidget); createEditWidget);
connect(m_diagnosticWidget, connect(m_diagnosticWidget, &ClangDiagnosticConfigsSelectionWidget::changed,
&CppEditor::ClangDiagnosticConfigsSelectionWidget::changed, this, &RunSettingsWidget::changed);
this,
&RunSettingsWidget::changed);
disconnect(m_buildBeforeAnalysis, 0, 0, 0); disconnect(m_buildBeforeAnalysis, 0, 0, 0);
m_buildBeforeAnalysis->setToolTip(hintAboutBuildBeforeAnalysis()); m_buildBeforeAnalysis->setToolTip(hintAboutBuildBeforeAnalysis());

View File

@@ -36,7 +36,7 @@ SettingsWidget::SettingsWidget()
resize(400, 300); resize(400, 300);
QString placeHolderText = shippedClangTidyExecutable().toUserOutput(); QString placeHolderText = toolShippedExecutable(ClangToolType::Tidy).toUserOutput();
FilePath path = m_settings->executable(ClangToolType::Tidy); FilePath path = m_settings->executable(ClangToolType::Tidy);
if (path.isEmpty() && placeHolderText.isEmpty()) if (path.isEmpty() && placeHolderText.isEmpty())
path = Constants::CLANG_TIDY_EXECUTABLE_NAME; path = Constants::CLANG_TIDY_EXECUTABLE_NAME;
@@ -47,7 +47,7 @@ SettingsWidget::SettingsWidget()
m_clangTidyPathChooser->setFilePath(path); m_clangTidyPathChooser->setFilePath(path);
m_clangTidyPathChooser->setHistoryCompleter("ClangTools.ClangTidyExecutable.History"); m_clangTidyPathChooser->setHistoryCompleter("ClangTools.ClangTidyExecutable.History");
placeHolderText = shippedClazyStandaloneExecutable().toUserOutput(); placeHolderText = toolShippedExecutable(ClangToolType::Clazy).toUserOutput();
path = m_settings->executable(ClangToolType::Clazy); path = m_settings->executable(ClangToolType::Clazy);
if (path.isEmpty() && placeHolderText.isEmpty()) if (path.isEmpty() && placeHolderText.isEmpty())
path = Constants::CLAZY_STANDALONE_EXECUTABLE_NAME; path = Constants::CLAZY_STANDALONE_EXECUTABLE_NAME;