Bug 1311069 - Don't throw InvalidOptionError exceptions when a non-available option was set from an environment variable. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 19 Oct 2016 09:06:41 +0900
changeset 345355 83a03cc29bb7674645a46b805cafdc75502f2afe
parent 345354 39b93a343b1be0e8214be4beb0df0b9903d273cb
child 345356 313322c0bd154030f7dbe670a880f68ee7cc4e27
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1311069
milestone52.0a1
Bug 1311069 - Don't throw InvalidOptionError exceptions when a non-available option was set from an environment variable. r=chmanchester
python/mozbuild/mozbuild/configure/__init__.py
python/mozbuild/mozbuild/test/configure/test_configure.py
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -470,18 +470,23 @@ class ConfigureSandbox(dict):
                 % (e.arg, reason, e.old_arg, e.old_origin))
 
         if option_string:
             self._raw_options[option] = option_string
 
         when = self._conditions.get(option)
         if (when and not self._value_for(when, need_help_dependency=True) and
             value is not None and value.origin != 'default'):
+            if value.origin == 'environment':
+                # The value we return doesn't really matter, because of the
+                # requirement for @depends to have the same when.
+                return None
             raise InvalidOptionError(
-                '%s is not available in this configuration' % option_string)
+                '%s is not available in this configuration'
+                % option_string.split('=', 1)[0])
 
         return value
 
     def _dependency(self, arg, callee_name, arg_name=None):
         if isinstance(arg, types.StringTypes):
             prefix, name, values = Option.split_option(arg)
             if values != ():
                 raise ConfigureError("Option must not contain an '='")
--- a/python/mozbuild/mozbuild/test/configure/test_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_configure.py
@@ -769,17 +769,17 @@ class TestConfigure(unittest.TestCase):
             @depends('--help')
             def always(_):
                 return True
             @depends('--help')
             def never(_):
                 return False
             option('--with-foo', help='foo', when=always)
             option('--with-bar', help='bar', when=never)
-            option('--with-qux', help='qux', when='--with-foo')
+            option('--with-qux', env="QUX", help='qux', when='--with-foo')
 
             set_config('FOO', depends('--with-foo', when=always)(lambda x: x))
             set_config('BAR', depends('--with-bar', when=never)(lambda x: x))
             set_config('QUX', depends('--with-qux', when='--with-foo')(lambda x: x))
         '''):
             config = self.get_config()
             self.assertEquals(config, {
                 'FOO': NegativeOptionValue(),
@@ -808,16 +808,29 @@ class TestConfigure(unittest.TestCase):
             with self.assertRaises(InvalidOptionError) as e:
                 self.get_config(['--with-qux'])
 
             self.assertEquals(
                 e.exception.message,
                 '--with-qux is not available in this configuration'
             )
 
+            with self.assertRaises(InvalidOptionError) as e:
+                self.get_config(['QUX=1'])
+
+            self.assertEquals(
+                e.exception.message,
+                'QUX is not available in this configuration'
+            )
+
+            config = self.get_config(env={'QUX': '1'})
+            self.assertEquals(config, {
+                'FOO': NegativeOptionValue(),
+            })
+
             help, config = self.get_config(['--help'])
             self.assertEquals(help, textwrap.dedent('''\
                 Usage: configure [options]
 
                 Options: [defaults in brackets after descriptions]
                   --help                    print this message
                   --with-foo                foo