From 563880df0e359ab83a03342831813257302224e7 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 10 May 2017 11:35:22 +0900 Subject: [PATCH] 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 --- build/moz.configure/checks.configure | 2 +- build/moz.configure/compile-checks.configure | 8 +++++--- build/moz.configure/toolchain.configure | 12 ++++++++---- python/mozbuild/mozbuild/configure/__init__.py | 4 ++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/build/moz.configure/checks.configure b/build/moz.configure/checks.configure index 8c2dbc0cc4c3..07ec0bab12cc 100644 --- a/build/moz.configure/checks.configure +++ b/build/moz.configure/checks.configure @@ -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): diff --git a/build/moz.configure/compile-checks.configure b/build/moz.configure/compile-checks.configure index 82a0343c9c57..8ea4538d97a7 100644 --- a/build/moz.configure/compile-checks.configure +++ b/build/moz.configure/compile-checks.configure @@ -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) diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure index cc330558b485..1590576eaf4a 100644 --- a/build/moz.configure/toolchain.configure +++ b/build/moz.configure/toolchain.configure @@ -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): diff --git a/python/mozbuild/mozbuild/configure/__init__.py b/python/mozbuild/mozbuild/configure/__init__.py index 67f1597a1d12..478bcf72af44 100644 --- a/python/mozbuild/mozbuild/configure/__init__.py +++ b/python/mozbuild/mozbuild/configure/__init__.py @@ -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__ = (