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

--HG--
extra : rebase_source : 5db9a6b4bb9ef7195c2513407810093bff5e9174
extra : amend_source : f67ab46c2ac00a2a95cfc67e9763ac12b690ac14
This commit is contained in:
Ted Mielczarek 2016-03-17 11:04:12 -04:00
parent b6487df277
commit 8f2baa8e8b
3 changed files with 15 additions and 1 deletions

View File

@ -52,6 +52,8 @@ 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)

View File

@ -7,6 +7,7 @@
@template
@advanced
def warn(*args):
'Print a warning.'
import sys
print(*args, file=sys.stderr)
sys.stderr.flush()
@ -15,12 +16,23 @@ def warn(*args):
@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):

View File

@ -93,7 +93,7 @@ class ConfigureSandbox(dict):
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