# HG changeset patch # User osimons # Date 1249091774 0 # Node ID 294641e84e892ea5893db196137b269e700abf9e # Parent 610a97f7e1bad47b378b24f5423809e32039f461 0.6dev: Adding `${name}` and `${basedir}` (#325) for recipe substitution. Updated docs + new test. diff --git a/bitten/master.py b/bitten/master.py --- a/bitten/master.py +++ b/bitten/master.py @@ -189,6 +189,7 @@ xml.attr['build'] = str(build.id) target_platform = TargetPlatform.fetch(self.env, build.platform) xml.attr['platform'] = target_platform.name + xml.attr['name'] = build.slave body = str(xml) self.log.info('Build slave %r initiated build %d', build.slave, diff --git a/bitten/recipe.py b/bitten/recipe.py --- a/bitten/recipe.py +++ b/bitten/recipe.py @@ -56,6 +56,7 @@ self.output = [] self.basedir = os.path.realpath(self.config.interpolate(basedir, **self.vars)) + self.vars['basedir'] = self.basedir def run(self, step, namespace, name, attr): """Run the specified recipe command. diff --git a/bitten/tests/recipe.py b/bitten/tests/recipe.py --- a/bitten/tests/recipe.py +++ b/bitten/tests/recipe.py @@ -13,10 +13,27 @@ import tempfile import unittest -from bitten.recipe import Recipe, InvalidRecipeError +from bitten.build.config import Configuration +from bitten.recipe import Context, Recipe, InvalidRecipeError from bitten.util import xmlio +class ContextTestCase(unittest.TestCase): + + def setUp(self): + self.basedir = os.path.realpath(tempfile.mkdtemp()) + + def tearDown(self): + shutil.rmtree(self.basedir) + + def test_vars_basedir(self): + config = Configuration(properties={'foo.bar': 'baz'}) + ctxt = Context('/foo/${path}/${foo.bar}', config, + {'path': 'bar'}) + + self.assertEquals('/foo/bar/baz', ctxt.vars['basedir']) + + class RecipeTestCase(unittest.TestCase): def setUp(self): @@ -102,7 +119,10 @@ recipe.validate() def suite(): - return unittest.makeSuite(RecipeTestCase, 'test') + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(ContextTestCase, 'test')) + suite.addTest(unittest.makeSuite(RecipeTestCase, 'test')) + return suite if __name__ == '__main__': unittest.main(defaultTest='suite') diff --git a/doc/configure.txt b/doc/configure.txt --- a/doc/configure.txt +++ b/doc/configure.txt @@ -131,6 +131,9 @@ version = 2.3.5 path = /usr/bin/python2.3 +*Note:* Options called ``name`` is not allowed in custom sections (will +be skipped). + The build slave sends this package information as part of the build initiation, which when using verbose logging (``bitten-slave -v``) will display a debug message 'Sending slave configuration:' followed by: diff --git a/doc/recipes.txt b/doc/recipes.txt --- a/doc/recipes.txt +++ b/doc/recipes.txt @@ -36,9 +36,9 @@ these elements are declared in XML namespaces, where the namespace URI defines a collection of related commands. -A `````element can additionally have a ``onerror`` attribute with possible -values of ``fail`` (terminate after step, default behaviour), or ``continue`` -(fail, but run next step), or ``ignore`` (errors are unimportant, continue). +A ```` element can additionally have an ``onerror`` attribute with +value of ``fail`` (terminate after step, default behaviour) or ``ignore`` +(fail, but run next step). Commonly, the first step of any build recipe will perform the checkout from the repository. @@ -75,7 +75,7 @@ `Slave Configuration`_ further custom properties can be used. Bitten supports these pre-defined properties: -.. _`slave configuration`: slaveconfig.html +.. _`slave configuration`: configure.html +-----------------+----------------------------------------------------------+ | Constant | Value | @@ -88,6 +88,13 @@ +-----------------+----------------------------------------------------------+ | ``${revision}`` | The repository revision being tested | +-----------------+----------------------------------------------------------+ +| ``${platform}`` | The name of the target platform being built | ++-----------------+----------------------------------------------------------+ +| ``${name}`` | The name of the build slave | ++-----------------+----------------------------------------------------------+ +| ``${basedir}`` | The absolute path of the build location, joining | +| | ``work-dir`` (absolute) with ``build-dir`` (relative) | ++-----------------+----------------------------------------------------------+ As the recipe needs to be valid XML, any reserved characters in attributes must be quoted using regular XML entities: