Bug 1525474 - Disallow filenames in LOCAL_INCLUDES; r=nalexander
authorMike Shal <mshal@mozilla.com>
Fri, 01 Mar 2019 17:51:42 +0000
changeset 519855 f4ec35c8165ffde437c749537af1793c9f86abbf
parent 519854 a59b3f861c7d988f0de8384ded27558da16be3dc
child 519856 ccd70bb02d61d1b627815f921caaebe1ce999e4f
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1525474
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525474 - Disallow filenames in LOCAL_INCLUDES; r=nalexander The underlying backends only support directories in LOCAL_INCLUDES (since these ultimately translate to -I arguments to the compiler). We should disallow filenames here, in case a developer accidentally specifies a header file instead of a directory. Differential Revision: https://phabricator.services.mozilla.com/D21698
python/mozbuild/mozbuild/frontend/emitter.py
python/mozbuild/mozbuild/test/frontend/data/local_includes-filename/foo.h
python/mozbuild/mozbuild/test/frontend/data/local_includes-filename/moz.build
python/mozbuild/mozbuild/test/frontend/test_emitter.py
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -1177,21 +1177,25 @@ class TreeMetadataEmitter(LoggingMixin):
                 self._idls[context_var].add(mozpath.join(context.srcdir, name))
         # WEBIDL_EXAMPLE_INTERFACES do not correspond to files.
         for name in context.get('WEBIDL_EXAMPLE_INTERFACES', []):
             self._idls['WEBIDL_EXAMPLE_INTERFACES'].add(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(full_path)):
-                raise SandboxValidationError('Path specified in LOCAL_INCLUDES '
-                    'does not exist: %s (resolved to %s)' % (local_include,
-                    full_path), context)
+            if not isinstance(local_include, ObjDirPath):
+                if not os.path.exists(full_path):
+                    raise SandboxValidationError('Path specified in LOCAL_INCLUDES '
+                        'does not exist: %s (resolved to %s)' % (local_include,
+                        full_path), context)
+                if not os.path.isdir(full_path):
+                    raise SandboxValidationError('Path specified in LOCAL_INCLUDES '
+                        'is a filename, but a directory is required: %s '
+                        '(resolved to %s)' % (local_include, full_path), context)
             if (full_path == context.config.topsrcdir or
                     full_path == context.config.topobjdir):
                 raise SandboxValidationError('Path specified in LOCAL_INCLUDES '
                     '(%s) resolves to the topsrcdir or topobjdir (%s), which is '
                     'not allowed' % (local_include, full_path), context)
             include_obj = LocalInclude(context, local_include)
             local_includes.append(include_obj.path.full_path)
             yield include_obj
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/local_includes-filename/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 += ['foo.h']
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -1064,16 +1064,25 @@ class TestEmitterBasic(unittest.TestCase
         reader = self.reader('local_includes-invalid/objdir')
 
         with self.assertRaisesRegexp(
                 SandboxValidationError,
                 'Path specified in LOCAL_INCLUDES.*resolves to the '
                 'topsrcdir or topobjdir'):
             objs = self.read_topsrcdir(reader)
 
+    def test_local_includes_file(self):
+        """Test that a filename can't be used in LOCAL_INCLUDES."""
+        reader = self.reader('local_includes-filename')
+
+        with self.assertRaisesRegexp(
+                SandboxValidationError,
+                'Path specified in LOCAL_INCLUDES is a filename'):
+            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',