Bug 946175 - Forbid assigning over a value previously set in moz.build. r=gps

This commit is contained in:
Mike Hommey 2013-12-09 13:34:00 +09:00
Родитель 10f157bdfb
Коммит 211d8bd0de
8 изменённых файлов: 43 добавлений и 14 удалений

Просмотреть файл

@ -4,8 +4,6 @@
# 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/.
FAIL_ON_WARNINGS = True
XPIDL_SOURCES += [
'nsIWifiAccessPoint.idl',
'nsIWifiListener.idl',
@ -27,9 +25,10 @@ else:
'nsWifiMonitor.cpp',
]
# osx_corewlan.mm has warnings I don't understand.
FAIL_ON_WARNINGS = CONFIG['OS_ARCH'] != 'Darwin'
if CONFIG['OS_ARCH'] == 'Darwin':
# osx_corewlan.mm has warnings I don't understand.
FAIL_ON_WARNINGS = False
UNIFIED_SOURCES += [
'nsWifiScannerMac.cpp',
]

Просмотреть файл

@ -185,9 +185,9 @@ class MozbuildSandbox(Sandbox):
for name, func in FUNCTIONS.items():
d[name] = getattr(self, func[0])
# Initialize the exports that we need in the global.
extra_vars = self.metadata.get('exports', dict())
self._globals.update(extra_vars)
# Initialize the exports that we need in the global.
extra_vars = self.metadata.get('exports', dict())
self._globals.update(extra_vars)
def exec_file(self, path, filesystem_absolute=False):
"""Override exec_file to normalize paths and restrict file loading.

Просмотреть файл

@ -124,6 +124,8 @@ class GlobalNamespace(dict):
self._allow_all_writes = False
self._allow_one_mutation = set()
def __getitem__(self, name):
try:
return dict.__getitem__(self, name)
@ -151,8 +153,21 @@ class GlobalNamespace(dict):
def __setitem__(self, name, value):
if self._allow_all_writes:
dict.__setitem__(self, name, value)
self._allow_one_mutation.add(name)
return
# Forbid assigning over a previously set value. Interestingly, when
# doing FOO += ['bar'], python actually does something like:
# foo = namespace.__getitem__('FOO')
# foo.__iadd__(['bar'])
# namespace.__setitem__('FOO', foo)
# This means __setitem__ is called with the value that is already
# in the dict, when doing +=, which is permitted.
if name in self._allow_one_mutation:
self._allow_one_mutation.remove(name)
elif name in self and dict.__getitem__(self, name) is not value:
raise Exception('Reassigning %s is forbidden' % name)
# We don't need to check for name.isupper() here because LocalNamespace
# only sends variables our way if isupper() is True.
stored_type, input_type, docs, tier = \
@ -195,6 +210,11 @@ class GlobalNamespace(dict):
yield self
self._allow_all_writes = False
# dict.update doesn't call our __setitem__, so we have to override it.
def update(self, other):
for name, value in other.items():
self.__setitem__(name, value)
class LocalNamespace(dict):
"""Represents the locals namespace in a Sandbox.

Просмотреть файл

@ -3,5 +3,3 @@
# 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/.
XPIDL_MODULE = 'bazbar'

Просмотреть файл

@ -76,10 +76,23 @@ class TestGlobalNamespace(unittest.TestCase):
self.assertTrue(d['foo'])
with self.assertRaises(KeyError) as ke:
ns['foo'] = False
ns['bar'] = False
self.assertEqual(ke.exception.args[1], 'set_unknown')
ns['DIRS'] = []
with self.assertRaisesRegexp(Exception, 'Reassigning .* is forbidden') as ke:
ns['DIRS'] = []
with ns.allow_all_writes() as d:
d['DIST_SUBDIR'] = 'foo'
self.assertEqual(ns['DIST_SUBDIR'], 'foo')
ns['DIST_SUBDIR'] = 'bar'
self.assertEqual(ns['DIST_SUBDIR'], 'bar')
with self.assertRaisesRegexp(Exception, 'Reassigning .* is forbidden') as ke:
ns['DIST_SUBDIR'] = 'baz'
self.assertTrue(d['foo'])
def test_key_checking(self):

Просмотреть файл

@ -262,7 +262,7 @@ class TestBuildReader(unittest.TestCase):
self.assertEqual([sandbox['RELATIVEDIR'] for sandbox in sandboxes],
['', 'foo', 'foo/baz', 'bar'])
self.assertEqual([sandbox['XPIDL_MODULE'] for sandbox in sandboxes],
['foobar', 'foobar', 'foobar', 'bazbar'])
['foobar', 'foobar', 'foobar', 'foobar'])
if __name__ == '__main__':
main()

Просмотреть файл

@ -146,9 +146,9 @@ class TestSandbox(unittest.TestCase):
sandbox = self.sandbox()
sandbox.exec_source('DIRS = ["foo"]', 'foo.py')
sandbox.exec_source('DIRS = ["bar"]', 'foo.py')
sandbox.exec_source('DIRS += ["bar"]', 'foo.py')
self.assertEqual(sandbox['DIRS'], ['bar'])
self.assertEqual(sandbox['DIRS'], ['foo', 'bar'])
def test_exec_source_illegal_key_set(self):
sandbox = self.sandbox()

Просмотреть файл

@ -13,7 +13,6 @@ EXPORTS += [
]
XPIDL_MODULE = 'diskspacewatcher'
XPIDL_MODULE = 'toolkitcomps'
SOURCES = [
'DiskSpaceWatcher.cpp',