Bug 1378410 - 2a. Expose `set` to moz.build sandbox; r=gps
To construct an empty set, we need to use the `set()` notation. In order
to do that, we need to expose `set` to the moz.build sandbox.
MozReview-Commit-ID: DMyKnF0FEx2
--- a/build/docs/mozbuild-files.rst
+++ b/build/docs/mozbuild-files.rst
@@ -29,20 +29,20 @@ The following properties make execution
1. The execution environment exposes a limited subset of Python.
2. There is a special set of global symbols and an enforced naming
convention of symbols.
3. Some symbols are inherited from previously-executed ``moz.build``
files.
The limited subset of Python is actually an extremely limited subset.
-Only a few symbols from ``__builtins__`` are exposed. These include
-``True``, ``False``, and ``None``. Global functions like ``import``,
-``print``, and ``open`` aren't available. Without these, ``moz.build``
-files can do very little. *This is by design*.
+Only a few symbols from ``__builtin__`` are exposed. These include
+``True``, ``False``, ``None``, ``sorted``, ``int``, and ``set``. Global
+functions like ``import``, ``print``, and ``open`` aren't available.
+Without these, ``moz.build`` files can do very little. *This is by design*.
The execution sandbox treats all ``UPPERCASE`` variables specially. Any
``UPPERCASE`` variable must be known to the sandbox before the script
executes. Any attempt to read or write to an unknown ``UPPERCASE``
variable will result in an exception being raised. Furthermore, the
types of all ``UPPERCASE`` variables is strictly enforced. Attempts to
assign an incompatible type to an ``UPPERCASE`` variable will result in
an exception being raised.
--- a/python/mozbuild/mozbuild/frontend/sandbox.py
+++ b/python/mozbuild/mozbuild/frontend/sandbox.py
@@ -105,16 +105,17 @@ class Sandbox(dict):
# The default set of builtins.
BUILTINS = ReadOnlyDict({
# Only real Python built-ins should go here.
'None': None,
'False': False,
'True': True,
'sorted': alphabetical_sorted,
'int': int,
+ 'set': set,
})
def __init__(self, context, builtins=None, finder=default_finder):
"""Initialize a Sandbox ready for execution.
"""
self._builtins = builtins or self.BUILTINS
dict.__setitem__(self, '__builtins__', self._builtins)