From 1930fc82e24a72625cd851903c22d893e4817a3c Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 8 Oct 2019 11:02:00 -0400 Subject: [PATCH 1/2] Fix `if not disabler()` case Closes: #6010 --- mesonbuild/interpreterbase.py | 2 ++ test cases/common/163 disabler/meson.build | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index 082515c45..5c8390029 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -500,6 +500,8 @@ class InterpreterBase: def evaluate_notstatement(self, cur): v = self.evaluate_statement(cur.value) + if is_disabler(v): + return v if not isinstance(v, bool): raise InterpreterException('Argument to "not" is not a boolean.') return not v diff --git a/test cases/common/163 disabler/meson.build b/test cases/common/163 disabler/meson.build index 5eb24ba11..8da2a0bd1 100644 --- a/test cases/common/163 disabler/meson.build +++ b/test cases/common/163 disabler/meson.build @@ -76,3 +76,25 @@ else has_not_changed = true endif assert(has_not_changed, 'App has changed.') + +if_is_disabled = true +if disabler() + if_is_disabled = false +else + if_is_disabled = false +endif +assert(if_is_disabled, 'Disabler in "if condition" must skip both blocks') + +if not disabler() + if_is_disabled = false +else + if_is_disabled = false +endif +assert(if_is_disabled, 'Disabler in "if not condition" must skip both blocks') + +if disabler() == 1 + if_is_disabled = false +else + if_is_disabled = false +endif +assert(if_is_disabled, 'Disabler in "if a==b" must skip both blocks') From 9855b2d3c58800f485355229102212eaebf6645a Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 8 Oct 2019 12:09:01 -0400 Subject: [PATCH 2/2] Test disabler in foreach loops The is_disabler() check in evaluate_foreach() was useless because we already checked that items is a list. --- mesonbuild/interpreterbase.py | 4 ---- test cases/common/163 disabler/meson.build | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index 5c8390029..562ba273c 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -682,8 +682,6 @@ The result of this is undefined and will become a hard error in a future Meson r if len(node.varnames) != 1: raise InvalidArguments('Foreach on array does not unpack') varname = node.varnames[0].value - if is_disabler(items): - return items for item in items: self.set_variable(varname, item) try: @@ -695,8 +693,6 @@ The result of this is undefined and will become a hard error in a future Meson r elif isinstance(items, dict): if len(node.varnames) != 2: raise InvalidArguments('Foreach on dict unpacks key and value') - if is_disabler(items): - return items for key, value in items.items(): self.set_variable(node.varnames[0].value, key) self.set_variable(node.varnames[1].value, value) diff --git a/test cases/common/163 disabler/meson.build b/test cases/common/163 disabler/meson.build index 8da2a0bd1..1f0580cb5 100644 --- a/test cases/common/163 disabler/meson.build +++ b/test cases/common/163 disabler/meson.build @@ -98,3 +98,25 @@ else if_is_disabled = false endif assert(if_is_disabled, 'Disabler in "if a==b" must skip both blocks') + +loops = 0 +disablers = 0 +foreach i : [true, disabler(), true] + loops += 1 + if is_disabler(i) + disablers += 1 + endif +endforeach +assert(loops == 3, 'Disabler in foreach array') +assert(disablers == 1, 'Disabler in foreach array') + +loops = 0 +disablers = 0 +foreach k, i : {'a': true, 'b': disabler(), 'c': true} + loops += 1 + if is_disabler(i) + disablers += 1 + endif +endforeach +assert(loops == 3, 'Disabler in foreach dict') +assert(disablers == 1, 'Disabler in foreach dict')