summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-30 14:29:39 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-30 14:29:39 +0100
commit98961cb380a78ac76a58dc61ee1aa881f730180e (patch)
treee7a05d6a6148d6eed8f967f7e31d4bfbfdc43e41 /morphlib
parente039026513a7536579d0894bdfb052e6bd560058 (diff)
downloadmorph-98961cb380a78ac76a58dc61ee1aa881f730180e.tar.gz
Add looking up of build systems by name
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/buildsystem.py28
-rw-r--r--morphlib/buildsystem_tests.py13
2 files changed, 37 insertions, 4 deletions
diff --git a/morphlib/buildsystem.py b/morphlib/buildsystem.py
index 0ac27387..9ee62d03 100644
--- a/morphlib/buildsystem.py
+++ b/morphlib/buildsystem.py
@@ -45,6 +45,8 @@ class BuildSystem(object):
class ManualBuildSystem(BuildSystem):
'''A manual build system where the morphology must specify all commands.'''
+
+ name = 'manual'
def used_by_project(self, srcdir):
return False
@@ -53,6 +55,8 @@ class ManualBuildSystem(BuildSystem):
class AutotoolsBuildSystem(BuildSystem):
'''The automake/autoconf/libtool holy trinity.'''
+
+ name = 'autotools'
def used_by_project(self, srcdir):
indicators = [
@@ -66,6 +70,12 @@ class AutotoolsBuildSystem(BuildSystem):
for x in indicators)
+build_systems = [
+ ManualBuildSystem(),
+ AutotoolsBuildSystem(),
+]
+
+
def detect_build_system(srcdir):
'''Automatically detect the build system, if possible.
@@ -74,12 +84,22 @@ def detect_build_system(srcdir):
'''
- build_systems = [
- AutotoolsBuildSystem(),
- ]
-
for bs in build_systems:
if bs.used_by_project(srcdir):
return bs
return ManualBuildSystem()
+
+
+def lookup_build_system(name):
+ '''Return build system that corresponds to the name.
+
+ If the name does not match any build system, raise ``KeyError``.
+
+ '''
+
+ for bs in build_systems:
+ if bs.name == name:
+ return bs
+ raise KeyError(name)
+
diff --git a/morphlib/buildsystem_tests.py b/morphlib/buildsystem_tests.py
index c8e9058f..362b85dd 100644
--- a/morphlib/buildsystem_tests.py
+++ b/morphlib/buildsystem_tests.py
@@ -90,3 +90,16 @@ class DetectBuildSystemTests(unittest.TestCase):
bs = morphlib.buildsystem.detect_build_system(self.tempdir)
self.assertEqual(type(bs), morphlib.buildsystem.AutotoolsBuildSystem)
+
+class LookupBuildSystemTests(unittest.TestCase):
+
+ def lookup(self, name):
+ return morphlib.buildsystem.lookup_build_system(name)
+
+ def test_raises_keyerror_for_unknown_name(self):
+ self.assertRaises(KeyError, self.lookup, 'unkonwn')
+
+ def test_looks_up_manual(self):
+ self.assertEqual(type(self.lookup('manual')),
+ morphlib.buildsystem.ManualBuildSystem)
+