forked from qt-creator/qt-creator
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:
@@ -67,7 +67,7 @@ ClangTidyRunner::ClangTidyRunner(const ClangDiagnosticConfig &config, QObject *p
|
||||
: ClangToolRunner(parent)
|
||||
{
|
||||
setName(tr("Clang-Tidy"));
|
||||
setExecutable(clangTidyExecutable());
|
||||
setExecutable(toolExecutable(ClangToolType::Tidy));
|
||||
setArgsCreator([this, config](const QStringList &baseOptions) {
|
||||
return QStringList() << tidyChecksArguments(config)
|
||||
<< mainToolArguments()
|
||||
@@ -80,7 +80,7 @@ ClazyStandaloneRunner::ClazyStandaloneRunner(const ClangDiagnosticConfig &config
|
||||
: ClangToolRunner(parent)
|
||||
{
|
||||
setName(tr("Clazy"));
|
||||
setExecutable(clazyStandaloneExecutable());
|
||||
setExecutable(toolExecutable(ClangToolType::Clazy));
|
||||
setArgsCreator([this, config](const QStringList &baseOptions) {
|
||||
return QStringList() << clazyChecksArguments(config)
|
||||
<< mainToolArguments()
|
||||
|
@@ -860,12 +860,14 @@ static CheckResult canAnalyze()
|
||||
{
|
||||
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,
|
||||
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,
|
||||
ClangTool::tr("Set a valid Clazy-Standalone executable.")};
|
||||
}
|
||||
|
@@ -203,12 +203,13 @@ static VersionAndSuffix getVersionNumber(VersionAndSuffix &version, const FilePa
|
||||
|
||||
VersionAndSuffix ClangToolsSettings::clangTidyVersion()
|
||||
{
|
||||
return getVersionNumber(instance()->m_clangTidyVersion, Internal::clangTidyExecutable());
|
||||
return getVersionNumber(instance()->m_clangTidyVersion,
|
||||
Internal::toolExecutable(ClangToolType::Tidy));
|
||||
}
|
||||
|
||||
QVersionNumber ClangToolsSettings::clazyVersion()
|
||||
{
|
||||
return ClazyStandaloneInfo::getInfo(Internal::clazyStandaloneExecutable()).version;
|
||||
return ClazyStandaloneInfo::getInfo(Internal::toolExecutable(ClangToolType::Clazy)).version;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -145,22 +145,6 @@ void showHintAboutBuildBeforeAnalysis()
|
||||
"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 candidate = executable;
|
||||
@@ -190,36 +174,30 @@ static FilePath findValidExecutable(const FilePaths &candidates)
|
||||
return {};
|
||||
}
|
||||
|
||||
FilePath clangTidyFallbackExecutable()
|
||||
FilePath toolShippedExecutable(ClangToolType tool)
|
||||
{
|
||||
return findValidExecutable({
|
||||
shippedClangTidyExecutable(),
|
||||
Constants::CLANG_TIDY_EXECUTABLE_NAME,
|
||||
});
|
||||
const FilePath shippedExecutable = tool == ClangToolType::Tidy
|
||||
? Core::ICore::clangTidyExecutable(CLANG_BINDIR)
|
||||
: 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())
|
||||
return fullPath(fromSettings);
|
||||
return clangTidyFallbackExecutable();
|
||||
return toolFallbackExecutable(tool);
|
||||
}
|
||||
|
||||
FilePath clazyStandaloneFallbackExecutable()
|
||||
FilePath toolFallbackExecutable(ClangToolType tool)
|
||||
{
|
||||
return findValidExecutable({
|
||||
shippedClazyStandaloneExecutable(),
|
||||
Constants::CLAZY_STANDALONE_EXECUTABLE_NAME,
|
||||
});
|
||||
}
|
||||
|
||||
FilePath clazyStandaloneExecutable()
|
||||
{
|
||||
const FilePath fromSettings = ClangToolsSettings::instance()->executable(ClangToolType::Clazy);
|
||||
if (!fromSettings.isEmpty())
|
||||
return fullPath(fromSettings);
|
||||
return clazyStandaloneFallbackExecutable();
|
||||
const FilePath fallback = tool == ClangToolType::Tidy
|
||||
? FilePath(Constants::CLANG_TIDY_EXECUTABLE_NAME)
|
||||
: FilePath(Constants::CLAZY_STANDALONE_EXECUTABLE_NAME);
|
||||
return findValidExecutable({toolShippedExecutable(tool), fallback});
|
||||
}
|
||||
|
||||
static void addBuiltinConfigs(ClangDiagnosticConfigsModel &model)
|
||||
|
@@ -43,13 +43,9 @@ QString createFullLocationString(const Debugger::DiagnosticLocation &location);
|
||||
QString hintAboutBuildBeforeAnalysis();
|
||||
void showHintAboutBuildBeforeAnalysis();
|
||||
|
||||
Utils::FilePath shippedClazyStandaloneExecutable();
|
||||
Utils::FilePath clazyStandaloneExecutable();
|
||||
Utils::FilePath clazyStandaloneFallbackExecutable();
|
||||
|
||||
Utils::FilePath shippedClangTidyExecutable();
|
||||
Utils::FilePath clangTidyExecutable();
|
||||
Utils::FilePath clangTidyFallbackExecutable();
|
||||
Utils::FilePath toolShippedExecutable(CppEditor::ClangToolType tool);
|
||||
Utils::FilePath toolExecutable(CppEditor::ClangToolType tool);
|
||||
Utils::FilePath toolFallbackExecutable(CppEditor::ClangToolType tool);
|
||||
|
||||
Utils::FilePath fullPath(const Utils::FilePath &executable);
|
||||
|
||||
|
@@ -1265,7 +1265,7 @@ void DiagnosticConfigsWidget::syncClazyChecksGroupBox()
|
||||
|
||||
QString removeClangTidyCheck(const QString &checks, const QString &check)
|
||||
{
|
||||
const ClangTidyInfo tidyInfo(clangTidyExecutable());
|
||||
const ClangTidyInfo tidyInfo(toolExecutable(ClangToolType::Tidy));
|
||||
TidyChecksTreeModel model(tidyInfo.supportedChecks);
|
||||
model.selectChecks(checks);
|
||||
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)
|
||||
{
|
||||
const ClazyStandaloneInfo clazyInfo = ClazyStandaloneInfo::getInfo(clazyStandaloneExecutable());
|
||||
const ClazyStandaloneInfo clazyInfo = ClazyStandaloneInfo::getInfo(toolExecutable(ClangToolType::Clazy));
|
||||
ClazyChecksTreeModel model(clazyInfo.supportedChecks);
|
||||
model.enableChecks(checks.split(',', Qt::SkipEmptyParts));
|
||||
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) {
|
||||
config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks);
|
||||
const ClazyStandaloneInfo clazyInfo
|
||||
= ClazyStandaloneInfo::getInfo(clazyStandaloneExecutable());
|
||||
= ClazyStandaloneInfo::getInfo(toolExecutable(ClangToolType::Clazy));
|
||||
config.setChecks(ClangToolType::Clazy, clazyInfo.defaultChecks.join(','));
|
||||
}
|
||||
config.setChecks(ClangToolType::Clazy,
|
||||
@@ -1336,7 +1336,7 @@ void disableChecks(const QList<Diagnostic> &diagnostics)
|
||||
} else if (config.clangTidyMode() != ClangDiagnosticConfig::TidyMode::UseConfigFile) {
|
||||
if (config.clangTidyMode() == ClangDiagnosticConfig::TidyMode::UseDefaultChecks) {
|
||||
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,
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <QSpinBox>
|
||||
#include <QThread>
|
||||
|
||||
using namespace CppEditor;
|
||||
using namespace Utils;
|
||||
|
||||
namespace ClangTools::Internal {
|
||||
@@ -28,7 +29,7 @@ RunSettingsWidget::RunSettingsWidget(QWidget *parent)
|
||||
{
|
||||
resize(383, 125);
|
||||
|
||||
m_diagnosticWidget = new CppEditor::ClangDiagnosticConfigsSelectionWidget;
|
||||
m_diagnosticWidget = new ClangDiagnosticConfigsSelectionWidget;
|
||||
|
||||
m_buildBeforeAnalysis = new QCheckBox(tr("Build the project before analysis"));
|
||||
|
||||
@@ -55,13 +56,13 @@ RunSettingsWidget::RunSettingsWidget(QWidget *parent)
|
||||
|
||||
RunSettingsWidget::~RunSettingsWidget() = default;
|
||||
|
||||
CppEditor::ClangDiagnosticConfigsSelectionWidget *RunSettingsWidget::diagnosticSelectionWidget()
|
||||
ClangDiagnosticConfigsSelectionWidget *RunSettingsWidget::diagnosticSelectionWidget()
|
||||
{
|
||||
return m_diagnosticWidget;
|
||||
}
|
||||
|
||||
static CppEditor::ClangDiagnosticConfigsWidget *createEditWidget(
|
||||
const CppEditor::ClangDiagnosticConfigs &configs, const Id &configToSelect)
|
||||
static ClangDiagnosticConfigsWidget *createEditWidget(const ClangDiagnosticConfigs &configs,
|
||||
const Id &configToSelect)
|
||||
{
|
||||
// Determine executable paths
|
||||
FilePath clangTidyPath;
|
||||
@@ -69,16 +70,17 @@ static CppEditor::ClangDiagnosticConfigsWidget *createEditWidget(
|
||||
if (auto settingsWidget = SettingsWidget::instance()) {
|
||||
// Global settings case; executables might not yet applied to settings
|
||||
clangTidyPath = settingsWidget->clangTidyPath();
|
||||
clangTidyPath = clangTidyPath.isEmpty() ? clangTidyFallbackExecutable()
|
||||
clangTidyPath = clangTidyPath.isEmpty() ? toolFallbackExecutable(ClangToolType::Tidy)
|
||||
: fullPath(clangTidyPath);
|
||||
|
||||
clazyStandalonePath = settingsWidget->clazyStandalonePath();
|
||||
clazyStandalonePath = clazyStandalonePath.isEmpty() ? clazyStandaloneFallbackExecutable()
|
||||
: fullPath(clazyStandalonePath);
|
||||
clazyStandalonePath = clazyStandalonePath.isEmpty()
|
||||
? toolFallbackExecutable(ClangToolType::Clazy)
|
||||
: fullPath(clazyStandalonePath);
|
||||
} else {
|
||||
// "Projects Mode > Clang Tools" case, check settings
|
||||
clangTidyPath = clangTidyExecutable();
|
||||
clazyStandalonePath = clazyStandaloneExecutable();
|
||||
clangTidyPath = toolExecutable(ClangToolType::Tidy);
|
||||
clazyStandalonePath = toolExecutable(ClangToolType::Clazy);
|
||||
}
|
||||
|
||||
return new DiagnosticConfigsWidget(configs,
|
||||
@@ -93,10 +95,8 @@ void RunSettingsWidget::fromSettings(const RunSettings &s)
|
||||
m_diagnosticWidget->refresh(diagnosticConfigsModel(),
|
||||
s.diagnosticConfigId(),
|
||||
createEditWidget);
|
||||
connect(m_diagnosticWidget,
|
||||
&CppEditor::ClangDiagnosticConfigsSelectionWidget::changed,
|
||||
this,
|
||||
&RunSettingsWidget::changed);
|
||||
connect(m_diagnosticWidget, &ClangDiagnosticConfigsSelectionWidget::changed,
|
||||
this, &RunSettingsWidget::changed);
|
||||
|
||||
disconnect(m_buildBeforeAnalysis, 0, 0, 0);
|
||||
m_buildBeforeAnalysis->setToolTip(hintAboutBuildBeforeAnalysis());
|
||||
|
@@ -36,7 +36,7 @@ SettingsWidget::SettingsWidget()
|
||||
|
||||
resize(400, 300);
|
||||
|
||||
QString placeHolderText = shippedClangTidyExecutable().toUserOutput();
|
||||
QString placeHolderText = toolShippedExecutable(ClangToolType::Tidy).toUserOutput();
|
||||
FilePath path = m_settings->executable(ClangToolType::Tidy);
|
||||
if (path.isEmpty() && placeHolderText.isEmpty())
|
||||
path = Constants::CLANG_TIDY_EXECUTABLE_NAME;
|
||||
@@ -47,7 +47,7 @@ SettingsWidget::SettingsWidget()
|
||||
m_clangTidyPathChooser->setFilePath(path);
|
||||
m_clangTidyPathChooser->setHistoryCompleter("ClangTools.ClangTidyExecutable.History");
|
||||
|
||||
placeHolderText = shippedClazyStandaloneExecutable().toUserOutput();
|
||||
placeHolderText = toolShippedExecutable(ClangToolType::Clazy).toUserOutput();
|
||||
path = m_settings->executable(ClangToolType::Clazy);
|
||||
if (path.isEmpty() && placeHolderText.isEmpty())
|
||||
path = Constants::CLAZY_STANDALONE_EXECUTABLE_NAME;
|
||||
|
Reference in New Issue
Block a user