writing a gnome builder plugin
I like Gnome Builder, and I had the copious free time required to be the change I wanted to see in the world. So I looked into writing a Go plugin.
The minimum-viable plugin
A directory, in /home/hank/.local/share/gnome-builder/plugins/${plugin}
, an
empty python file, called ${plugin}.py
, and a .plugin
file, maybe
${plugin}.plugin
. Maybe something like this:
[Plugin]
Name=Go Plugin
Module=go
Loader=python3
X-Project-File-Filter-Pattern=*.go
X-Project-File-Filter-Name=Go Project
This is enough of a skeleton to convince Gnome Builder that folders with Go files constitute a Go project, and will make it easier to navigate the ‘Open Project’ dialog.
Running builds
For this, we’ll fill out ${plugin}.py
:
#!/usr/bin/env python3
import gi
from gi.repository import Ide
class BobBuildPipelineAddin(Ide.Object, Ide.BuildPipelineAddin):
def do_load(self, pipeline):
context = pipeline.get_context()
srcdir = pipeline.get_srcdir()
# Register a BUILD action, which will get run when the user hits 'build'
get_launcher = pipeline.create_launcher()
get_launcher.set_cwd(srcdir)
get_launcher.push_argv("go")
get_launcher.push_argv("build")
get_stage = Ide.BuildStageLauncher.new(context, get_launcher)
self.track(pipeline.connect(Ide.BuildPhase.BUILD, 0, get_stage))
def do_unload(self, application):
pass
def _query(self, stage, pipeline, cancellable):
stage.set_completed(False)
And that’s it- click ‘build’ in Builder, and get a build.
There are a bunch of different build phases, I haven’t done much with them,
although DOWNLOAD
seems to map well to go get
, INSTALL
with go install
,
and go generate
seems like it would map well to AUTOGEN
. The Build Phase
announcement
is sort of tantalizing.
I pieced this together from the official docs, which are good, if incomplete. The upstream plugins are also a great resource.