From 6ba5b139b25c7797b8171e0fea3f4e8aebc7f64f Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 2 Oct 2014 09:14:08 +0900 Subject: [PATCH] Bug 1063437 - Use SourcePath smart type for sandbox includes. r=gps --- python/mozbuild/mozbuild/frontend/context.py | 12 +++++++++++- python/mozbuild/mozbuild/frontend/reader.py | 6 +++--- .../mozbuild/mozbuild/test/frontend/test_sandbox.py | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py index 448aaf676345..1746c60a1752 100644 --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -339,6 +339,16 @@ class SourcePath(ContextDerivedValue, UserString): ret = mozpath.join(self.context.objdir, self.value) return mozpath.normpath(ret) + def join(self, *p): + """Lazy mozpath.join(self, *p), returning a new SourcePath instance. + + In an ideal world, this wouldn't be required, but with the + external_source_dir business, and the fact that comm-central and + mozilla-central have directories in common, resolving a SourcePath + before doing mozpath.join doesn't work out properly. + """ + return SourcePath(self.context, mozpath.join(self.value, *p)) + @memoize def ContextDerivedTypedList(type, base_class=List): @@ -1157,7 +1167,7 @@ for name in TEMPLATE_VARIABLES: # The first element is an attribute on Sandbox that should be a function type. # FUNCTIONS = { - 'include': (lambda self: self._include, (str,), + 'include': (lambda self: self._include, (SourcePath,), """Include another mozbuild file in the context of this one. This is similar to a ``#include`` in C languages. The filename passed to diff --git a/python/mozbuild/mozbuild/frontend/reader.py b/python/mozbuild/mozbuild/frontend/reader.py index a361f7d087ae..96acdf6663ed 100644 --- a/python/mozbuild/mozbuild/frontend/reader.py +++ b/python/mozbuild/mozbuild/frontend/reader.py @@ -278,8 +278,8 @@ class MozbuildSandbox(Sandbox): def _include(self, path): """Include and exec another file within the context of this one.""" - # exec_file() handles normalization and verification of the path. - self.exec_file(path) + # path is a SourcePath, and needs to be coerced to unicode. + self.exec_file(unicode(path), filesystem_absolute=True) def _warning(self, message): # FUTURE consider capturing warnings in a variable instead of printing. @@ -978,7 +978,7 @@ class BuildReader(object): recurse_info[d]['exports'] = dict(sandbox.metadata['exports']) for path, child_metadata in recurse_info.items(): - child_path = mozpath.join(path, 'moz.build') + child_path = path.join('moz.build') # Ensure we don't break out of the topsrcdir. We don't do realpath # because it isn't necessary. If there are symlinks in the srcdir, diff --git a/python/mozbuild/mozbuild/test/frontend/test_sandbox.py b/python/mozbuild/mozbuild/test/frontend/test_sandbox.py index a916434721d3..fc1850b6f9b0 100644 --- a/python/mozbuild/mozbuild/test/frontend/test_sandbox.py +++ b/python/mozbuild/mozbuild/test/frontend/test_sandbox.py @@ -233,7 +233,8 @@ class TestMozbuildSandbox(unittest.TestCase): with self.assertRaises(SandboxLoadError) as se: sandbox.exec_file('relative.build') - self.assertEqual(se.exception.illegal_path, '../moz.build') + self.assertEqual(se.exception.illegal_path, + sandbox.normalize_path('../moz.build')) def test_include_error_stack(self): # Ensure the path stack is reported properly in exceptions.