From efd884df575db99e241a4de9032f21677d7f4b4a Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Tue, 5 Mar 2013 10:45:43 -0800 Subject: [PATCH] Bug 836208 - Part 2: Make |mach build some/Makefile| start one level up. r=glandium --- python/mozbuild/mozbuild/test/test_util.py | 10 ++++++++++ python/mozbuild/mozbuild/util.py | 13 ++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/python/mozbuild/mozbuild/test/test_util.py b/python/mozbuild/mozbuild/test/test_util.py index 324c5452fb5..6dc5cc8f8d0 100644 --- a/python/mozbuild/mozbuild/test/test_util.py +++ b/python/mozbuild/mozbuild/test/test_util.py @@ -119,6 +119,8 @@ class TestResolveTargetToMake(unittest.TestCase): def test_top_level(self): self.assertResolve('package', (None, 'package')) + # Makefile handling shouldn't affect top-level targets. + self.assertResolve('Makefile', (None, 'Makefile')) def test_regular_file(self): self.assertResolve('test-dir/with/file', ('test-dir/with', 'file')) @@ -129,6 +131,14 @@ class TestResolveTargetToMake(unittest.TestCase): self.assertResolve('test-dir/without/with/file', ('test-dir/without/with', 'file')) self.assertResolve('test-dir/without/with/without/file', ('test-dir/without/with', 'without/file')) + def test_Makefile(self): + self.assertResolve('test-dir/with/Makefile', ('test-dir', 'with/Makefile')) + self.assertResolve('test-dir/with/without/Makefile', ('test-dir/with', 'without/Makefile')) + self.assertResolve('test-dir/with/without/with/Makefile', ('test-dir/with', 'without/with/Makefile')) + + self.assertResolve('test-dir/without/Makefile', ('test-dir', 'without/Makefile')) + self.assertResolve('test-dir/without/with/Makefile', ('test-dir', 'without/with/Makefile')) + self.assertResolve('test-dir/without/with/without/Makefile', ('test-dir/without/with', 'without/Makefile')) if __name__ == '__main__': main() diff --git a/python/mozbuild/mozbuild/util.py b/python/mozbuild/mozbuild/util.py index 5591fe7fd99..e4d8b07c81b 100644 --- a/python/mozbuild/mozbuild/util.py +++ b/python/mozbuild/mozbuild/util.py @@ -162,8 +162,13 @@ def resolve_target_to_make(topobjdir, target): A directory resolves to the nearest directory at or above containing a Makefile, and target `None`. - A file resolves to the nearest directory at or above the file - containing a Makefile, and an appropriate target. + A regular (non-Makefile) file resolves to the nearest directory at + or above the file containing a Makefile, and an appropriate + target. + + A Makefile resolves to the nearest parent strictly above the + Makefile containing a different Makefile, and an appropriate + target. ''' if os.path.isabs(target): print('Absolute paths for make targets are not allowed.') @@ -200,7 +205,9 @@ def resolve_target_to_make(topobjdir, target): while True: make_path = os.path.join(topobjdir, reldir, 'Makefile') - if os.path.exists(make_path): + # We append to target every iteration, so the check below + # happens exactly once. + if target != 'Makefile' and os.path.exists(make_path): return (reldir, target) target = os.path.join(os.path.basename(reldir), target)