From kde-commits Wed Nov 30 22:18:14 2016 From: Kevin Funk Date: Wed, 30 Nov 2016 22:18:14 +0000 To: kde-commits Subject: [kdev-clang-tidy] /: Implement runtime detection of clang-tidy Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=148054430529895 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/74da34922eebf261d6c56bd5b0708aa5446= 1b328 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 Te= xtEditor 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"> - file:///usr/bin/clang-tidy + The full path to the clang-tidy executable The full path to the clang-tidy executable. 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 @@ - - - - - file://@CLANG_TIDY_EXEC@ - - The full path to the clang-tidy executable - The full path to the clang-tidy executable. - - - diff --git a/src/config/clangtidypreferences.cpp b/src/config/clangtidypref= erences.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 =3D KSharedConfig::openConfig()->group("Clangtidy= "); - projConf.writeEntry(ConfigGroup::ExecutablePath, ui->kcfg_clangtidyPat= h->text()); + ConfigGroup configGroup =3D KSharedConfig::openConfig()->group("Clangt= idy"); + configGroup.writeEntry(ConfigGroup::ExecutablePath, ui->kcfg_clangtidy= Path->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& /*u= nused*/) pms->addModel(QStringLiteral("Clangtidy"), i18n("Clang-Tidy"), m_model= .data()); = m_config =3D KSharedConfig::openConfig()->group("Clangtidy"); - auto clangtidyPath =3D m_config.readEntry(ConfigGroup::ExecutablePath); - - // TODO(cnihelton): auto detect clang-tidy executable instead of hard-= coding - // it. - if (clangtidyPath.isEmpty()) { - clangtidyPath =3D QString(CLANG_TIDY_PATH); + auto clangTidyPath =3D m_config.readEntry(ConfigGroup::ExecutablePath); + if (clangTidyPath.isEmpty()) { + clangTidyPath =3D 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=3D*") << QLatin1String= ("--list-checks"); + tidy << clangTidyPath << QLatin1String("-checks=3D*") << QLatin1String= ("--list-checks"); tidy.setOutputChannelMode(KProcess::OnlyStdoutChannel); tidy.start(); = @@ -177,18 +174,18 @@ void Plugin::runClangtidy(bool allFiles) return; } = - auto clangtidyPath =3D m_config.readEntry(ConfigGroup::ExecutablePath); + ConfigGroup configGroup =3D KSharedConfig::openConfig()->group("Clangt= idy"); + auto clangTidyPath =3D configGroup.readEntry(ConfigGroup::ExecutablePa= th); auto buildSystem =3D project->buildSystemManager(); = Job::Parameters params; = params.projectRootDir =3D project->path().toLocalFile(); = - // TODO: auto detect clang-tidy executable instead of hard-coding it. - if (clangtidyPath.isEmpty()) { - params.executablePath =3D QStringLiteral("/usr/bin/clang-tidy"); + if (clangTidyPath.isEmpty()) { + params.executablePath =3D QStandardPaths::findExecutable("/usr/bin= /clang-tidy"); } else { - params.executablePath =3D clangtidyPath; + params.executablePath =3D 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 - * - * 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 -#include - -#include -#include -#include - -#include -#include -#include - -#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 t= he IPlugin interface. - */ -class Plugin : public KDevelop::IPlugin -{ - Q_OBJECT - -public: - Plugin(QObject* parent, const QVariantList& =3D QVariantList()); - ~Plugin() =3D 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=3D* --list-checks" - * parameters. - */ - QStringList allAvailableChecks() { return m_allChecks; } -protected: - /** - * \function - * \brief collects all available checks by running clang-tidy with the= following parameters: "--checks=3D* - * --list-checks". - * \param clangtidyPath QString - the system path for the clang-tidy p= rogram. - */ - 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 m_model; - QStringList m_allChecks; - QStringList m_activeChecks; -}; - -} // namespace ClangTidy - -#endif // CLANGTIDY_PLUGIN_H