Skip to content

Commit

Permalink
Merge pull request mesonbuild#6011 from xclaesse/not-disabler
Browse files Browse the repository at this point in the history
Fix `if not disabler()` case
  • Loading branch information
jpakkane authored Oct 9, 2019
2 parents b8fbbf5 + 9855b2d commit 34ea712
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mesonbuild/interpreterbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ def evaluate_dictstatement(self, cur):

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
Expand Down Expand Up @@ -680,8 +682,6 @@ def evaluate_foreach(self, node):
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:
Expand All @@ -693,8 +693,6 @@ def evaluate_foreach(self, node):
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)
Expand Down
44 changes: 44 additions & 0 deletions test cases/common/163 disabler/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,47 @@ 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')

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')

0 comments on commit 34ea712

Please sign in to comment.