summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2014-08-08 07:59:02 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2014-08-08 15:22:50 +0000
commit552420219dd9275c15cf25b31e0b8355b4a72f6e (patch)
treef35a4b9c3ff6a8237233c2b765942a892481f7e5
parent2fbc0825bf6d716003f602fd1c410f2d02b27576 (diff)
downloadmorph-552420219dd9275c15cf25b31e0b8355b4a72f6e.tar.gz
morph3: Add a get_commands method to Morphology
morph2.Morphology has a `get_commands` method which is used to return the [configure|build|install]-commands of the chunk, either by getting them from the chunk morphology or from the build system of the chunk. This commit implements a similar method in morph3.Morphology and adds tests for it, so that when we remove morph2 the API changes to morphologies are minimal.
-rw-r--r--morphlib/morph3.py12
-rw-r--r--morphlib/morph3_tests.py36
2 files changed, 46 insertions, 2 deletions
diff --git a/morphlib/morph3.py b/morphlib/morph3.py
index 477cac1a..a91ff390 100644
--- a/morphlib/morph3.py
+++ b/morphlib/morph3.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Codethink Limited
+# Copyright (C) 2013-2014 Codethink Limited
#
# 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
@@ -18,6 +18,8 @@
import UserDict
+import morphlib
+
class Morphology(UserDict.IterableUserDict):
@@ -43,3 +45,11 @@ class Morphology(UserDict.IterableUserDict):
self.filename = None
self.dirty = None
+ def get_commands(self, which):
+ '''Return the commands to run from a morphology or the build system'''
+ if self.get(which, None) is None:
+ attr = '_'.join(which.split('-'))
+ bs = morphlib.buildsystem.lookup_build_system(self['build-system'])
+ return getattr(bs, attr)
+ else:
+ return self[which]
diff --git a/morphlib/morph3_tests.py b/morphlib/morph3_tests.py
index e150bf33..51b70597 100644
--- a/morphlib/morph3_tests.py
+++ b/morphlib/morph3_tests.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Codethink Limited
+# Copyright (C) 2013-2014 Codethink Limited
#
# 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
@@ -46,3 +46,37 @@ class MorphologyTests(unittest.TestCase):
self.morph.dirty = True
self.assertEqual(self.morph.dirty, True)
+ def test_uses_morphology_commands_when_given(self):
+ m = morphlib.morph3.Morphology(
+ {
+ 'name': 'foo',
+ 'kind': 'chunk',
+ 'build-system': 'dummy',
+ 'build-commands': ['build-it']
+ }
+ )
+ cmds = m.get_commands('build-commands')
+ self.assertEqual(cmds, ['build-it'])
+
+ def test_uses_build_system_commands_when_morphology_doesnt(self):
+ m = morphlib.morph3.Morphology(
+ {
+ 'name': 'foo',
+ 'kind': 'chunk',
+ 'build-system': 'dummy',
+ }
+ )
+ cmds = m.get_commands('build-commands')
+ self.assertEqual(cmds, ['echo dummy build'])
+
+ def test_uses_morphology_commands_when_morphology_has_empty_list(self):
+ m = morphlib.morph3.Morphology(
+ {
+ 'name': 'foo',
+ 'kind': 'chunk',
+ 'build-system': 'dummy',
+ 'build-commands': []
+ }
+ )
+ cmds = m.get_commands('build-commands')
+ self.assertEqual(cmds, [])