diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ enable_testing() +add_subdirectory(buildsystem) add_subdirectory(parser) add_subdirectory(duchain) add_subdirectory(codecompletion) diff --git a/buildsystem/CMakeLists.txt b/buildsystem/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/buildsystem/CMakeLists.txt @@ -0,0 +1,14 @@ +add_definitions(-DTRANSLATION_DOMAIN=\"buildsystem\") + +set(buildsystem_PART_SRCS + buildsystem.cpp + builder.cpp + buildjob.cpp +) + +qt5_add_resources(buildsystem_PART_SRCS buildsystem.qrc) +kdevplatform_add_plugin(gobuildsystem JSON buildsystem.json SOURCES ${buildsystem_PART_SRCS}) +target_link_libraries(gobuildsystem + KF5::KIOWidgets + KDev::Interfaces KDev::Project KDev::Util KDev::Language KDev::OutputView +) diff --git a/buildsystem/builder.h b/buildsystem/builder.h new file mode 100644 --- /dev/null +++ b/buildsystem/builder.h @@ -0,0 +1,33 @@ +/* KDevelop go build support + * + * Copyright 2017 Mikhail Ivchenko + * + * 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. + */ +#ifndef BUILDER_H +#define BUILDER_H + +#include + +namespace KDevelop { + class ProjectBaseItem; +} + +class GoBuilder: public QObject, public KDevelop::IProjectBuilder +{ + Q_OBJECT + Q_INTERFACES(KDevelop::IProjectBuilder) +public: + KJob* build(KDevelop::ProjectBaseItem *item) override; + KJob* clean(KDevelop::ProjectBaseItem *item) override; + KJob* install(KDevelop::ProjectBaseItem *item, const QUrl &installPath) override; + +private: + KJob *createJobForAction(KDevelop::ProjectBaseItem *item, const QString &action) const; +}; + +#endif // BUILDER_H + diff --git a/buildsystem/builder.cpp b/buildsystem/builder.cpp new file mode 100644 --- /dev/null +++ b/buildsystem/builder.cpp @@ -0,0 +1,43 @@ +/* KDevelop go build support + * + * Copyright 2017 Mikhail Ivchenko + * + * 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. + */ + +#include "builder.h" + +#include +#include +#include +#include + +#include "buildjob.h" + +KJob* GoBuilder::build( KDevelop::ProjectBaseItem *item ) +{ + return createJobForAction(item, QStringLiteral("build")); +} + +KJob* GoBuilder::clean( KDevelop::ProjectBaseItem *item ) +{ + return createJobForAction(item, QStringLiteral("clean")); +} + +KJob* GoBuilder::install(KDevelop::ProjectBaseItem *item, const QUrl &installPath) +{ + Q_UNUSED(installPath) + return createJobForAction(item, QStringLiteral("install")); +} + +KJob* GoBuilder::createJobForAction(KDevelop::ProjectBaseItem *item, const QString &action) const +{ + auto bsm = item->project()->buildSystemManager(); + auto buildDir = bsm->buildDirectory(item); + auto job = new GoBuildJob(nullptr, action, buildDir.toUrl()); + job->setWorkingDirectory(buildDir.toUrl()); + return job; +} diff --git a/buildsystem/buildjob.h b/buildsystem/buildjob.h new file mode 100644 --- /dev/null +++ b/buildsystem/buildjob.h @@ -0,0 +1,27 @@ +/* KDevelop go build support + * + * Copyright 2017 Mikhail Ivchenko + * + * 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. + */ + +#ifndef BUILDJOB_H +#define BUILDJOB_H + +#include + +class GoBuildJob : public KDevelop::OutputExecuteJob +{ + Q_OBJECT +public: + + GoBuildJob(QObject* parent, QString command, QUrl buildDir); + QStringList commandLine() const override; +private: + QString m_command; +}; +#endif // BUILDJOB_H + diff --git a/buildsystem/buildjob.cpp b/buildsystem/buildjob.cpp new file mode 100644 --- /dev/null +++ b/buildsystem/buildjob.cpp @@ -0,0 +1,30 @@ +/* KDevelop go build support + * + * Copyright 2017 Mikhail Ivchenko + * + * 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. + */ + +#include "buildjob.h" + +#include + +using namespace KDevelop; + +GoBuildJob::GoBuildJob(QObject* parent, QString command, QUrl buildDir) : OutputExecuteJob(parent), m_command(command) +{ + setStandardToolView(IOutputView::BuildView); + setFilteringStrategy(new CompilerFilterStrategy(buildDir.toString())); + setWorkingDirectory(buildDir); + setProperties(KDevelop::OutputExecuteJob::NeedWorkingDirectory | KDevelop::OutputExecuteJob::DisplayStderr | KDevelop::OutputExecuteJob::IsBuilderHint); +} + +QStringList GoBuildJob::commandLine() const +{ + return {"go", m_command}; +} + +#include "buildjob.moc" diff --git a/buildsystem/buildsystem.h b/buildsystem/buildsystem.h new file mode 100644 --- /dev/null +++ b/buildsystem/buildsystem.h @@ -0,0 +1,45 @@ +/* KDevelop go build support + * + * Copyright 2017 Mikhail Ivchenko + * + * 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. + */ + +#ifndef BUILDSYSTEM_H +#define BUILDSYSTEM_H + +#include +#include + +class GoBuildSystem : public KDevelop::AbstractFileManagerPlugin, + public KDevelop::IBuildSystemManager +{ + Q_OBJECT + Q_INTERFACES( KDevelop::IBuildSystemManager ) +public: + + GoBuildSystem(QObject* parent = nullptr, const QVariantList& args = QVariantList()); + + ~GoBuildSystem() override; + + Features features() const override { return Features(Folders | Targets | Files); } + KDevelop::IProjectBuilder* builder() const override; + KDevelop::Path::List includeDirectories(KDevelop::ProjectBaseItem*) const override; + KDevelop::Path::List frameworkDirectories(KDevelop::ProjectBaseItem*) const override; + QHash defines(KDevelop::ProjectBaseItem*) const override; + KDevelop::ProjectTargetItem* createTarget(const QString& target, KDevelop::ProjectFolderItem *parent) override; + bool addFilesToTarget(const QList &files, KDevelop::ProjectTargetItem *parent) override; + bool removeTarget(KDevelop::ProjectTargetItem *target) override; + bool removeFilesFromTargets(const QList&) override; + bool hasBuildInfo(KDevelop::ProjectBaseItem* item) const override; + KDevelop::Path buildDirectory(KDevelop::ProjectBaseItem*) const override; + QList targets(KDevelop::ProjectFolderItem*) const override; + KDevelop::ProjectFolderItem* createFolderItem(KDevelop::IProject * project, const KDevelop::Path & path, KDevelop::ProjectBaseItem * parent) override; + +private: + KDevelop::IProjectBuilder* m_builder; +}; +#endif // BUILDSYSTEM_H diff --git a/buildsystem/buildsystem.cpp b/buildsystem/buildsystem.cpp new file mode 100644 --- /dev/null +++ b/buildsystem/buildsystem.cpp @@ -0,0 +1,121 @@ +/* KDevelop go build support + * + * Copyright 2017 Mikhail Ivchenko + * + * 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. + */ + +#include "buildsystem.h" + +#include "builder.h" +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace KDevelop; + +K_PLUGIN_FACTORY_WITH_JSON(BuildSystemFactory, "buildsystem.json", registerPlugin(); ) + +GoBuildSystem::GoBuildSystem( QObject *parent, const QVariantList& args ) +: KDevelop::AbstractFileManagerPlugin( "gobuildsystem", parent ), m_builder(new GoBuilder()) +{ + Q_UNUSED(args) + setXMLFile( "buildsystem.rc" ); + +} + +GoBuildSystem::~GoBuildSystem() +{ +} + +IProjectBuilder* GoBuildSystem::builder() const +{ + return m_builder; +} + +Path::List GoBuildSystem::includeDirectories(KDevelop::ProjectBaseItem*) const +{ + return {}; +} + +Path::List GoBuildSystem::frameworkDirectories(KDevelop::ProjectBaseItem*) const +{ + return {}; +} + +QHash GoBuildSystem::defines(KDevelop::ProjectBaseItem*) const +{ + return {}; +} + +ProjectTargetItem* GoBuildSystem::createTarget(const QString& target, KDevelop::ProjectFolderItem *parent) +{ + Q_UNUSED(target) + Q_UNUSED(parent) + return nullptr; +} + +bool GoBuildSystem::addFilesToTarget(const QList< ProjectFileItem* > &files, ProjectTargetItem* parent) +{ + Q_UNUSED( files ) + Q_UNUSED( parent ) + return false; +} + +bool GoBuildSystem::removeTarget(KDevelop::ProjectTargetItem *target) +{ + Q_UNUSED( target ) + return false; +} + +bool GoBuildSystem::removeFilesFromTargets(const QList< ProjectFileItem* > &targetFiles) +{ + Q_UNUSED( targetFiles ) + return false; +} + +bool GoBuildSystem::hasBuildInfo(KDevelop::ProjectBaseItem* item) const +{ + Q_UNUSED(item); + return false; +} + +Path GoBuildSystem::buildDirectory(KDevelop::ProjectBaseItem* item) const +{ + auto project = item->project(); + ProjectFolderItem *folder = nullptr; + do { + folder = dynamic_cast(item); + item = item->parent(); + } while (!folder && item); + + if(folder) { + return folder->path(); + } + + return project->path(); +} + +QList GoBuildSystem::targets(KDevelop::ProjectFolderItem*) const +{ + return {}; +} + +KDevelop::ProjectFolderItem * GoBuildSystem::createFolderItem(KDevelop::IProject* project, const KDevelop::Path& path, KDevelop::ProjectBaseItem* parent) +{ + return new KDevelop::ProjectBuildFolderItem(project, path, parent); +} + + +#include "buildsystem.moc" diff --git a/buildsystem/buildsystem.json b/buildsystem/buildsystem.json new file mode 100644 --- /dev/null +++ b/buildsystem/buildsystem.json @@ -0,0 +1,28 @@ +{ + "KPlugin": { + "Category": "Project Management", + "Description": "Imports go projects", + "Icon": "kdevelop", + "Id": "KDevGoBuildSystem", + "Name": "Go Project Manager", + "ServiceTypes": [ + "KDevelop/Plugin" + ] + }, + "X-KDevelop-FileManager": "Go", + "X-KDevelop-IRequired": [ + "org.kdevelop.IMakeBuilder", + "org.kdevelop.IDefinesAndIncludesManager" + ], + "X-KDevelop-Interfaces": [ + "org.kdevelop.IBuildSystemManager", + "org.kdevelop.IProjectFileManager" + ], + "X-KDevelop-ProjectFilesFilter": [ + "*.go" + ], + "X-KDevelop-ProjectFilesFilterDescription": [ + "Go projects" + ], + "X-KDevelop-Mode": "NoGUI" +} diff --git a/buildsystem/buildsystem.qrc b/buildsystem/buildsystem.qrc new file mode 100644 --- /dev/null +++ b/buildsystem/buildsystem.qrc @@ -0,0 +1,6 @@ + + + + buildsystem.rc + + diff --git a/buildsystem/buildsystem.rc b/buildsystem/buildsystem.rc new file mode 100644 --- /dev/null +++ b/buildsystem/buildsystem.rc @@ -0,0 +1,9 @@ + + + + + Run + + + +