diff --git a/plugins/meson/CMakeLists.txt b/plugins/meson/CMakeLists.txt index 51c14ab09c..e97c10419f 100644 --- a/plugins/meson/CMakeLists.txt +++ b/plugins/meson/CMakeLists.txt @@ -1,55 +1,54 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kdevmesonmanager\") set(mesonbuilder_SRCS mesonbuilder.cpp mesonconfig.cpp mesonintrospectjob.cpp - mesonimportjob.cpp mesonjob.cpp mesonjobprune.cpp mesonmanager.cpp mesonoptions.cpp mesontargets.cpp settings/mesonadvancedsettings.cpp settings/mesonconfigpage.cpp settings/mesonlisteditor.cpp settings/mesonnewbuilddir.cpp settings/mesonoptionbaseview.cpp settings/mesonoptionsview.cpp ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) ki18n_wrap_ui(mesonbuilder_SRCS settings/mesonadvancedsettings.ui settings/mesonconfigpage.ui settings/mesonlisteditor.ui settings/mesonnewbuilddir.ui settings/mesonoptionbaseview.ui settings/mesonoptionsview.ui ) ecm_qt_declare_logging_category(mesonbuilder_SRCS HEADER debug.h IDENTIFIER KDEV_Meson CATEGORY_NAME "kdevelop.plugins.meson" ) kdevplatform_add_plugin(kdevmesonmanager JSON kdevmesonmanager.json SOURCES ${mesonbuilder_SRCS}) add_subdirectory(icons) target_link_libraries(kdevmesonmanager Qt5::Concurrent KDev::Interfaces KDev::Project KDev::Util KDev::OutputView ) set_target_properties(kdevmesonmanager PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES ) diff --git a/plugins/meson/mesonimportjob.cpp b/plugins/meson/mesonimportjob.cpp deleted file mode 100644 index 264d478778..0000000000 --- a/plugins/meson/mesonimportjob.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* This file is part of KDevelop - Copyright 2017 Aleix Pol Gonzalez - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "mesonimportjob.h" -#include "mesonconfig.h" -#include "mesonmanager.h" -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace KDevelop; - -MesonImportJob::MesonImportJob(MesonManager* manager, KDevelop::IProject* project, QObject* parent) - : KJob(parent) - , m_project(project) - , m_manager(manager) -{ - connect(&m_futureWatcher, &QFutureWatcher::finished, this, &MesonImportJob::importFinished); -} - -// TODO: probably want to process the object in this function (e.g. see CMakeImportJsonJob) -QJsonObject import() -{ - qCDebug(KDEV_Meson) << "import(): This is a stub."; - return QJsonObject(); -} - -void MesonImportJob::start() -{ - Meson::BuildDir buildDir = Meson::currentBuildDir(m_project); - if (!buildDir.isValid()) { - qCWarning(KDEV_Meson) << "The current build directory is invalid"; - setError(true); - setErrorText(i18n("The current build directory for %1 is invalid").arg(m_project->name())); - emitResult(); - return; - } - - auto future = QtConcurrent::run(import); - m_futureWatcher.setFuture(future); -} - -void MesonImportJob::importFinished() -{ - auto future = m_futureWatcher.future(); - auto data = future.result(); - m_manager->setProjectData(m_project, data); - emitResult(); -} - -bool MesonImportJob::doKill() -{ - if (m_futureWatcher.isRunning()) { - m_futureWatcher.cancel(); - } - return true; -} diff --git a/plugins/meson/mesonimportjob.h b/plugins/meson/mesonimportjob.h deleted file mode 100644 index 7000681cc9..0000000000 --- a/plugins/meson/mesonimportjob.h +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of KDevelop - Copyright 2017 Aleix Pol Gonzalez - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef MESONIMPORTJOB_H -#define MESONIMPORTJOB_H - -#include -#include -#include -#include - -class MesonManager; - -class MesonImportJob : public KJob -{ - Q_OBJECT - -public: - MesonImportJob(MesonManager* manager, KDevelop::IProject* project, QObject* parent); - - void start() override; - bool doKill() override; - -private: - void importFinished(); - - KDevelop::IProject* m_project; - QFutureWatcher m_futureWatcher; - MesonManager* m_manager; -}; - -#endif // MESONIMPORTJOB_H diff --git a/plugins/meson/mesonmanager.cpp b/plugins/meson/mesonmanager.cpp index 7e537199ab..858634bea2 100644 --- a/plugins/meson/mesonmanager.cpp +++ b/plugins/meson/mesonmanager.cpp @@ -1,189 +1,174 @@ /* This file is part of KDevelop Copyright 2017 Aleix Pol Gonzalez Copyright 2018 Daniel Mensinger This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mesonmanager.h" #include "mesonbuilder.h" #include "mesonconfig.h" -#include "mesonimportjob.h" #include "settings/mesonconfigpage.h" #include "settings/mesonnewbuilddir.h" #include #include #include #include #include #include #include #include #include #include "debug.h" using namespace KDevelop; static const QString GENERATOR_NINJA = QStringLiteral("ninja"); K_PLUGIN_FACTORY_WITH_JSON(MesonSupportFactory, "kdevmesonmanager.json", registerPlugin();) MesonManager::MesonManager(QObject* parent, const QVariantList& args) : AbstractFileManagerPlugin(QStringLiteral("KDevMesonManager"), parent, args) , m_builder(new MesonBuilder(this)) { if (m_builder->hasError()) { setErrorDescription(i18n("Meson builder error: %1", m_builder->errorDescription())); } } MesonManager::~MesonManager() { delete m_builder; } // ********************************* // * AbstractFileManagerPlugin API * // ********************************* IProjectFileManager::Features MesonManager::features() const { return IProjectFileManager::Files | IProjectFileManager::Folders | IProjectFileManager::Targets; } ProjectFolderItem* MesonManager::createFolderItem(IProject* project, const Path& path, ProjectBaseItem* parent) { // TODO: Maybe use meson targets instead if (QFile::exists(path.toLocalFile() + QStringLiteral("/meson.build"))) return new ProjectBuildFolderItem(project, path, parent); else return AbstractFileManagerPlugin::createFolderItem(project, path, parent); } // *************************** // * IBuildSystemManager API * // *************************** KJob* MesonManager::createImportJob(ProjectFolderItem* item) { auto project = item->project(); - auto job = new MesonImportJob(this, project, this); - - connect(job, &KJob::result, this, [this, job, project]() { - if (job->error() != 0) { - qCWarning(KDEV_Meson) << "couldn't load project successfully" << project->name(); - m_projects.remove(project); - } - }); const QList jobs = { builder()->configure(project), // Make sure the project is configured - job, // Import the compile_commands.json file AbstractFileManagerPlugin::createImportJob(item) // generate the file system listing }; Q_ASSERT(!jobs.contains(nullptr)); auto composite = new ExecuteCompositeJob(this, jobs); composite->setAbortOnError(false); return composite; } Path MesonManager::buildDirectory(ProjectBaseItem* item) const { Q_ASSERT(item); Meson::BuildDir buildDir = Meson::currentBuildDir(item->project()); return buildDir.buildDir; } IProjectBuilder* MesonManager::builder() const { return m_builder; } KJob *MesonManager::newBuildDirectory(IProject* project) { Q_ASSERT(project); MesonNewBuildDir newBD(project); if (!newBD.exec() || !newBD.isConfigValid()) { qCWarning(KDEV_Meson) << "Failed to create new build directory for project " << project->name(); return nullptr; } Meson::BuildDir buildDir = newBD.currentConfig(); Meson::MesonConfig mesonCfg = Meson::getMesonConfig(project); buildDir.canonicalizePaths(); mesonCfg.currentIndex = mesonCfg.addBuildDir(buildDir); Meson::writeMesonConfig(project, mesonCfg); return m_builder->configure(project, buildDir, newBD.mesonArgs()); } QStringList MesonManager::supportedMesonBackends() const { // Maybe add support for other generators return { GENERATOR_NINJA }; } QString MesonManager::defaultMesonBackend() const { return GENERATOR_NINJA; } Path MesonManager::findMeson() const { QString mesonPath; const static QStringList mesonExecutables = { QStringLiteral("meson"), QStringLiteral("meson.py") }; const static QStringList mesonPaths = { QStringLiteral("%1/.local/bin").arg(QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]) }; for (auto const& i : mesonExecutables) { mesonPath = QStandardPaths::findExecutable(i); if (!mesonPath.isEmpty()) { break; } mesonPath = QStandardPaths::findExecutable(i, mesonPaths); if (!mesonPath.isEmpty()) { break; } } return Path(mesonPath); } -void MesonManager::setProjectData(IProject* project, const QJsonObject& data) -{ - m_projects[project] = data; -} - ConfigPage* MesonManager::perProjectConfigPage(int number, const ProjectConfigOptions& options, QWidget* parent) { if (number == 0) { return new MesonConfigPage(this, options.project, parent); } return nullptr; } int MesonManager::perProjectConfigPages() const { return 1; } #include "mesonmanager.moc" diff --git a/plugins/meson/mesonmanager.h b/plugins/meson/mesonmanager.h index 4b3f71867f..f3cc4f9f78 100644 --- a/plugins/meson/mesonmanager.h +++ b/plugins/meson/mesonmanager.h @@ -1,112 +1,109 @@ /* This file is part of KDevelop Copyright 2017 Aleix Pol Gonzalez Copyright 2018 Daniel Mensinger This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_PLUGIN_MESONMANAGER_H #define KDEVPLATFORM_PLUGIN_MESONMANAGER_H #include "mesonconfig.h" #include #include class MesonBuilder; class MesonManager : public KDevelop::AbstractFileManagerPlugin, public KDevelop::IBuildSystemManager { Q_OBJECT Q_INTERFACES(KDevelop::IBuildSystemManager) public: explicit MesonManager(QObject* parent = nullptr, const QVariantList& args = QVariantList()); ~MesonManager() override; // ******************** // * Custom functions * // ******************** /** * Create a new build directory and write it into the config. * @returns The configuration job on success or nullptr on error. */ KJob *newBuildDirectory(KDevelop::IProject* project); /// Returns a list of all supported Meson backends (for now only ninja) QStringList supportedMesonBackends() const; QString defaultMesonBackend() const; KDevelop::Path findMeson() const; - void setProjectData(KDevelop::IProject* project, const QJsonObject& data); - // ********************************* // * AbstractFileManagerPlugin API * // ********************************* KDevelop::IProjectFileManager::Features features() const override; KDevelop::ProjectFolderItem* createFolderItem(KDevelop::IProject* project, const KDevelop::Path& path, KDevelop::ProjectBaseItem* parent = nullptr) override; // *********** // * IPlugin * // *********** KDevelop::ConfigPage* perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, QWidget* parent) override; int perProjectConfigPages() const override; // *************************** // * IBuildSystemManager API * // *************************** KJob* createImportJob(KDevelop::ProjectFolderItem* item) override; KDevelop::IProjectBuilder* builder() const override; // FIXME now: should use compile_commands.json for these (i.e. m_projects) KDevelop::Path::List includeDirectories(KDevelop::ProjectBaseItem*) const override { return {}; } KDevelop::Path::List frameworkDirectories(KDevelop::ProjectBaseItem*) const override { return {}; } QHash defines(KDevelop::ProjectBaseItem*) const override { return {}; } QString extraArguments(KDevelop::ProjectBaseItem* /*item*/) const override { return {}; } bool hasBuildInfo(KDevelop::ProjectBaseItem* /*item*/) const override { return false; } KDevelop::Path buildDirectory(KDevelop::ProjectBaseItem*) const override; // fill if&when we have targets QList targets(KDevelop::ProjectFolderItem*) const override { return {}; } // you can ignore these for now I guess, but TODO KDevelop::ProjectTargetItem* createTarget(const QString& /*target*/, KDevelop::ProjectFolderItem* /*parent*/) override { return nullptr; } bool removeTarget(KDevelop::ProjectTargetItem* /*target*/) override { return false; } bool addFilesToTarget(const QList& /*files*/, KDevelop::ProjectTargetItem* /*target*/) override { return false; } bool removeFilesFromTargets(const QList& /*files*/) override { return false; } private: MesonBuilder* m_builder; - QHash m_projects; }; #endif