From 79b309644997caa28d446d6a4fcbe8bedc9af783 Mon Sep 17 00:00:00 2001 From: Sambuddha Basu Date: Thu, 18 Feb 2016 17:26:09 -0800 Subject: [PATCH] Bug 952564 - Disallow empty lists in moz.build variables r=gps --HG-- extra : rebase_source : 9a70b6a3150fe898a724a43815dc923bb0d70b89 extra : amend_source : 7aa800ef61427117e5dc461443f82ebd403d8164 --- dom/media/webspeech/synth/moz.build | 2 -- python/mozbuild/mozbuild/frontend/sandbox.py | 4 ++++ .../data/reader-error-empty-list/moz.build | 5 +++++ .../mozbuild/test/frontend/test_reader.py | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 python/mozbuild/mozbuild/test/frontend/data/reader-error-empty-list/moz.build diff --git a/dom/media/webspeech/synth/moz.build b/dom/media/webspeech/synth/moz.build index de03c2fc4a4a..4a2eae08e783 100644 --- a/dom/media/webspeech/synth/moz.build +++ b/dom/media/webspeech/synth/moz.build @@ -41,8 +41,6 @@ if CONFIG['MOZ_WEBSPEECH']: 'test/nsFakeSynthServices.cpp' ] - DIRS = [] - if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': DIRS += ['windows'] diff --git a/python/mozbuild/mozbuild/frontend/sandbox.py b/python/mozbuild/mozbuild/frontend/sandbox.py index 0ae8e30daefb..9f2666f8c51b 100644 --- a/python/mozbuild/mozbuild/frontend/sandbox.py +++ b/python/mozbuild/mozbuild/frontend/sandbox.py @@ -286,6 +286,10 @@ class Sandbox(dict): if key in self._context and self._context[key] is not value: raise KeyError('global_ns', 'reassign', key) + if (key not in self._context and isinstance(value, (list, dict)) + and not value): + raise KeyError('Variable %s assigned an empty value.' % key) + self._context[key] = value else: dict.__setitem__(self, key, value) diff --git a/python/mozbuild/mozbuild/test/frontend/data/reader-error-empty-list/moz.build b/python/mozbuild/mozbuild/test/frontend/data/reader-error-empty-list/moz.build new file mode 100644 index 000000000000..fc4ce0217978 --- /dev/null +++ b/python/mozbuild/mozbuild/test/frontend/data/reader-error-empty-list/moz.build @@ -0,0 +1,5 @@ +# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +DIRS = [] diff --git a/python/mozbuild/mozbuild/test/frontend/test_reader.py b/python/mozbuild/mozbuild/test/frontend/test_reader.py index 730588b71823..d50a0658354a 100644 --- a/python/mozbuild/mozbuild/test/frontend/test_reader.py +++ b/python/mozbuild/mozbuild/test/frontend/test_reader.py @@ -11,8 +11,10 @@ import unittest from mozunit import main from mozbuild.frontend.context import BugzillaComponent -from mozbuild.frontend.reader import BuildReaderError -from mozbuild.frontend.reader import BuildReader +from mozbuild.frontend.reader import ( + BuildReaderError, + BuildReader, +) from mozbuild.test.common import MockConfig @@ -246,6 +248,15 @@ class TestBuildReader(unittest.TestCase): contexts = list(reader.read_topsrcdir()) + def test_error_empty_list(self): + reader = self.reader('reader-error-empty-list') + + with self.assertRaises(BuildReaderError) as bre: + list(reader.read_topsrcdir()) + + e = bre.exception + self.assertIn('Variable DIRS assigned an empty value.', str(e)) + def test_inheriting_variables(self): reader = self.reader('inheriting-variables')