[gnome-builder] make: Add makefile plugin



commit 33a040968c5e794ce36bff0dd9772a7cd86d8c0d
Author: Matthew Leeds <mleeds redhat com>
Date:   Mon Mar 6 14:55:30 2017 -0600

    make: Add makefile plugin
    
    This commit adds a plugin to provide very basic support for projects
    with Makefiles but without autotools. It essentially just knows how to
    run "make", "make clean", and "make install" in the source directory,
    but doesn't know how to find build targets (so the Run button doesn't
    work).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779684

 configure.ac                         |    2 +
 plugins/Makefile.am                  |    1 +
 plugins/make/Makefile.am             |   15 ++++
 plugins/make/configure.ac            |   12 +++
 plugins/make/make.plugin             |   11 +++
 plugins/make/make_plugin/__init__.py |  127 ++++++++++++++++++++++++++++++++++
 plugins/make/meson.build             |    6 ++
 plugins/meson.build                  |    1 +
 8 files changed, 175 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c59b53e..83f8d97 100644
--- a/configure.ac
+++ b/configure.ac
@@ -315,6 +315,7 @@ m4_include([plugins/html-completion/configure.ac])
 m4_include([plugins/html-preview/configure.ac])
 m4_include([plugins/jedi/configure.ac])
 m4_include([plugins/jhbuild/configure.ac])
+m4_include([plugins/make/configure.ac])
 m4_include([plugins/meson/configure.ac])
 m4_include([plugins/meson-templates/configure.ac])
 m4_include([plugins/mingw/configure.ac])
@@ -598,6 +599,7 @@ echo "  GNOME Code Assistance ................ : ${enable_gnome_code_assistance_
 echo "  HTML Autocompletion .................. : ${enable_html_completion_plugin}"
 echo "  HTML and Markdown Preview ............ : ${enable_html_preview_plugin}"
 echo "  JHBuild .............................. : ${enable_jhbuild_plugin}"
+echo "  Make ................................. : ${enable_make_plugin}"
 echo "  Meson ................................ : ${enable_meson_plugin}"
 echo "  MinGW ................................ : ${enable_mingw_plugin}"
 echo "  Project Creation ..................... : ${enable_create_project_plugin}"
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index de3e8d6..7f5283e 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -23,6 +23,7 @@ SUBDIRS =                            \
        html-preview                 \
        jedi                         \
        jhbuild                      \
+       make                         \
        mingw                        \
        meson                        \
        meson-templates              \
