Bug 1264482 - Fake an arbitrary __name__ in sandboxed global. r?ted
--- a/build/moz.configure/checks.configure
+++ b/build/moz.configure/checks.configure
@@ -8,17 +8,16 @@
# ==============================================================
# Declare some exceptions. This is cumbersome, but since we shouldn't need a
# lot of them, let's stack them all here. When adding a new one, put it in the
# _declare_exceptions template, and add it to the return statement. Then
# destructure in the assignment below the function declaration.
@template
@imports(_from='__builtin__', _import='Exception')
-@imports(_from='__builtin__', _import='__name__')
def _declare_exceptions():
class FatalCheckError(Exception):
'''An exception to throw from a function decorated with @checking.
It will result in calling die() with the given message.
Debugging messages emitted from the decorated function will also be
printed out.'''
return (FatalCheckError,)
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -685,16 +685,17 @@ class ConfigureSandbox(dict):
glob = SandboxedGlobal(
(k, v) for k, v in func.func_globals.iteritems()
if (inspect.isfunction(v) and v not in self._templates) or (
inspect.isclass(v) and issubclass(v, Exception))
)
glob.update(
__builtins__=self.BUILTINS,
__file__=self._paths[-1] if self._paths else '',
+ __name__=self._paths[-1] if self._paths else '',
os=self.OS,
log=self.log_impl,
)
self._apply_imports(func, glob)
# The execution model in the sandbox doesn't guarantee the execution
# order will always be the same for a given function, and if it uses
# variables from a closure that are changed after the function is