Skip to content

Commit

Permalink
Add a simple example of a custom plugin to the documentation
Browse files Browse the repository at this point in the history
Provide a simple but complete example of a custom step plugin not doing
anything more than defining a property.
  • Loading branch information
vadz committed Nov 16, 2015
1 parent 8ca5ef5 commit 2b916e9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 51 additions & 1 deletion docs/devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,58 @@ Extending and developing Bakefile
Writing Bakefile plugins
------------------------

.. TODO
As mentioned in :ref:`loading_plugins`, it is possible to use plugins written
in Python to extend Bakefile functionality. The most common types of plugins
are those defining custom tool sets, i.e. new output formats, or custom build
steps, allowing to perform more or less arbitrary actions.

But the simplest possible custom step plugin may actually not do anything at
all, but just define some properties that can be used in bakefiles. For
example, here is a complete example of a plugin:

.. code-block:: py
from bkl.api import CustomStep, Property
from bkl.vartypes import StringType
from datetime import date
class MyVersion(CustomStep):
"""
Simple bakefile plugin defining MY_VERSION property.
The value of the version is just the current date.
"""
name = "my_version"
properties_project = [
Property("MY_VERSION",
type=StringType(),
default=data.today().isoformat(),
inheritable=False,
readonly=True),
]
This plugin can then be used in the following way:

.. code-block:: bkl
plugin bkl.plugins.my_version.py;
program my_program {
basename = my_program-$(MY_VERSION);
...
}
Of course, a more realistic example would use something other than just the
date of the last Bakefile execution as version. As plugin is just a normal
Python script, there are a lot of possibilities, for example it could extract
the version from the VCS used by the program or read it from some file inside
the source tree.

.. TODO provide an example of implementing generate() in a custom step
.. TODO explain what other plugin types can be used for
Reference
---------
Expand Down
2 changes: 2 additions & 0 deletions docs/language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ specified one.



.. _loading_plugins:

Loading plugins
---------------

Expand Down

0 comments on commit 2b916e9

Please sign in to comment.