Bug 1428608 - Forbid / or !/ in LOCAL_INCLUDES. r?nfroyd draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 17 Jan 2018 17:10:20 +0900
changeset 721920 407170d126a1ee37ce80caf4a078265bed954d78
parent 721208 b2cb61e83ac50115a28f04aaa8a32d4db90aad23
child 746484 72dc16644a3f1a0a35d7520de02f3dc8d3b288ee
push id96000
push userbmo:mh+mozilla@glandium.org
push dateThu, 18 Jan 2018 04:46:04 +0000
reviewersnfroyd
bugs1428608, 1427668, 1428678
milestone59.0a1
Bug 1428608 - Forbid / or !/ in LOCAL_INCLUDES. r?nfroyd And remove the two cases that currently set that, without actually using it. The webrtc gtest one never relied on it, and the gfx one was added in bug 1427668 for a single header, and the corresponding #includes were changed in bug 1428678.
dom/canvas/moz.build
media/webrtc/trunk/gtest/moz.build
python/mozbuild/mozbuild/frontend/emitter.py
python/mozbuild/mozbuild/test/frontend/data/local_includes-invalid/objdir/moz.build
python/mozbuild/mozbuild/test/frontend/data/local_includes-invalid/srcdir/moz.build
python/mozbuild/mozbuild/test/frontend/test_emitter.py
--- a/dom/canvas/moz.build
+++ b/dom/canvas/moz.build
@@ -196,17 +196,16 @@ LOCAL_INCLUDES += [
     '/js/xpconnect/wrappers',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 LOCAL_INCLUDES += [
     '../workers',
-    '/', # Allow including relpaths from root.
     '/dom/base',
     '/dom/html',
     '/dom/svg',
     '/dom/workers',
     '/dom/xul',
     '/gfx/gl',
     '/image',
     '/js/xpconnect/src',
--- a/media/webrtc/trunk/gtest/moz.build
+++ b/media/webrtc/trunk/gtest/moz.build
@@ -16,17 +16,16 @@ DEFINES['WEBRTC_APM_DEBUG_DUMP'] = True
 DEFINES['WEBRTC_INTELLIGIBILITY_ENHANCER'] = 0
 DEFINES['WEBRTC_MOZILLA_BUILD'] = 1
 
 # Hit build errors on windows with xutility otherwise
 DisableStlWrapping()
 
 LOCAL_INCLUDES += [
     '../',
-    '/',
     '/ipc/chromium/src/',
     '/media/libopus/celt/',
     '/media/libopus/include',
     '/media/libopus/src',
     '/media/libyuv/libyuv/include',
 ]
 
 USE_LIBS += [
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -1116,21 +1116,27 @@ class TreeMetadataEmitter(LoggingMixin):
             ('WEBIDL_EXAMPLE_INTERFACES', ExampleWebIDLInterface),
         ]
         for context_var, klass in simple_lists:
             for name in context.get(context_var, []):
                 yield klass(context, name)
 
         local_includes = []
         for local_include in context.get('LOCAL_INCLUDES', []):
+            full_path = local_include.full_path
             if (not isinstance(local_include, ObjDirPath) and
-                    not os.path.exists(local_include.full_path)):
+                    not os.path.exists(full_path)):
                 raise SandboxValidationError('Path specified in LOCAL_INCLUDES '
                     'does not exist: %s (resolved to %s)' % (local_include,
-                    local_include.full_path), context)
+                    full_path), context)
+            if (full_path == context.config.topsrcdir or
+                    full_path == context.config.topobjdir):
+                raise SandboxValidationError('Path specified in LOCAL_INCLUDES '
+                    'is not allowed: %s (resolved to %s)' % (local_include,
+                    full_path), context)
             include_obj = LocalInclude(context, local_include)
             local_includes.append(include_obj.path.full_path)
             yield include_obj
 
         computed_flags.resolve_flags('LOCAL_INCLUDES', ['-I%s' % p for p in local_includes])
         computed_as_flags.resolve_flags('LOCAL_INCLUDES', ['-I%s' % p for p in local_includes])
         computed_host_flags.resolve_flags('LOCAL_INCLUDES', ['-I%s' % p for p in local_includes])
 
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/local_includes-invalid/objdir/moz.build
@@ -0,0 +1,5 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+LOCAL_INCLUDES += ['!/']
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/local_includes-invalid/srcdir/moz.build
@@ -0,0 +1,5 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+LOCAL_INCLUDES += ['/']
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -967,16 +967,32 @@ class TestEmitterBasic(unittest.TestCase
                           for o in objs if isinstance(o, LocalInclude)]
         expected = [
             mozpath.join(reader.config.topsrcdir, 'bar/baz'),
             mozpath.join(reader.config.topsrcdir, 'foo'),
         ]
 
         self.assertEqual(local_includes, expected)
 
+    def test_local_includes_invalid(self):
+        """Test that invalid LOCAL_INCLUDES are properly detected."""
+        reader = self.reader('local_includes-invalid/srcdir')
+
+        with self.assertRaisesRegexp(
+                SandboxValidationError,
+                'Path specified in LOCAL_INCLUDES is not allowed:'):
+            objs = self.read_topsrcdir(reader)
+
+        reader = self.reader('local_includes-invalid/objdir')
+
+        with self.assertRaisesRegexp(
+                SandboxValidationError,
+                'Path specified in LOCAL_INCLUDES is not allowed:'):
+            objs = self.read_topsrcdir(reader)
+
     def test_generated_includes(self):
         """Test that GENERATED_INCLUDES is emitted correctly."""
         reader = self.reader('generated_includes')
         objs = self.read_topsrcdir(reader)
 
         generated_includes = [o.path for o in objs if isinstance(o, LocalInclude)]
         expected = [
             '!/bar/baz',