diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-10-16 12:12:59 +0100 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-10-17 16:23:59 +0000 |
commit | 2dea5e3eddb4dad81aec8a444f52198e0bb27357 (patch) | |
tree | 972a558d5a87cf0a0e01bae3d90a8a7ff4a23949 | |
parent | ff9619a94f10c3ae757da6e3634a3de608e263b7 (diff) | |
download | import-2dea5e3eddb4dad81aec8a444f52198e0bb27357.tar.gz |
Add build system detection
Change-Id: Iaa1572cf3d5fd7baf96d2084f7194953bede634c
-rw-r--r-- | baserockimport/mainloop.py | 6 | ||||
-rw-r--r-- | baserockimport/package.py | 52 |
2 files changed, 58 insertions, 0 deletions
diff --git a/baserockimport/mainloop.py b/baserockimport/mainloop.py index 9aa38ff..7d7cd87 100644 --- a/baserockimport/mainloop.py +++ b/baserockimport/mainloop.py @@ -233,6 +233,9 @@ class ImportLoop(object): package.version_in_use = checked_out_version + if not self.generate_chunk_morphs: + package.detect_build_system(source_repo.list_files()) + with morphlib.util.temp_dir() as td: source_repo.clone_into(td, ref=ref) temp_repo = morphlib.gitdir.GitDirectory(td) @@ -641,6 +644,9 @@ class ImportLoop(object): 'unpetrify-ref': package.named_ref, } + if package.build_system is not None: + entry['build-system'] = package.build_system + if morphology is not None: entry['morph'] = morphology.filename diff --git a/baserockimport/package.py b/baserockimport/package.py index 8df011b..ddeaa51 100644 --- a/baserockimport/package.py +++ b/baserockimport/package.py @@ -26,6 +26,7 @@ class Package(object): self._kind = kind self._name = name self._version = version + self._build_system = None self.required_by = [] self.morphology = None self.repo_url = None @@ -77,3 +78,54 @@ class Package(object): @property def parent(self): return self.required_by[0] if len(self.required_by) > 0 else None + + @property + def build_system(self): + return self._build_system + + def detect_build_system(self, file_iter): + '''Automatically detect the build system, if possible. + + If the build system cannot be detected automatically, return None. + ''' + + build_systems = { + 'autotools': [ + 'autogen', + 'autogen.sh', + 'configure', + 'configure.ac', + 'configure.in', + 'configure.in.in', + ], + 'python-distutils': [ + 'setup.py' + ], + 'cpan': [ + 'Makefile.PL' + ], + 'module-build': [ + 'Build.PL' + ], + 'cmake': [ + 'CMakeLists.txt', + ], + 'qmake': [ + '.pro' + ] + } + + # Aside from ensuring generated definitions are stable, + # an explicit ordering allows us to favour one build system + # over another in the case that a single repo supports more + # than one build system. + order = ['autotools', 'python-distutils', 'cpan', 'module-build', + 'cmake', 'qmake'] + + files = set(file_iter) + for bs in order: + indicators = set(build_systems[bs]) + + if not files.isdisjoint(indicators): + self._build_system = bs + return |