Bug 1256573 - Switch configure tests to use @imports instead of @advanced. r=nalexander
authorMike Hommey <mh+mozilla@glandium.org>
Sun, 27 Mar 2016 11:14:48 +0900
changeset 290991 89b86fc355d7611a3a43872ee047bd32d651ddd1
parent 290990 96ef4c62378d5ddabb8c27c745bc928517273c20
child 290992 f4e24db79431e447e3f6b2758ec6dba4dca817c2
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1256573
milestone48.0a1
Bug 1256573 - Switch configure tests to use @imports instead of @advanced. r=nalexander
python/mozbuild/mozbuild/test/configure/data/included.configure
python/mozbuild/mozbuild/test/configure/data/moz.configure
python/mozbuild/mozbuild/test/configure/test_configure.py
--- a/python/mozbuild/mozbuild/test/configure/data/included.configure
+++ b/python/mozbuild/mozbuild/test/configure/data/included.configure
@@ -36,23 +36,21 @@ set_config('TEMPLATE_VALUE', check)
 @depends(is_gcc)
 def check(value):
     if value:
         for val in twentyone():
             return val
 
 set_config('TEMPLATE_VALUE_2', check)
 
-# Templates can use @advanced too to import modules and get the full set of
-# builtins.
+# Templates can use @imports too to import modules.
 @template
-@advanced
+@imports('sys')
 def platform():
-    import sys
     return sys.platform
 
-option('--enable-advanced-template', help='Advanced template')
-@depends('--enable-advanced-template')
+option('--enable-imports-in-template', help='Imports in template')
+@depends('--enable-imports-in-template')
 def check(value):
     if value:
         return platform()
 
 set_config('PLATFORM', check)
--- a/python/mozbuild/mozbuild/test/configure/data/moz.configure
+++ b/python/mozbuild/mozbuild/test/configure/data/moz.configure
@@ -137,56 +137,56 @@ include('included.configure')
 # defaults and choices.
 option('--enable-include', nargs=1, help='Include')
 @depends('--enable-include', '--help')
 def include_path(path, help):
     return path[0] if path else None
 
 include(include_path)
 
-# @advanced functions are allowed to import modules and have access to
-# the standard builtins instead of restricted ones. The order of the decorators
-# matter: @advanced needs to appear last.
-option('--with-advanced', nargs='?', help='Advanced')
-@depends('--with-advanced')
-@advanced
-def with_advanced(value):
+# Sandboxed functions can import from modules through the use of the @imports
+# decorator.
+# The order of the decorators matter: @imports needs to appear after other
+# decorators.
+option('--with-imports', nargs='?', help='Imports')
+@depends('--with-imports')
+@imports(_from='mozbuild.configure.options', _import='OptionValue')
+def with_imports(value):
     if value:
-        from mozbuild.configure.options import OptionValue
         return isinstance(value, OptionValue)
 
-set_config('ADVANCED', with_advanced)
+set_config('IMPORTS', with_imports)
 
-# Trying to import without @advanced will fail at runtime.
-@depends('--with-advanced')
-def with_advanced(value):
+# Trying to import manually will fail at runtime.
+@depends('--with-imports')
+def with_imports(value):
     if len(value) and value[0] == 'break':
         from mozbuild.configure.options import OptionValue
         return isinstance(value, OptionValue)
 
-set_config('ADVANCED2', with_advanced)
+set_config('IMPORTS2', with_imports)
 
-# A limited set of functions from os.path are exposed to non @advanced
-# functions.
-@depends('--with-advanced')
-def with_advanced(value):
+# A limited set of functions from os.path are exposed by default.
+@depends('--with-imports')
+def with_imports(value):
     if len(value):
         return os.path.isfile(value[0])
 
-set_config('IS_FILE', with_advanced)
+set_config('IS_FILE', with_imports)
 
-# An @advanced function can still import the full set.
-@depends('--with-advanced')
-@advanced
-def with_advanced(value):
-    if len(value):
-        import os.path
-        return hasattr(os.path, 'getatime')
-
-set_config('HAS_GETATIME', with_advanced)
-
-@depends('--with-advanced')
-@advanced
-def with_advanced(value):
+# It is still possible to import the full set from os.path.
+# It is also possible to cherry-pick builtins.
+@depends('--with-imports')
+@imports('os.path')
+@imports(_from='__builtin__', _import='hasattr')
+def with_imports(value):
     if len(value):
         return hasattr(os.path, 'getatime')
 
