summaryrefslogtreecommitdiff
path: root/morphlib/buildsystem.py
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 /morphlib/buildsystem.py
parentdc589edd6f3faa94c6cbaf66c2caadff51cfbe5a (diff)
downloadmorph-5f73977dc108ff119e63c68d225bec8c9b4378b0.tar.gz
Make build system autodetection use an file existence function passed in
Diffstat (limited to 'morphlib/buildsystem.py')
-rw-r--r--morphlib/buildsystem.py23
1 files changed, 14 insertions, 9 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