From 24ce400759b299c3afd44f4d111baed1e22b0c39 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 15 Apr 2016 20:55:57 +0900 Subject: [PATCH] Bug 1266343 - Avoid _apply_imports happening twice for the same function. r=chmanchester --- .../mozbuild/mozbuild/configure/__init__.py | 4 ++- .../mozbuild/test/configure/test_configure.py | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/python/mozbuild/mozbuild/configure/__init__.py b/python/mozbuild/mozbuild/configure/__init__.py index 2477e07a2ea1..6a96c4a23311 100644 --- a/python/mozbuild/mozbuild/configure/__init__.py +++ b/python/mozbuild/mozbuild/configure/__init__.py @@ -735,7 +735,9 @@ class ConfigureSandbox(dict): )) @wraps(new_func) def wrapped(*args, **kwargs): - self._apply_imports(func, glob) + if func in self._imports: + self._apply_imports(func, glob) + del self._imports[func] return new_func(*args, **kwargs) self._prepared_functions.add(wrapped) diff --git a/python/mozbuild/mozbuild/test/configure/test_configure.py b/python/mozbuild/mozbuild/test/configure/test_configure.py index 75d069eb6dcb..eeef10b452aa 100644 --- a/python/mozbuild/mozbuild/test/configure/test_configure.py +++ b/python/mozbuild/mozbuild/test/configure/test_configure.py @@ -342,6 +342,31 @@ class TestConfigure(unittest.TestCase): self.assertEquals(sandbox.keys(), ['__builtins__', 'foo']) self.assertEquals(sandbox['__builtins__'], ConfigureSandbox.BUILTINS) + def test_apply_imports(self): + imports = [] + + class CountApplyImportsSandbox(ConfigureSandbox): + def _apply_imports(self, *args, **kwargs): + imports.append((args, kwargs)) + super(CountApplyImportsSandbox, self)._apply_imports( + *args, **kwargs) + + config = {} + out = StringIO() + sandbox = CountApplyImportsSandbox(config, {}, [], out, out) + + exec_(textwrap.dedent(''' + @template + @imports('sys') + def foo(): + return sys + foo() + foo()'''), + sandbox + ) + + self.assertEquals(len(imports), 1) + def test_os_path(self): config = self.get_config(['--with-imports=%s' % __file__]) self.assertIn('IS_FILE', config)