Bug 1257104 - Allow options with choices and possibly no given values. r=ted
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 16 Mar 2016 16:44:00 +0900
changeset 289057 9689998f67d4fe656592a5c838bb6ccc07fd5649
parent 289056 c7969fc23e51c269bf9cbcce200dc05e26214dc8
child 289058 732831f18167727c126dcc0be83f69093dc57141
push id73687
push usermh@glandium.org
push dateWed, 16 Mar 2016 22:22:08 +0000
treeherdermozilla-inbound@744e0f1f8d9b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1257104
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1257104 - Allow options with choices and possibly no given values. r=ted 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.
python/mozbuild/mozbuild/configure/options.py
python/mozbuild/mozbuild/test/configure/test_options.py
--- 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
 
     @staticmethod
     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):
             self.assertEquals(opt.option,
                               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'))