-set_config('HAS_GETATIME2', with_advanced)
+set_config('HAS_GETATIME', with_imports)
+
+@depends('--with-imports')
+@imports(_from='__builtin__', _import='hasattr')
+def with_imports(value):
+    if len(value):
+        return hasattr(os.path, 'getatime')
+
+set_config('HAS_GETATIME2', with_imports)
--- a/python/mozbuild/mozbuild/test/configure/test_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_configure.py
@@ -72,20 +72,20 @@ class TestConfigure(unittest.TestCase):
             '  --enable-simple           Enable simple\n'
             '  --enable-with-env         Enable with env\n'
             '  --enable-values           Enable values\n'
             '  --without-thing           Build without thing\n'
             '  --with-stuff              Build with stuff\n'
             '  --option                  Option\n'
             '  --with-returned-default   Returned default [not-simple]\n'
             '  --returned-choices        Choices\n'
-            '  --enable-advanced-template\n'
-            '                            Advanced template\n'
+            '  --enable-imports-in-template\n'
+            '                            Imports in template\n'
             '  --enable-include          Include\n'
-            '  --with-advanced           Advanced\n'
+            '  --with-imports            Imports\n'
             '\n'
             'Environment variables:\n'
             '  CC                        C Compiler\n',
             out
         )
 
     def test_unknown(self):
         with self.assertRaises(InvalidOptionError):
@@ -222,23 +222,23 @@ class TestConfigure(unittest.TestCase):
     def test_template(self):
         config = self.get_config(env={'CC': 'gcc'})
         self.assertIn('CFLAGS', config)
         self.assertEquals(config['CFLAGS'], ['-Werror=foobar'])
 
         config = self.get_config(env={'CC': 'clang'})
         self.assertNotIn('CFLAGS', config)
 
-    def test_advanced(self):
-        config = self.get_config(['--with-advanced'])
-        self.assertIn('ADVANCED', config)
-        self.assertEquals(config['ADVANCED'], True)
+    def test_imports(self):
+        config = self.get_config(['--with-imports'])
+        self.assertIn('IMPORTS', config)
+        self.assertEquals(config['IMPORTS'], True)
 
         with self.assertRaises(ImportError):
-            self.get_config(['--with-advanced=break'])
+            self.get_config(['--with-imports=break'])
 
     def test_imports(self):
         config = {}
         out = StringIO()
         sandbox = ConfigureSandbox(config, {}, [], out, out)
 
         with self.assertRaises(ImportError):
             exec(textwrap.dedent('''
@@ -334,38 +334,38 @@ class TestConfigure(unittest.TestCase):
 
         self.assertIs(sandbox['foo'](), sandbox)
 
         # Nothing leaked from the function being executed
         self.assertEquals(sandbox.keys(), ['__builtins__', 'foo'])
         self.assertEquals(sandbox['__builtins__'], ConfigureSandbox.BUILTINS)
 
     def test_os_path(self):
-        config = self.get_config(['--with-advanced=%s' % __file__])
+        config = self.get_config(['--with-imports=%s' % __file__])
         self.assertIn('IS_FILE', config)
         self.assertEquals(config['IS_FILE'], True)
 
-        config = self.get_config(['--with-advanced=%s.no-exist' % __file__])
+        config = self.get_config(['--with-imports=%s.no-exist' % __file__])
         self.assertIn('IS_FILE', config)
         self.assertEquals(config['IS_FILE'], False)
 
         self.assertIn('HAS_GETATIME', config)
         self.assertEquals(config['HAS_GETATIME'], True)
         self.assertIn('HAS_GETATIME2', config)
         self.assertEquals(config['HAS_GETATIME2'], False)
 
     def test_template_call(self):
         config = self.get_config(env={'CC': 'gcc'})
         self.assertIn('TEMPLATE_VALUE', config)
         self.assertEquals(config['TEMPLATE_VALUE'], 42)
         self.assertIn('TEMPLATE_VALUE_2', config)
         self.assertEquals(config['TEMPLATE_VALUE_2'], 21)
 
-    def test_template_advanced(self):
-        config = self.get_config(['--enable-advanced-template'])
+    def test_template_imports(self):
+        config = self.get_config(['--enable-imports-in-template'])
         self.assertIn('PLATFORM', config)
         self.assertEquals(config['PLATFORM'], sys.platform)
 
     def test_decorators(self):
         config = {}
         out = StringIO()
         sandbox = ConfigureSandbox(config, {}, [], out, out)