Bug 1363585 - Forbid boolean operations on @depends functions. r=chmanchester

Doing something like "not foo" when foo is a @depends function is never
going to do what the user expects, while not necessarily leading to an
error (like, when used in set_config).

It is better to have an error in those cases where it's expected not to
work, at the expense of making templates a little more verbose, rather
than silently do something the user is not expecting.

--HG--
extra : rebase_source : 87ba80eccc5606322f6dd185d5cb5fc88471e51b
This commit is contained in:
Mike Hommey 2017-05-10 11:35:22 +09:00
parent f57ed7a6e8
commit 563880df0e
4 changed files with 18 additions and 8 deletions

View File

@ -95,7 +95,7 @@ def checking(what, callback=None):
@imports(_from='mozbuild.shellutil', _import='quote')
def check_prog(var, progs, what=None, input=None, allow_missing=False,
paths=None):
if input:
if input is not None:
# Wrap input with type checking and normalization.
@depends(input)
def input(value):

View File

@ -45,7 +45,8 @@ def try_compile(includes=None, body='', language='C++', flags=None, check_msg=No
# conditional on the value of that function.
@template
def check_header(header, language='C++', flags=None, includes=None, when=None):
when = when or always
if when is None:
when = always
if includes:
includes = includes[:]
@ -97,12 +98,13 @@ def warnings_cxxflags():
# for add_gcc_warning().
@template
def check_and_add_gcc_warning(warning, compiler=None, when=None, check=True):
if compiler:
if compiler is not None:
compilers = (compiler,)
else:
compilers = (c_compiler, cxx_compiler)
when = when or always
if when is None:
when = always
for c in compilers:
assert c in (c_compiler, cxx_compiler)

View File

@ -565,9 +565,10 @@ def compiler(language, host_or_target, c_compiler=None, other_compiler=None,
'''
assert host_or_target in (host, target)
assert language in ('C', 'C++')
assert language == 'C' or c_compiler
assert host_or_target == target or other_compiler
assert language == 'C' or host_or_target == target or other_c_compiler
assert language == 'C' or c_compiler is not None
assert host_or_target == target or other_compiler is not None
assert language == 'C' or host_or_target == target or \
other_c_compiler is not None
host_or_target_str = {
host: 'host',
@ -619,7 +620,10 @@ def compiler(language, host_or_target, c_compiler=None, other_compiler=None,
# executable, when cross compiling with clang, default to the same compiler
# as the target compiler, resetting flags.
if host_or_target == host:
args = (c_compiler, other_c_compiler) if other_c_compiler else ()
if other_c_compiler is not None:
args = (c_compiler, other_c_compiler)
else:
args = ()
@depends(provided_compiler, other_compiler, cross_compiling, *args)
def provided_compiler(value, other_compiler, cross_compiling, *args):

View File

@ -57,6 +57,10 @@ class SandboxDependsFunction(object):
'with another @depends function.')
return self._or(other).sandboxed
def __nonzero__(self):
raise ConfigureError(
'Cannot do boolean operations on @depends functions.')
class DependsFunction(object):
__slots__ = (