From 10276f39ee22d52a30474793461bac8f4403e31d Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 4 Nov 2015 14:04:29 +0900 Subject: [PATCH] Bug 1221453 - Use SourcePaths for LOCAL_INCLUDES. r=gps --- .../src/third_party/libeventcommon.mozbuild | 6 ++-- .../mozbuild/backend/recursivemake.py | 28 ++++++++++++++++--- .../mozbuild/mozbuild/backend/visualstudio.py | 7 +---- python/mozbuild/mozbuild/frontend/context.py | 2 +- python/mozbuild/mozbuild/frontend/emitter.py | 13 ++------- .../test/backend/test_recursivemake.py | 2 +- .../mozbuild/test/frontend/test_emitter.py | 9 ++++++ 7 files changed, 42 insertions(+), 25 deletions(-) diff --git a/ipc/chromium/src/third_party/libeventcommon.mozbuild b/ipc/chromium/src/third_party/libeventcommon.mozbuild index f5736187bfe..bb8f41bcf40 100644 --- a/ipc/chromium/src/third_party/libeventcommon.mozbuild +++ b/ipc/chromium/src/third_party/libeventcommon.mozbuild @@ -31,7 +31,7 @@ else: if os_posix and not CONFIG['MOZ_NATIVE_LIBEVENT']: DEFINES['HAVE_CONFIG_H'] = True LOCAL_INCLUDES += sorted([ - libevent_path_prefix + '/libevent', - libevent_path_prefix + '/libevent/include', - libevent_path_prefix + '/libevent/' + libevent_include_suffix, + 'libevent', + 'libevent/include', + 'libevent/' + libevent_include_suffix, ]) diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index 33767778b34..c923d3f61fe 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -24,6 +24,11 @@ from mozpack.manifests import ( ) import mozpack.path as mozpath +from mozbuild.frontend.context import ( + Path, + SourcePath, + ObjDirPath, +) from .common import CommonBackend from ..frontend.data import ( AndroidAssetsDirs, @@ -868,6 +873,21 @@ class RecursiveMakeBackend(CommonBackend): ensureParentDir(mozpath.join(self.environment.topobjdir, 'dist', 'foo')) + def _pretty_path(self, path, backend_file): + assert isinstance(path, Path) + if isinstance(path, SourcePath): + if path.full_path.startswith(backend_file.srcdir): + return '$(srcdir)' + path.full_path[len(backend_file.srcdir):] + if path.full_path.startswith(self.environment.topsrcdir): + return '$(topsrcdir)' + path.full_path[len(self.environment.topsrcdir):] + elif isinstance(path, ObjDirPath): + if path.full_path.startswith(backend_file.objdir): + return path.full_path[len(backend_file.objdir) + 1:] + if path.full_path.startswith(self.environment.topobjdir): + return '$(DEPTH)' + path.full_path[len(self.environment.topobjdir):] + + return path.full_path + def _process_unified_sources(self, obj): backend_file = self._get_backend_file_for(obj) @@ -1219,11 +1239,11 @@ INSTALL_TARGETS += %(prefix)s self.backend_input_files |= obj.manifest.manifests def _process_local_include(self, local_include, backend_file): - if local_include.startswith('/'): - path = '$(topsrcdir)' + path = self._pretty_path(local_include, backend_file) + if ' ' in path: + backend_file.write('LOCAL_INCLUDES += -I\'%s\'\n' % path) else: - path = '$(srcdir)/' - backend_file.write('LOCAL_INCLUDES += -I%s%s\n' % (path, local_include)) + backend_file.write('LOCAL_INCLUDES += -I%s\n' % path) def _process_generated_include(self, generated_include, backend_file): if generated_include.startswith('/'): diff --git a/python/mozbuild/mozbuild/backend/visualstudio.py b/python/mozbuild/mozbuild/backend/visualstudio.py index 51dd2e298b6..11aa573cede 100644 --- a/python/mozbuild/mozbuild/backend/visualstudio.py +++ b/python/mozbuild/mozbuild/backend/visualstudio.py @@ -136,13 +136,8 @@ class VisualStudioBackend(CommonBackend): self._paths_to_defines.setdefault(reldir, {}).update(obj.defines) elif isinstance(obj, LocalInclude): - p = obj.path includes = self._paths_to_includes.setdefault(reldir, []) - - if p.startswith('/'): - includes.append(os.path.join('$(TopSrcDir)', p[1:])) - else: - includes.append(os.path.join('$(TopSrcDir)', reldir, p)) + includes.append(obj.path.full_path) # Just acknowledge everything. return True diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py index 51991237b2e..6bb747b4fef 100644 --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -1169,7 +1169,7 @@ VARIABLES = { """List of system libraries for host programs and libraries. """, None), - 'LOCAL_INCLUDES': (StrictOrderingOnAppendList, list, + 'LOCAL_INCLUDES': (ContextDerivedTypedList(SourcePath, StrictOrderingOnAppendList), list, """Additional directories to be searched for include files by the compiler. """, None), diff --git a/python/mozbuild/mozbuild/frontend/emitter.py b/python/mozbuild/mozbuild/frontend/emitter.py index 6370fd7e2e2..b6dd7a81b38 100644 --- a/python/mozbuild/mozbuild/frontend/emitter.py +++ b/python/mozbuild/mozbuild/frontend/emitter.py @@ -671,17 +671,10 @@ class TreeMetadataEmitter(LoggingMixin): yield klass(context, name) for local_include in context.get('LOCAL_INCLUDES', []): - if local_include.startswith('/'): - path = context.config.topsrcdir - relative_include = local_include[1:] - else: - path = context.srcdir - relative_include = local_include - - actual_include = os.path.join(path, relative_include) - if not os.path.exists(actual_include): + if not os.path.exists(local_include.full_path): raise SandboxValidationError('Path specified in LOCAL_INCLUDES ' - 'does not exist: %s (resolved to %s)' % (local_include, actual_include), context) + 'does not exist: %s (resolved to %s)' % (local_include, + local_include.full_path), context) yield LocalInclude(context, local_include) final_target_files = context.get('FINAL_TARGET_FILES') diff --git a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py index 56ca2ac48bc..6a47de225c1 100644 --- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py +++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py @@ -610,7 +610,7 @@ class TestRecursiveMakeBackend(BackendTester): lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]] expected = [ - 'LOCAL_INCLUDES += -I$(topsrcdir)/bar/baz', + 'LOCAL_INCLUDES += -I$(srcdir)/bar/baz', 'LOCAL_INCLUDES += -I$(srcdir)/foo', ] diff --git a/python/mozbuild/mozbuild/test/frontend/test_emitter.py b/python/mozbuild/mozbuild/test/frontend/test_emitter.py index e46191ad63b..b29571ddb8c 100644 --- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py +++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py @@ -647,6 +647,15 @@ class TestEmitterBasic(unittest.TestCase): self.assertEqual(local_includes, expected) + local_includes = [o.path.full_path + 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_generated_includes(self): """Test that GENERATED_INCLUDES is emitted correctly.""" reader = self.reader('generated_includes')