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
--- 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,