summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-30 14:18:59 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-30 14:18:59 +0100
commit9579486fadb5af77ecfc8df9dd1e9e814d958bef (patch)
treed36fd4b393f225dcb4a3b6dd64f7fbc44a89b945
parent907ced8460dee3763c5890a69f9d5e126621041e (diff)
downloadmorph-9579486fadb5af77ecfc8df9dd1e9e814d958bef.tar.gz
Add autodetection for autotools, and a factory function
-rw-r--r--morphlib/buildsystem.py33
-rw-r--r--morphlib/buildsystem_tests.py28
2 files changed, 57 insertions, 4 deletions
diff --git a/morphlib/buildsystem.py b/morphlib/buildsystem.py
index 7ac56cf4..3969bddc 100644
--- a/morphlib/buildsystem.py
+++ b/morphlib/buildsystem.py
@@ -14,6 +14,9 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import os
+
+
class BuildSystem(object):
'''An abstraction of an upstream build system.
@@ -40,7 +43,37 @@ class ManualBuildSystem(BuildSystem):
def used_by_project(self, srcdir):
return False
+
class AutotoolsBuildSystem(BuildSystem):
'''The automake/autoconf/libtool holy trinity.'''
+
+ def used_by_project(self, srcdir):
+ indicators = [
+ 'autogen.sh',
+ 'configure.ac',
+ 'configure.in',
+ 'configure.in.in',
+ ]
+
+ return any(os.path.exists(os.path.join(srcdir, x))
+ for x in indicators)
+
+
+def detect_build_system(srcdir):
+ '''Automatically detect the build system, if possible.
+
+ If the build system cannot be detected automatically, then the manual
+ build system is used instead.
+
+ '''
+
+ build_systems = [
+ AutotoolsBuildSystem(),
+ ]
+
+ for bs in build_systems:
+ if bs.used_by_project(srcdir):
+ return bs
+ return ManualBuildSystem()
diff --git a/morphlib/buildsystem_tests.py b/morphlib/buildsystem_tests.py
index 33b7a580..c8e9058f 100644
--- a/morphlib/buildsystem_tests.py
+++ b/morphlib/buildsystem_tests.py
@@ -27,12 +27,12 @@ def touch(pathname):
pass
-def create_empty_project(srcdir):
+def create_manual_project(srcdir):
pass
def create_autotools_project(srcdir):
- touch(os.path.join(srcdir, 'configure'))
+ touch(os.path.join(srcdir, 'configure.in'))
class ManualBuildSystem(unittest.TestCase):
@@ -45,7 +45,7 @@ class ManualBuildSystem(unittest.TestCase):
shutil.rmtree(self.tempdir)
def test_does_not_autodetect_empty(self):
- create_empty_project(self.tempdir)
+ create_manual_project(self.tempdir)
self.assertFalse(self.bs.used_by_project(self.tempdir))
def test_does_not_autodetect_autotools(self):
@@ -63,10 +63,30 @@ class AutotoolsBuildSystem(unittest.TestCase):
shutil.rmtree(self.tempdir)
def test_does_not_autodetect_empty(self):
- create_empty_project(self.tempdir)
+ create_manual_project(self.tempdir)
self.assertFalse(self.bs.used_by_project(self.tempdir))
def test_autodetects_autotools(self):
create_autotools_project(self.tempdir)
self.assertFalse(self.bs.used_by_project(self.tempdir))
+
+class DetectBuildSystemTests(unittest.TestCase):
+
+ def setUp(self):
+ self.bs = morphlib.buildsystem.ManualBuildSystem()
+ self.tempdir = tempfile.mkdtemp()
+
+ def tearDown(self):
+ shutil.rmtree(self.tempdir)
+
+ def test_autodetects_manual(self):
+ create_manual_project(self.tempdir)
+ bs = morphlib.buildsystem.detect_build_system(self.tempdir)
+ self.assertEqual(type(bs), morphlib.buildsystem.ManualBuildSystem)
+
+ def test_autodetects_autotools(self):
+ create_autotools_project(self.tempdir)
+ bs = morphlib.buildsystem.detect_build_system(self.tempdir)
+ self.assertEqual(type(bs), morphlib.buildsystem.AutotoolsBuildSystem)
+