diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-08-24 17:58:42 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-08-24 17:58:42 +0100 |
commit | 98b802e36b2a291b39dbdb83b55546b1acae1573 (patch) | |
tree | a6579f891f29f15a7b8b7c94ea3847cc66ad5428 /morphlib/buildsystem_tests.py | |
parent | 975b3f30605c36a714bf5b9619817a897cb6a4a3 (diff) | |
download | morph-98b802e36b2a291b39dbdb83b55546b1acae1573.tar.gz |
Use git ls-tree to autodetect build system
The cost of one git ls-tree call is roughly the same as one
git cat-file call. Therefore, when autodetecting the build system,
it is much faster to list the tree once and then search for the
required files than to call git cat-file for every possible one.
Diffstat (limited to 'morphlib/buildsystem_tests.py')
-rw-r--r-- | morphlib/buildsystem_tests.py | 76 |
1 files changed, 22 insertions, 54 deletions
diff --git a/morphlib/buildsystem_tests.py b/morphlib/buildsystem_tests.py index c955f12a..53b4fc17 100644 --- a/morphlib/buildsystem_tests.py +++ b/morphlib/buildsystem_tests.py @@ -26,13 +26,8 @@ def touch(pathname): with open(pathname, 'w'): pass - -def create_manual_project(srcdir): - pass - - -def create_autotools_project(srcdir): - touch(os.path.join(srcdir, 'configure.in')) +manual_project = [] +autotools_project = ['configure.in'] class BuildSystemTests(unittest.TestCase): @@ -62,85 +57,58 @@ class ManualBuildSystemTests(unittest.TestCase): def setUp(self): self.bs = morphlib.buildsystem.ManualBuildSystem() - self.tempdir = tempfile.mkdtemp() - - 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.exists)) + def exists(filename): + return filename in manual_project + self.assertFalse(self.bs.used_by_project(exists)) def test_does_not_autodetect_autotools(self): - create_autotools_project(self.tempdir) - self.assertFalse(self.bs.used_by_project(self.exists)) + def exists(filename): + return filename in autotools_project + self.assertFalse(self.bs.used_by_project(exists)) class DummyBuildSystemTests(unittest.TestCase): def setUp(self): self.bs = morphlib.buildsystem.DummyBuildSystem() - self.tempdir = tempfile.mkdtemp() - - 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.exists)) + def exists(filename): + return filename in manual_project + self.assertFalse(self.bs.used_by_project(exists)) def test_does_not_autodetect_autotools(self): - create_autotools_project(self.tempdir) - self.assertFalse(self.bs.used_by_project(self.exists)) + def exists(filename): + return filename in autotools_project + self.assertFalse(self.bs.used_by_project(exists)) class AutotoolsBuildSystemTests(unittest.TestCase): def setUp(self): self.bs = morphlib.buildsystem.AutotoolsBuildSystem() - self.tempdir = tempfile.mkdtemp() - - 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.exists)) + def exists(filename): + return filename in manual_project + self.assertFalse(self.bs.used_by_project(exists)) def test_autodetects_autotools(self): - create_autotools_project(self.tempdir) - self.assertTrue(self.bs.used_by_project(self.exists)) + def exists(filename): + return filename in autotools_project + self.assertTrue(self.bs.used_by_project(exists)) class DetectBuildSystemTests(unittest.TestCase): - def setUp(self): - self.bs = morphlib.buildsystem.ManualBuildSystem() - self.tempdir = tempfile.mkdtemp() - - 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.exists) + bs = morphlib.buildsystem.detect_build_system(manual_project) self.assertEqual(bs, None) def test_autodetects_autotools(self): - create_autotools_project(self.tempdir) - bs = morphlib.buildsystem.detect_build_system(self.exists) + bs = morphlib.buildsystem.detect_build_system(autotools_project) self.assertEqual(type(bs), morphlib.buildsystem.AutotoolsBuildSystem) |