[gnome-builder] waf: add initial support for waf build system



commit 56bdcf9faa88934229a5f6f56f9285f799da4038
Author: Christian Hergert <chergert redhat com>
Date:   Thu Feb 21 12:09:41 2019 -0800

    waf: add initial support for waf build system
    
    This does the minimal build pipeline setup and is provided by
    Alex Mitchell. It is modified to also try to sniff the requested
    python version from the waf file.
    
    We still need to add support for locating build configuration flags
    based on the compilation database (when supported).

 meson_options.txt             |   1 +
 src/plugins/meson.build       |   2 +
 src/plugins/waf/meson.build   |  13 +++++
 src/plugins/waf/waf.plugin    |  11 ++++
 src/plugins/waf/waf_plugin.py | 115 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 142 insertions(+)
---
diff --git a/meson_options.txt b/meson_options.txt
index 0b5e487d3..3028c49bb 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -70,5 +70,6 @@ option('plugin_sysroot', type: 'boolean')
 option('plugin_todo', type: 'boolean')
 option('plugin_vala', type: 'boolean')
 option('plugin_valgrind', type: 'boolean')
+option('plugin_waf', type: 'boolean')
 option('plugin_words', type: 'boolean')
 option('plugin_xml_pack', type: 'boolean')
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 66f787d14..217f8e3f6 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -118,6 +118,7 @@ subdir('trim-spaces')
 subdir('valgrind')
 subdir('vcsui')
 subdir('vim')
+subdir('waf')
 subdir('words')
 subdir('xml-pack')
 
@@ -181,6 +182,7 @@ status += [
   'Todo .................. : @0@'.format(get_option('plugin_todo')),
   'Vala Pack ............. : @0@'.format(get_option('plugin_vala')),
   'Valgrind .............. : @0@'.format(get_option('plugin_valgrind')),
+  'Waf ................... : @0@'.format(get_option('plugin_waf')),
   'Word Completion ....... : @0@'.format(get_option('plugin_words')),
   'XML Pack .............. : @0@'.format(get_option('plugin_xml_pack')),
   '',
diff --git a/src/plugins/waf/meson.build b/src/plugins/waf/meson.build
new file mode 100644
index 000000000..de81df877
--- /dev/null
+++ b/src/plugins/waf/meson.build
@@ -0,0 +1,13 @@
+if get_option('plugin_waf')
+
+install_data('waf_plugin.py', install_dir: plugindir)
+
+configure_file(
+          input: 'waf.plugin',
+         output: 'waf.plugin',
+  configuration: config_h,
+        install: true,
+    install_dir: plugindir,
+)
+
+endif
diff --git a/src/plugins/waf/waf.plugin b/src/plugins/waf/waf.plugin
new file mode 100644
index 000000000..dda0e0d08
--- /dev/null
+++ b/src/plugins/waf/waf.plugin
@@ -0,0 +1,11 @@
+[Plugin]
+Authors=Alex Mitchel, Christian Hergert
+Copyright=Copyright 2019 Alex Mitchell, 2019 Christian Hergert
+Description=Provides integration with the Waf build system
+Hidden=true
+Loader=python3
+Module=waf_plugin
+Name=Waf
+X-Project-File-Filter-Name=Waf (waf)
+X-Project-File-Filter-Pattern=waf
+X-Builder-ABI=@PACKAGE_ABI@
diff --git a/src/plugins/waf/waf_plugin.py b/src/plugins/waf/waf_plugin.py
new file mode 100644
index 000000000..80fd1dbea
--- /dev/null
+++ b/src/plugins/waf/waf_plugin.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env-python3
+
+#
+# waf_plugin.py
+#
+# Copyright 2019 Alex Mitchell
+# Copyright 2019 Christian Hergert <chergert 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 os
+
+from gi.repository import Gio
+from gi.repository import GLib
+from gi.repository import Ide
+from gi.repository import GObject
+
+_ = Ide.gettext
+
+def sniff_python_version(path):
+    """
+    Use python3 if specified, otherwise python2.
+    """
+    try:
+        f = open(path, 'r')
+        line = f.readline()
+        if 'python3' in line:
+            return 'python3'
+    except:
+        pass
+    return 'python2'
+
+class WafBuildSystemDiscovery(Ide.SimpleBuildSystemDiscovery):
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.props.glob = 'waf'
+        self.props.hint = 'waf_plugin'
+        self.props.priority = 1000
+
+class WafBuildSystem(Ide.Object, Ide.BuildSystem):
+    project_file = GObject.Property(type=Gio.File)
+
+    def do_get_id(self):
+        return 'waf'
+
+    def do_get_display_name(self):
+        return 'Waf'
+
+    def do_get_priority(self):
+        return 1000
+
+class WafPipelineAddin(Ide.Object, Ide.PipelineAddin):
+    """
+    The WafPipelineAddin is responsible for creating the necessary build
+    stages and attaching them to phases of the build pipeline.
+    """
+
+    def do_load(self, pipeline):
+        context = self.get_context()
+        build_system = Ide.BuildSystem.from_context(context)
+        srcdir = pipeline.get_srcdir()
+
+        # Ignore pipeline unless this is a waf project
+        if type(build_system) != WafBuildSystem:
+            return
+
+        # Sniff the required python version
+        waf = os.path.join(srcdir, 'waf')
+        python = sniff_python_version(waf)
+
+        # Launcher for project configuration
+        config_launcher = pipeline.create_launcher()
+        config_launcher.set_cwd(srcdir)
+        config_launcher.push_argv(python)
+        config_launcher.push_argv('waf')
+        config_launcher.push_argv('configure')
+        self.track(pipeline.attach_launcher(Ide.PipelinePhase.CONFIGURE, 0, config_launcher))
+
+        # Now create our launcher to build the project
+        build_launcher = pipeline.create_launcher()
+        build_launcher.set_cwd(srcdir)
+        build_launcher.push_argv(python)
+        build_launcher.push_argv('waf')
+
+        clean_launcher = pipeline.create_launcher()
+        clean_launcher.set_cwd(srcdir)
+        clean_launcher.push_argv(python)
+        clean_launcher.push_argv('waf')
+        clean_launcher.push_argv('clean')
+
+        build_stage = Ide.PipelineStageLauncher.new(context, build_launcher)
+        build_stage.set_name(_("Building project"))
+        build_stage.set_clean_launcher(clean_launcher)
+        build_stage.connect('query', self._query)
+        self.track(pipeline.attach(Ide.PipelinePhase.BUILD, 0, build_stage))
+
+    def do_unload(self, application):
+        pass
+
+    def _query(self, stage, pipeline, targets, cancellable):
+        # Defer to waf to determine if building is necessary
+        stage.set_completed(False)
+


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