[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdev-clang-tidy] /: Implement runtime detection of clang-tidy
From: Kevin Funk <kfunk () kde ! org>
Date: 2016-11-30 22:18:14
Message-ID: E1cCDCg-0005ta-QL () code ! kde ! org
[Download RAW message or body]
Git commit 74da34922eebf261d6c56bd5b0708aa54461b328 by Kevin Funk.
Committed on 30/11/2016 at 22:18.
Pushed by kfunk into branch 'master'.
Implement runtime detection of clang-tidy
Solves some TODOs. The plugin is way more usable now IMO.
CCMAIL: carlosnsoliveira@gmail.com
M +0 -12 CMakeLists.txt
M +1 -1 res/clangtidyconfig.kcfg
D +0 -14 res/clangtidyconfig.kcfg.in
M +2 -2 src/config/clangtidypreferences.cpp
M +11 -14 src/plugin.cpp
D +0 -107 src/plugin.h.in
https://commits.kde.org/kdev-clang-tidy/74da34922eebf261d6c56bd5b0708aa54461b328
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b215ac5..24357ba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,18 +20,6 @@ find_package(Qt5 REQUIRED Core Widgets Test)
find_package(KF5 REQUIRED COMPONENTS IconThemes ItemModels ThreadWeaver TextEditor \
I18n) find_package(KDevPlatform ${KDEVPLATFORM_VERSION} REQUIRED)
-# find clang-tidy executable and sets it in plugin.h.in
-find_program(CLANG_TIDY_EXEC NAMES "clang-tidy")
-if(NOT CLANG_TIDY_EXEC)
- message(ERROR "clang-tidy program not found")
-else()
- configure_file("${PROJECT_SOURCE_DIR}/src/plugin/plugin.h.in"
- "${PROJECT_SOURCE_DIR}/src/plugin/plugin.h" )
-
- configure_file("${PROJECT_SOURCE_DIR}/res/clangtidyconfig.kcfg.in"
- "${PROJECT_SOURCE_DIR}/res/clangtidyconfig.kcfg" ) \
-endif()
-
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include_directories(
diff --git a/res/clangtidyconfig.kcfg b/res/clangtidyconfig.kcfg
index e0d0112..9fb01ae 100644
--- a/res/clangtidyconfig.kcfg
+++ b/res/clangtidyconfig.kcfg
@@ -5,7 +5,7 @@
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<group name="Clangtidy">
<entry name="clangtidyPath" key="Clangtidy Path" type="Url">
- <default>file:///usr/bin/clang-tidy</default>
+ <default></default>
<label>clang-tidy Executable</label>
<tooltip>The full path to the clang-tidy executable</tooltip>
<whatsthis>The full path to the clang-tidy executable.</whatsthis>
diff --git a/res/clangtidyconfig.kcfg.in b/res/clangtidyconfig.kcfg.in
deleted file mode 100644
index 6f80342..0000000
--- a/res/clangtidyconfig.kcfg.in
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
- http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
- <group name="Clangtidy">
- <entry name="clangtidyPath" key="Clangtidy Path" type="Url">
- <default>file://@CLANG_TIDY_EXEC@</default>
- <label>clang-tidy Executable</label>
- <tooltip>The full path to the clang-tidy executable</tooltip>
- <whatsthis>The full path to the clang-tidy executable.</whatsthis>
- </entry>
- </group>
-</kcfg>
diff --git a/src/config/clangtidypreferences.cpp \
b/src/config/clangtidypreferences.cpp index 091ab7d..658c26e 100644
--- a/src/config/clangtidypreferences.cpp
+++ b/src/config/clangtidypreferences.cpp
@@ -67,6 +67,6 @@ QIcon ClangtidyPreferences::icon() const
void ClangtidyPreferences::apply()
{
- ConfigGroup projConf = KSharedConfig::openConfig()->group("Clangtidy");
- projConf.writeEntry(ConfigGroup::ExecutablePath, \
ui->kcfg_clangtidyPath->text()); + ConfigGroup configGroup = \
KSharedConfig::openConfig()->group("Clangtidy"); + \
configGroup.writeEntry(ConfigGroup::ExecutablePath, ui->kcfg_clangtidyPath->text()); \
}
diff --git a/src/plugin.cpp b/src/plugin.cpp
index fcd9028..450e399 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -93,15 +93,12 @@ Plugin::Plugin(QObject* parent, const QVariantList& /*unused*/)
pms->addModel(QStringLiteral("Clangtidy"), i18n("Clang-Tidy"), m_model.data());
m_config = KSharedConfig::openConfig()->group("Clangtidy");
- auto clangtidyPath = m_config.readEntry(ConfigGroup::ExecutablePath);
-
- // TODO(cnihelton): auto detect clang-tidy executable instead of hard-coding
- // it.
- if (clangtidyPath.isEmpty()) {
- clangtidyPath = QString(CLANG_TIDY_PATH);
+ auto clangTidyPath = m_config.readEntry(ConfigGroup::ExecutablePath);
+ if (clangTidyPath.isEmpty()) {
+ clangTidyPath = QStandardPaths::findExecutable("clang-tidy");
}
- collectAllAvailableChecks(clangtidyPath);
+ collectAllAvailableChecks(clangTidyPath);
m_config.writeEntry(ConfigGroup::AdditionalParameters, "");
for (auto check : m_allChecks) {
@@ -123,11 +120,11 @@ void Plugin::unload()
pms->removeModel(QStringLiteral("Clangtidy"));
}
-void Plugin::collectAllAvailableChecks(QString clangtidyPath)
+void Plugin::collectAllAvailableChecks(QString clangTidyPath)
{
m_allChecks.clear();
KProcess tidy;
- tidy << clangtidyPath << QLatin1String("-checks=*") << \
QLatin1String("--list-checks"); + tidy << clangTidyPath << \
QLatin1String("-checks=*") << QLatin1String("--list-checks"); \
tidy.setOutputChannelMode(KProcess::OnlyStdoutChannel); tidy.start();
@@ -177,18 +174,18 @@ void Plugin::runClangtidy(bool allFiles)
return;
}
- auto clangtidyPath = m_config.readEntry(ConfigGroup::ExecutablePath);
+ ConfigGroup configGroup = KSharedConfig::openConfig()->group("Clangtidy");
+ auto clangTidyPath = configGroup.readEntry(ConfigGroup::ExecutablePath);
auto buildSystem = project->buildSystemManager();
Job::Parameters params;
params.projectRootDir = project->path().toLocalFile();
- // TODO: auto detect clang-tidy executable instead of hard-coding it.
- if (clangtidyPath.isEmpty()) {
- params.executablePath = QStringLiteral("/usr/bin/clang-tidy");
+ if (clangTidyPath.isEmpty()) {
+ params.executablePath = \
QStandardPaths::findExecutable("/usr/bin/clang-tidy"); } else {
- params.executablePath = clangtidyPath;
+ params.executablePath = clangTidyPath;
}
if (allFiles) {
diff --git a/src/plugin.h.in b/src/plugin.h.in
deleted file mode 100644
index 80cfe01..0000000
--- a/src/plugin.h.in
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * This file is part of KDevelop
- *
- * Copyright 2016 Carlos Nihelton <carlosnsoliveira@gmail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-#ifndef CLANGTIDY_PLUGIN_H
-#define CLANGTIDY_PLUGIN_H
-
-#include <QPointer>
-#include <QVariant>
-
-#include <interfaces/icore.h>
-#include <interfaces/iplugin.h>
-#include <interfaces/istatus.h>
-
-#include <interfaces/contextmenuextension.h>
-#include <interfaces/iuicontroller.h>
-#include <shell/problemmodel.h>
-
-#include "config/configgroup.h"
-#include "qCDebug/debug.h"
-
-class KJob;
-
-namespace KDevelop
-{
-class ProblemModel;
-}
-
-#define CLANG_TIDY_PATH "@CLANG_TIDY_EXEC@"
-
-namespace ClangTidy
-{
-/**
- * \class
- * \brief implements the support for clang-tidy inside KDevelop by using the IPlugin \
interface.
- */
-class Plugin : public KDevelop::IPlugin
-{
- Q_OBJECT
-
-public:
- Plugin(QObject* parent, const QVariantList& = QVariantList());
- ~Plugin() = default;
- void unload() override;
- KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) \
override;
- int configPages() const override { return 1; }
- /**
- * \function
- * \return the session configuration page for clang-tidy plugin.
- */
- KDevelop::ConfigPage* configPage(int number, QWidget* parent) override;
- int perProjectConfigPages() const override { return 1; }
- /**
- * \function
- * \return the clang-tidy configuration page for the current project.
- */
- KDevelop::ConfigPage* perProjectConfigPage(int number, const \
KDevelop::ProjectConfigOptions& options,
- QWidget* parent) override;
- /**
- *\function
- *\returns all available checks, obtained from clang-tidy program, ran with with \
"--checks=* --list-checks"
- * parameters.
- */
- QStringList allAvailableChecks() { return m_allChecks; }
-protected:
- /**
- * \function
- * \brief collects all available checks by running clang-tidy with the following \
parameters: "--checks=*
- * --list-checks".
- * \param clangtidyPath QString - the system path for the clang-tidy program.
- */
- void collectAllAvailableChecks(QString clangtidyPath);
-
-private slots:
- void loadOutput();
- void runClangtidy(bool allFiles);
- void runClangtidyFile();
- void runClangtidyAll();
- void result(KJob* job);
-
-private:
- ConfigGroup m_config;
- QScopedPointer<KDevelop::ProblemModel> m_model;
- QStringList m_allChecks;
- QStringList m_activeChecks;
-};
-
-} // namespace ClangTidy
-
-#endif // CLANGTIDY_PLUGIN_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic