Bug 1257104 - Allow options with choices and possibly no given values draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 16 Mar 2016 16:44:00 +0900
changeset 341065 fd8576b731c751f4e74fba03afafef3bb89550c8
parent 341064 b709c325a2b24e4019e6690854d4cd251e53f1a5
child 341066 0dfc7675bd65e62af1a48086c7d873c8fb620a9d
push id13127
push userbmo:mh+mozilla@glandium.org
push dateWed, 16 Mar 2016 12:32:02 +0000
Bug 1257104 - Allow options with choices and possibly no given values While rare, this is something we support for e.g. --enable-eme, where it can be either given with no values, "adobe", some future other EME GMP adapter names, or a combination of them.
--- a/python/mozbuild/mozbuild/configure/options.py
+++ b/python/mozbuild/mozbuild/configure/options.py
@@ -214,20 +214,16 @@ class Option(object):
             if has_choices and not all(d in choices for d in self.default):
                 raise InvalidOptionError(
                     'The `default` value must be one of %s' %
                     ', '.join("'%s'" % c for c in choices))
         elif has_choices:
             maxargs = self.maxargs
             if len(choices) < maxargs and maxargs != sys.maxint:
                 raise InvalidOptionError('Not enough `choices` for `nargs`')
-            if self.minargs == 0:
-                raise InvalidOptionError(
-                    '%s is not a valid `nargs` when `choices` are given'
-                    % str(nargs))
         self.choices = choices
         self.help = help
     def split_option(option):
         '''Split a flag or variable into a prefix, a name and values
         Variables come in the form NAME=values (no prefix).
--- a/python/mozbuild/mozbuild/test/configure/test_options.py
+++ b/python/mozbuild/mozbuild/test/configure/test_options.py
@@ -154,28 +154,19 @@ class TestOption(unittest.TestCase):
                               option.replace('-enable-', '-disable-')
                                     .replace('-with-', '-without-'))
         self.assertEquals(Option(env='FOO').option, 'FOO')
     def test_option_choices(self):
         with self.assertRaises(InvalidOptionError):
-            Option('--option', nargs=0, choices=('a', 'b'))
-        with self.assertRaises(InvalidOptionError):
             Option('--option', nargs=3, choices=('a', 'b'))
         with self.assertRaises(InvalidOptionError):
-            Option('--option', nargs='?', choices=('a', 'b'))
-        with self.assertRaises(InvalidOptionError):
-            Option('--option', nargs='*', choices=('a', 'b'))
-        with self.assertRaises(InvalidOptionError):
             Option('--without-option', nargs=1, choices=('a', 'b'))
         with self.assertRaises(InvalidOptionError):
             Option('--without-option', nargs='+', choices=('a', 'b'))
         with self.assertRaises(InvalidOptionError):
             Option('--without-option', default='c', choices=('a', 'b'))