[kdevelop/frameworks] projectmanagers/cmake: New approach for the cmake plugin

Aleix Pol aleixpol at kde.org
Tue Aug 5 23:37:20 UTC 2014


Git commit d22ca0e936a6acd29e9f31a1eaef636006068ec7 by Aleix Pol.
Committed on 05/08/2014 at 23:30.
Pushed by apol into branch 'frameworks'.

New approach for the cmake plugin

So far we were executing the whole project to figure out the cmake
projects information. This worked really well on one hand, but then
it was high maintainance and error prone.
What this plugin does is to use the generated compile_commands.json
file to populate the include directories and defines, therefore
making the analysis unneeded.

That's not entirely true though, we'll still want to keep analyzing
the files to provide the rest of the information we have to offer
(and that currently is not available with the commtted version of
the plugin) but now we can do it after loading the project, without
rush and following the parsing information in KDevelop, treating
cmake more like a language additionally to as a project.

CCMAIL: kdevelop-devel at kde.org

M  +1    -1    projectmanagers/cmake/CMakeLists.txt
M  +11   -8    projectmanagers/cmake/cmakemanager.cpp
M  +1    -1    projectmanagers/cmake/cmakeprojectdata.h

http://commits.kde.org/kdevelop/d22ca0e936a6acd29e9f31a1eaef636006068ec7

diff --git a/projectmanagers/cmake/CMakeLists.txt b/projectmanagers/cmake/CMakeLists.txt
index adb5aee..ea97c03 100644
--- a/projectmanagers/cmake/CMakeLists.txt
+++ b/projectmanagers/cmake/CMakeLists.txt
@@ -81,7 +81,7 @@ target_link_libraries( kdev4cmakecommon LINK_PRIVATE ${KDE4_KDEUI_LIBS}
                         )
 
 qt5_wrap_ui( cmakemanager_SRCS ${cmakemanager_UI} )
-add_library(kdevcmakemanager MODULE ${cmakemanager_SRCS} ../../languages/cpp/makefileresolver.cpp)
+add_library(kdevcmakemanager MODULE ${cmakemanager_SRCS} ../custommake/makefileresolver/makefileresolver.cpp)
 target_link_libraries( kdevcmakemanager ${KDE4_KDEUI_LIBS} KF5::KIOWidgets ${KDEVPLATFORM_UTIL_LIBRARIES}
                         ${KDEVPLATFORM_INTERFACES_LIBRARIES} kdev4cmakecommon
                         ${KDEVPLATFORM_PROJECT_LIBRARIES} ${KDEVPLATFORM_LANGUAGE_LIBRARIES}
diff --git a/projectmanagers/cmake/cmakemanager.cpp b/projectmanagers/cmake/cmakemanager.cpp
index f243df5..c884ef8 100644
--- a/projectmanagers/cmake/cmakemanager.cpp
+++ b/projectmanagers/cmake/cmakemanager.cpp
@@ -23,12 +23,13 @@
 #include "cmakeedit.h"
 #include "cmakeutils.h"
 #include "cmakeprojectdata.h"
-#include <languages/cpp/makefileresolver.h>
+#include <projectmanagers/custommake/makefileresolver/makefileresolver.h>
 
 #include <QDir>
 #include <QThread>
 #include <QFileSystemWatcher>
 #include <QTimer>
+#include <qjsondocument.h>
 #include <qjson/parser.h>
 
 #include <KPluginFactory>
@@ -71,7 +72,7 @@ K_PLUGIN_FACTORY(CMakeSupportFactory, registerPlugin<CMakeManager>(); )
 const QString DIALOG_CAPTION = i18n("KDevelop - CMake Support");
 
 CMakeManager::CMakeManager( QObject* parent, const QVariantList& )
-    : KDevelop::AbstractFileManagerPlugin( CMakeSupportFactory::componentData(), parent )
+    : KDevelop::AbstractFileManagerPlugin( "cmakemanager", parent )
     , m_filter( new ProjectFilterManager( this ) )
 {
     KDEV_USE_EXTENSION_INTERFACE( KDevelop::IBuildSystemManager )
@@ -726,11 +727,11 @@ ProjectFilterManager* CMakeManager::filterManager() const
 
 CMakeFile dataFromJson(const QVariantMap& entry)
 {
-    CppTools::MakeFileResolver resolver;
-    CppTools::PathResolutionResult result = resolver.processOutput(entry["command"].toString(), entry["directory"].toString());
+    MakeFileResolver resolver;
+    PathResolutionResult result = resolver.processOutput(entry["command"].toString(), entry["directory"].toString());
 
     CMakeFile ret;
-    ret.includes = KDevelop::toPathList(result.paths);
+    ret.includes = KDevelop::toPathList(QUrl::fromStringList(result.paths));
     return ret;
 }
 
@@ -757,7 +758,7 @@ void CMakeManager::initializeProject(IProject* project)
 
     Path commandsFile(CMake::currentBuildDir(project));
     commandsFile.addPath("compile_commands.json");
-    QJson::Parser parser;
+
     QFile f(commandsFile.toLocalFile());
     bool r = f.open(QFile::ReadOnly|QFile::Text);
     if(!r) {
@@ -768,8 +769,10 @@ void CMakeManager::initializeProject(IProject* project)
     }
     qDebug() << "found commands file" << commandsFile;
 
-    QVariantList values = parser.parse(&f, &r).toList();
-    Q_ASSERT(r);
+    QJsonDocument parser;
+    QJsonParseError error;
+    QVariantList values = parser.fromJson(f.readAll(), &error).toVariant().toList();
+    Q_ASSERT(error.error == QJsonParseError::NoError);
 
     foreach(const QVariant& v, values) {
         QVariantMap entry = v.toMap();
diff --git a/projectmanagers/cmake/cmakeprojectdata.h b/projectmanagers/cmake/cmakeprojectdata.h
index 60c7b79..40b6b4d 100644
--- a/projectmanagers/cmake/cmakeprojectdata.h
+++ b/projectmanagers/cmake/cmakeprojectdata.h
@@ -4,7 +4,7 @@
 #include <QStringList>
 #include <QFileSystemWatcher>
 #include "cmaketypes.h"
-#include <project/path.h>
+#include <util/path.h>
 
 /**
  * Represents any file in a cmake project that has been added


More information about the KDevelop-devel mailing list