Bug 1296530 - Rename DependsFunction to SandboxDependsFunction. r?chmanchester
--- a/build/moz.configure/compilers-util.configure
+++ b/build/moz.configure/compilers-util.configure
@@ -1,19 +1,19 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
@template
@imports('textwrap')
-@imports(_from='mozbuild.configure', _import='DependsFunction')
+@imports(_from='mozbuild.configure', _import='SandboxDependsFunction')
def compiler_class(compiler):
- class Compiler(DependsFunction):
+ class Compiler(SandboxDependsFunction):
# Generates a test program and attempts to compile it. In case of
# failure, the resulting check will return None. If the test program
# succeeds, it will return the output of the test program.
# - `includes` are the includes (as file names) that will appear at the
# top of the generated test program.
# - `body` is the code that will appear in the main function of the
# generated test program. `return 0;` is appended to the function
# body automatically.
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -328,19 +328,19 @@ def namespace(**kwargs):
return ReadOnlyNamespace(**kwargs)
# Turn an object into an object that can be used as an argument to @depends.
# The given object can be a literal value, a function that takes no argument,
# or, for convenience, a @depends function.
@template
@imports(_from='inspect', _import='isfunction')
-@imports(_from='mozbuild.configure', _import='DependsFunction')
+@imports(_from='mozbuild.configure', _import='SandboxDependsFunction')
def dependable(obj):
- if isinstance(obj, DependsFunction):
+ if isinstance(obj, SandboxDependsFunction):
return obj
if isfunction(obj):
return depends('--help')(lambda _: obj())
return depends('--help')(lambda _: obj)
always = dependable(True)
never = dependable(False)
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -37,17 +37,17 @@ from mozbuild.util import (
import mozpack.path as mozpath
class ConfigureError(Exception):
pass
-class DependsFunction(object):
+class SandboxDependsFunction(object):
'''Sandbox-visible representation of @depends functions.'''
def __call__(self, *arg, **kwargs):
raise ConfigureError('The `%s` function may not be called'
% self.__name__)
class SandboxedGlobal(dict):
'''Identifiable dict type for use as function global'''
@@ -274,52 +274,52 @@ class ConfigureSandbox(dict):
def __setitem__(self, key, value):
if (key in self.BUILTINS or key == '__builtins__' or
hasattr(self, '%s_impl' % key)):
raise KeyError('Cannot reassign builtins')
if inspect.isfunction(value) and value not in self._templates:
value, _ = self._prepare_function(value)
- elif (not isinstance(value, DependsFunction) and
+ elif (not isinstance(value, SandboxDependsFunction) and
value not in self._templates and
not (inspect.isclass(value) and issubclass(value, Exception))):
raise KeyError('Cannot assign `%s` because it is neither a '
'@depends nor a @template' % key)
return super(ConfigureSandbox, self).__setitem__(key, value)
def _resolve(self, arg, need_help_dependency=True):
- if isinstance(arg, DependsFunction):
+ if isinstance(arg, SandboxDependsFunction):
assert arg in self._depends
func, deps = self._depends[arg]
if need_help_dependency and self._help_option not in deps:
raise ConfigureError("Missing @depends for `%s`: '--help'" %
func.__name__)
return self._value_for(arg)
return arg
def _value_for(self, obj):
- if isinstance(obj, DependsFunction):
+ if isinstance(obj, SandboxDependsFunction):
return self._value_for_depends(obj)
elif isinstance(obj, Option):
return self._value_for_option(obj)
assert False
@memoize
def _value_for_depends(self, obj):
assert obj in self._depends
func, dependencies = self._depends[obj]
assert not inspect.isgeneratorfunction(func)
with_help = self._help_option in dependencies
if with_help:
for arg in dependencies:
- if isinstance(arg, DependsFunction):
+ if isinstance(arg, SandboxDependsFunction):
_, deps = self._depends[arg]
if self._help_option not in deps:
raise ConfigureError(
"`%s` depends on '--help' and `%s`. "
"`%s` must depend on '--help'"
% (func.__name__, arg.__name__, arg.__name__))
elif self._help:
raise ConfigureError("Missing @depends for `%s`: '--help'" %
@@ -429,31 +429,31 @@ class ConfigureSandbox(dict):
raise ConfigureError("Option must not contain an '='")
if name not in self._options:
raise ConfigureError("'%s' is not a known option. "
"Maybe it's declared too late?"
% arg)
arg = self._options[name]
self._seen.add(arg)
dependencies.append(arg)
- elif isinstance(arg, DependsFunction):
+ elif isinstance(arg, SandboxDependsFunction):
assert arg in self._depends
dependencies.append(arg)
else:
raise TypeError(
"Cannot use object of type '%s' as argument to @depends"
% type(arg).__name__)
dependencies = tuple(dependencies)
def decorator(func):
if inspect.isgeneratorfunction(func):
raise ConfigureError(
'Cannot decorate generator functions with @depends')
func, glob = self._prepare_function(func)
- dummy = wraps(func)(DependsFunction())
+ dummy = wraps(func)(SandboxDependsFunction())
self._depends[dummy] = func, dependencies
# Only @depends functions with a dependency on '--help' are
# executed immediately. Everything else is queued for later
# execution.
if self._help_option in dependencies:
self._value_for(dummy)
elif not self._help:
@@ -681,17 +681,17 @@ class ConfigureSandbox(dict):
used as per the descripted mapping above.
The `reason` argument indicates what caused the option to be implied.
It is necessary when it cannot be inferred from the `value`.
'''
# Don't do anything when --help was on the command line
if self._help:
return
- if not reason and isinstance(value, DependsFunction):
+ if not reason and isinstance(value, SandboxDependsFunction):
deps = self._depends[value][1]
possible_reasons = [d for d in deps if d != self._help_option]
if len(possible_reasons) == 1:
if isinstance(possible_reasons[0], Option):
reason = possible_reasons[0]
if not reason and (isinstance(value, (bool, tuple)) or
isinstance(value, types.StringTypes)):
# A reason can be provided automatically when imply_option