bug 1257542 - check_prog template should sanity check that progs is not a string. r?glandium draft
authorTed Mielczarek <ted@mielczarek.org>
Thu, 17 Mar 2016 11:04:12 -0400
changeset 341645 cab3a89b20c3cf6c18a8c477cbb732e8b3217180
parent 341644 5d3872081ea9fb9ee9d8d5ed0ef3de35270ebd0b
child 341741 cd659f108547f65e82de9e1c791ae87dbbdac38a
push id13256
push usertmielczarek@mozilla.com
push dateThu, 17 Mar 2016 15:05:14 +0000
reviewersglandium
bugs1257542
milestone48.0a1
bug 1257542 - check_prog template should sanity check that progs is not a string. r?glandium In Python parens around an expression without a trailing comma is not a tuple, so ('foo') == 'foo'. This is really easy to screw up with check_progs, which coerces progs to a list and would give you ['f','o','o'] in this case. This patch enforces that the progs argument is a tuple or list and errors if it is not. MozReview-Commit-ID: 7BJZuF9B8D5
build/moz.configure/checks.configure
build/moz.configure/util.configure
python/mozbuild/mozbuild/configure/__init__.py
--- a/build/moz.configure/checks.configure
+++ b/build/moz.configure/checks.configure
@@ -47,16 +47,18 @@ def checking(what):
 # will look for 'a' or 'b' in $PATH, and set_config PROG to the one
 # it can find. If PROG is already set from the environment or command line,
 # use that value instead.
 @template
 def check_prog(var, progs, allow_missing=False):
     option(env=var, nargs=1, help='Path to the %s program' % var.lower())
 
     not_found = 'not found'
+    if not (isinstance(progs, tuple) or isinstance(progs, list)):
+        configure_error('progs should be a list or tuple!')
     progs = list(progs)
 
     @depends(var)
     @checking('for %s' % var.lower())
     def check(value):
         if value:
             progs[:] = value
         for prog in progs:
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -18,16 +18,23 @@ def error(*args):
     import sys
     print(*args, file=sys.stderr)
     sys.stderr.flush()
     sys.exit(1)
 
 
 @template
 @advanced
+def configure_error(message):
+    from mozbuild.configure import ConfigureError
+    raise ConfigureError(message)
+
+
+@template
+@advanced
 def is_absolute_or_relative(path):
     import os
     if os.altsep and os.altsep in path:
         return True
     return os.sep in path
 
 
 @template
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -88,17 +88,17 @@ class ConfigureSandbox(dict):
         sandbox.run(path)
         do_stuff(config)
     """
 
     # The default set of builtins.
     BUILTINS = ReadOnlyDict({
         b: __builtins__[b]
         for b in ('None', 'False', 'True', 'int', 'bool', 'any', 'all', 'len',
-                  'list', 'set', 'dict')
+                  'list', 'set', 'dict', 'isinstance', 'tuple')
     }, __import__=forbidden_import)
 
     # Expose a limited set of functions from os.path
     OS = ReadOnlyNamespace(path=ReadOnlyNamespace(
         abspath=mozpath.abspath,
         basename=mozpath.basename,
         dirname=mozpath.dirname,
         exists=os.path.exists,