Bug 836208 - Part 2: Make |mach build some/Makefile| start one level up. r=glandium
☠☠ backed out by bdf1f0890e2f ☠ ☠
authorNick Alexander <nalexander@mozilla.com>
Tue, 05 Mar 2013 10:45:43 -0800
changeset 123866 64bad42e13b783e2ef292b40a563f852d43a2af8
parent 123865 1e2fc9c3b3c5d004337f943df347995d2e8ec588
child 123867 1f3d297633e0253fb9e7a4566f43e99db870f057
push id1401
push userpastithas@mozilla.com
push dateThu, 07 Mar 2013 07:26:45 +0000
treeherderfx-team@ee4879719f78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs836208
milestone22.0a1
Bug 836208 - Part 2: Make |mach build some/Makefile| start one level up. r=glandium
python/mozbuild/mozbuild/test/test_util.py
python/mozbuild/mozbuild/util.py
--- a/python/mozbuild/mozbuild/test/test_util.py
+++ b/python/mozbuild/mozbuild/test/test_util.py
@@ -114,21 +114,31 @@ class TestResolveTargetToMake(unittest.T
         self.assertResolve('test-dir', ('test-dir', None))
         self.assertResolve('test-dir/with', ('test-dir/with', None))
         self.assertResolve('test-dir/with', ('test-dir/with', None))
         self.assertResolve('test-dir/without', ('test-dir', None))
         self.assertResolve('test-dir/without/with', ('test-dir/without/with', None))
 
     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'))
         self.assertResolve('test-dir/with/without/file', ('test-dir/with', 'without/file'))
         self.assertResolve('test-dir/with/without/with/file', ('test-dir/with/without/with', 'file'))
 
         self.assertResolve('test-dir/without/file', ('test-dir', 'without/file'))
         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()
--- a/python/mozbuild/mozbuild/util.py
+++ b/python/mozbuild/mozbuild/util.py
@@ -157,18 +157,23 @@ def resolve_target_to_make(topobjdir, ta
 
     Returns a pair `(reldir, target)` where `reldir` is a directory
     relative to `topobjdir` containing a Makefile and `target` is a
     make target (possibly `None`).
 
     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.')
         return (None, None)
 
     target = target.replace(os.sep, '/')
 
     abs_target = os.path.join(topobjdir, target)
@@ -195,13 +200,15 @@ def resolve_target_to_make(topobjdir, ta
     # as far into the path as possible. Then, we compute the make
     # target as relative to that directory.
     reldir = os.path.dirname(target)
     target = os.path.basename(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)
         reldir = os.path.dirname(reldir)