bug 1257542 - check_prog template should sanity check that progs is not a string. r=glandium
authorTed Mielczarek <ted@mielczarek.org>
Thu, 17 Mar 2016 11:04:12 -0400
changeset 327234 a5bd947546623f30a25113b0bb996d781ff938f2
parent 327233 7960c66bd18957d88369ba0028000d5197564a81
child 327235 e1e446ee68823667291e2d6136398f1c948b925d
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1257542
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 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
@@ -2,32 +2,44 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 @template
 @advanced
 def warn(*args):
+    'Print a warning.'
     import sys
     print(*args, file=sys.stderr)
     sys.stderr.flush()
 
 
 @template
 @advanced
 def error(*args):
+    'Print an error and terminate configure.'
     import sys
     print(*args, file=sys.stderr)
     sys.stderr.flush()
     sys.exit(1)
 
 
 @template
 @advanced
+def configure_error(message):
+    '''Raise a programming error and terminate configure.
+    Primarily for use in moz.configure templates to sanity check
+    their inputs from moz.configure usage.'''
+    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', 'tuple', 'set', 'dict', 'isinstance')
     }, __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,