summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-30 17:01:56 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-30 17:01:56 +0100
commit5f73977dc108ff119e63c68d225bec8c9b4378b0 (patch)
treee7648ec19415d60c6cc5992518b771c79250811e
parentdc589edd6f3faa94c6cbaf66c2caadff51cfbe5a (diff)
downloadmorph-5f73977dc108ff119e63c68d225bec8c9b4378b0.tar.gz
Make build system autodetection use an file existence function passed in
-rw-r--r--morphlib/buildsystem.py23
-rw-r--r--morphlib/buildsystem_tests.py28
2 files changed, 34 insertions, 17 deletions
diff --git a/morphlib/buildsystem.py b/morphlib/buildsystem.py
index a048d881..6bff51b2 100644
--- a/morphlib/buildsystem.py
+++ b/morphlib/buildsystem.py
@@ -55,8 +55,13 @@ class BuildSystem(object):
'bs': self.name,
}
- def used_by_project(self, srcdir):
- '''Does project at ``srcdir`` use this build system?'''
+ def used_by_project(self, exists):
+ '''Does a project use this build system?
+
+ ``exists`` is a function that returns a boolean telling if a
+ filename, relative to the project source directory, exists or not.
+
+ '''
raise NotImplementedError() # pragma: no cover
@@ -66,7 +71,7 @@ class ManualBuildSystem(BuildSystem):
name = 'manual'
- def used_by_project(self, srcdir):
+ def used_by_project(self, exists):
return False
@@ -82,7 +87,7 @@ class DummyBuildSystem(BuildSystem):
self.test_commands = ['echo dummy test']
self.install_commands = ['echo dummy install']
- def used_by_project(self, srcdir):
+ def used_by_project(self, exists):
return False
@@ -107,7 +112,7 @@ class AutotoolsBuildSystem(BuildSystem):
'make DESTDIR="$DESTDIR" install',
]
- def used_by_project(self, srcdir):
+ def used_by_project(self, exists):
indicators = [
'autogen.sh',
'configure.ac',
@@ -115,8 +120,7 @@ class AutotoolsBuildSystem(BuildSystem):
'configure.in.in',
]
- return any(os.path.exists(os.path.join(srcdir, x))
- for x in indicators)
+ return any(exists(x) for x in indicators)
build_systems = [
@@ -126,15 +130,16 @@ build_systems = [
]
-def detect_build_system(srcdir):
+def detect_build_system(exists):
'''Automatically detect the build system, if possible.
If the build system cannot be detected automatically, return None.
+ For ``exists`` see the ``BuildSystem.exists`` method.
'''
for bs in build_systems:
- if bs.used_by_project(srcdir):
+ if bs.used_by_project(exists):
return bs
return None
diff --git a/morphlib/buildsystem_tests.py b/morphlib/buildsystem_tests.py
index 2d688922..8c790219 100644
--- a/morphlib/buildsystem_tests.py
+++ b/morphlib/buildsystem_tests.py
@@ -67,13 +67,16 @@ class ManualBuildSystemTests(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tempdir)
+ def exists(self, filename):
+ return os.path.exists(os.path.join(self.tempdir, filename))
+
def test_does_not_autodetect_empty(self):
create_manual_project(self.tempdir)
- self.assertFalse(self.bs.used_by_project(self.tempdir))
+ self.assertFalse(self.bs.used_by_project(self.exists))
def test_does_not_autodetect_autotools(self):
create_autotools_project(self.tempdir)
- self.assertFalse(self.bs.used_by_project(self.tempdir))
+ self.assertFalse(self.bs.used_by_project(self.exists))
class DummyBuildSystemTests(unittest.TestCase):
@@ -85,13 +88,16 @@ class DummyBuildSystemTests(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tempdir)
+ def exists(self, filename):
+ return os.path.exists(os.path.join(self.tempdir, filename))
+
def test_does_not_autodetect_empty(self):
create_manual_project(self.tempdir)
- self.assertFalse(self.bs.used_by_project(self.tempdir))
+ self.assertFalse(self.bs.used_by_project(self.exists))
def test_does_not_autodetect_autotools(self):
create_autotools_project(self.tempdir)
- self.assertFalse(self.bs.used_by_project(self.tempdir))
+ self.assertFalse(self.bs.used_by_project(self.exists))
class AutotoolsBuildSystemTests(unittest.TestCase):
@@ -103,13 +109,16 @@ class AutotoolsBuildSystemTests(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tempdir)
+ def exists(self, filename):
+ return os.path.exists(os.path.join(self.tempdir, filename))
+
def test_does_not_autodetect_empty(self):
create_manual_project(self.tempdir)
- self.assertFalse(self.bs.used_by_project(self.tempdir))
+ self.assertFalse(self.bs.used_by_project(self.exists))
def test_autodetects_autotools(self):
create_autotools_project(self.tempdir)
- self.assertFalse(self.bs.used_by_project(self.tempdir))
+ self.assertFalse(self.bs.used_by_project(self.exists))
class DetectBuildSystemTests(unittest.TestCase):
@@ -120,15 +129,18 @@ class DetectBuildSystemTests(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tempdir)
+
+ def exists(self, filename):
+ return os.path.exists(os.path.join(self.tempdir, filename))
def test_does_not_autodetect_manual(self):
create_manual_project(self.tempdir)
- bs = morphlib.buildsystem.detect_build_system(self.tempdir)
+ bs = morphlib.buildsystem.detect_build_system(self.exists)
self.assertEqual(bs, None)
def test_autodetects_autotools(self):
create_autotools_project(self.tempdir)
- bs = morphlib.buildsystem.detect_build_system(self.tempdir)
+ bs = morphlib.buildsystem.detect_build_system(self.exists)
self.assertEqual(type(bs), morphlib.buildsystem.AutotoolsBuildSystem)