diff --git a/plugins/make/Makefile.am b/plugins/make/Makefile.am
new file mode 100644
index 0000000..7fc5d10
--- /dev/null
+++ b/plugins/make/Makefile.am
@@ -0,0 +1,15 @@
+if ENABLE_MAKE_PLUGIN
+
+EXTRA_DIST = $(plugin_DATA)
+
+plugindir = $(libdir)/gnome-builder/plugins
+dist_plugin_DATA = make.plugin
+
+moduledir = $(libdir)/gnome-builder/plugins/make_plugin
+dist_module_DATA = make_plugin/__init__.py
+
+endif
+
+include $(top_srcdir)/plugins/Makefile.plugin
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/make/configure.ac b/plugins/make/configure.ac
new file mode 100644
index 0000000..df14fba
--- /dev/null
+++ b/plugins/make/configure.ac
@@ -0,0 +1,12 @@
+# --enable-make-plugin=yes/no
+AC_ARG_ENABLE([make-plugin],
+              [AS_HELP_STRING([--enable-make-plugin=@<:@yes/no@:>@],
+                              [Build with support for Makefile integration.])],
+              [enable_make_plugin=$enableval],
+              [enable_make_plugin=yes])
+
+# for if ENABLE_MAKE_PLUGIN in Makefile.am
+AM_CONDITIONAL(ENABLE_MAKE_PLUGIN, test x$enable_make_plugin = xyes)
+
+# Ensure our make is generated by autoconf
+AC_CONFIG_FILES([plugins/make/Makefile])
diff --git a/plugins/make/make.plugin b/plugins/make/make.plugin
new file mode 100644
index 0000000..b00df24
--- /dev/null
+++ b/plugins/make/make.plugin
@@ -0,0 +1,11 @@
+[Plugin]
+Module=make_plugin
+Loader=python3
+Name=Make
+Description=Provides support for Makefile projects without autotools
+Authors=Matthew Leeds <mleeds redhat com>
+Copyright=Copyright © 2017 Matthew Leeds
+Builtin=true
+Hidden=true
+X-Project-File-Filter-Pattern=Makefile
+X-Project-File-Filter-Name=Makefile Project
diff --git a/plugins/make/make_plugin/__init__.py b/plugins/make/make_plugin/__init__.py
new file mode 100644
index 0000000..79aee43
--- /dev/null
+++ b/plugins/make/make_plugin/__init__.py
@@ -0,0 +1,127 @@
+# __init__.py
+#
+# Copyright (C) 2017 Matthew Leeds <mleeds redhat 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 3 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, see <http://www.gnu.org/licenses/>.
+
+import gi
+
+gi.require_version('Ide', '1.0')
+
+from gi.repository import (
+    GObject,
+    Gio,
+    Ide
+)
+
+_ = Ide.gettext
+
+class MakeBuildSystem(Ide.Object, Ide.BuildSystem, Gio.AsyncInitable):
+    project_file = GObject.Property(type=Gio.File)
+
+    def do_init_async(self, priority, cancel, callback, data=None):
+        task = Gio.Task.new(self, cancel, callback)
+        task.set_priority(priority)
+
+        # TODO: Be async here also
+        project_file = self.get_context().get_project_file()
+        if project_file.get_basename() == 'Makefile':
+            task.return_boolean(True)
+        else:
+            child = project_file.get_child('Makefile')
+            exists = child.query_exists(cancel)
+            if exists:
+                self.props.project_file = child
+            task.return_boolean(exists)
+
+    def do_init_finish(self, result):
+        return result.propagate_boolean()
+
+    def do_get_priority(self):
+        return -400 # Lower priority than Autotools and Meson
+
+    def do_get_builddir(self, config):
+        context = self.get_context()
+        return context.get_vcs().get_working_directory().get_path()
+
+    def do_get_build_flags_async(self, ifile, cancellable, callback, data=None):
+        task = Gio.Task.new(self, cancellable, callback)
+        task.ifile = ifile
+        task.build_flags = []
+        task.return_boolean(True)
+
+    def do_get_build_flags_finish(self, result):
+        if result.propagate_boolean():
+            return result.build_flags
+
+    def do_get_build_targets_async(self, cancellable, callback, data=None):
+        task = Gio.Task.new(self, cancellable, callback)
+        task.build_targets = []
+        task.return_boolean(True)
+
+    def do_get_build_targets_finish(self, result):
+        if result.propagate_boolean():
+            return result.build_targets
+
+
+class MakePipelineAddin(Ide.Object, Ide.BuildPipelineAddin):
+    """
+    The MakePipelineAddin registers stages to be executed when various
+    phases of the build pipeline are requested.
+    """
+
+    def do_load(self, pipeline):
+        context = pipeline.get_context()
+        build_system = context.get_build_system()
+
+        # Only register stages if we are a makefile project
+        if type(build_system) != MakeBuildSystem:
+            return
+
+        config = pipeline.get_configuration()
+        runtime = config.get_runtime()
+
+        srcdir = context.get_vcs().get_working_directory().get_path()
+        builddir = build_system.get_builddir(config)
+
+        # Register the build launcher which will perform the incremental
+        # build of the project when the Ide.BuildPhase.BUILD phase is
+        # requested of the pipeline.
+        build_launcher = pipeline.create_launcher()
+        build_launcher.push_argv('make')
+        if config.props.parallelism > 0:
+            build_launcher.push_argv('-j{}'.format(config.props.parallelism))
+
+        clean_launcher = pipeline.create_launcher()
+        clean_launcher.push_argv('make')
+        clean_launcher.push_argv('clean')
+
+        build_stage = Ide.BuildStageLauncher.new(context, build_launcher)
+        build_stage.set_clean_launcher(clean_launcher)
+        build_stage.connect('query', self._query)
+        self.track(pipeline.connect(Ide.BuildPhase.BUILD, 0, build_stage))
+
+        # Register the install launcher which will perform our
+        # "make install" when the Ide.BuildPhase.INSTALL phase
+        # is requested of the pipeline.
+        install_launcher = pipeline.create_launcher()
+        install_launcher.push_argv('make')
+        install_launcher.push_argv('install')
+
+        install_stage = Ide.BuildStageLauncher.new(context, install_launcher)
+        self.track(pipeline.connect(Ide.BuildPhase.INSTALL, 0, install_stage))
+
+    def _query(self, stage, pipeline, cancellable):
+        stage.set_completed(False)
+
diff --git a/plugins/make/meson.build b/plugins/make/meson.build
new file mode 100644
index 0000000..b755959
--- /dev/null
+++ b/plugins/make/meson.build
@@ -0,0 +1,6 @@
+if get_option('with_make')
+
+install_data('make.plugin', install_dir: plugindir)
+install_data('make_plugin/__init__.py', install_dir: join_paths(plugindir, 'make_plugin'))
+
+endif
diff --git a/plugins/meson.build b/plugins/meson.build
index 85eb49f..29f3187 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -34,6 +34,7 @@ subdir('html-completion')
 subdir('html-preview')
 subdir('jedi')
 subdir('jhbuild')
+subdir('make')
 subdir('meson')
 subdir('meson-templates')
 subdir('mingw')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]