Allow get_variable to still function when the fallback is a disabler.

pull/7065/head
James Hilliard 5 years ago committed by Dylan Baker
parent cd566d2bd5
commit d7c24ccddd
  1. 2
      mesonbuild/interpreter.py
  2. 2
      mesonbuild/interpreterbase.py
  3. 28
      test cases/common/163 disabler/meson.build

@ -4661,6 +4661,8 @@ This will become a hard error in the future.''', location=self.current_node)
if len(args) < 1 or len(args) > 2: if len(args) < 1 or len(args) > 2:
raise InvalidCode('Get_variable takes one or two arguments.') raise InvalidCode('Get_variable takes one or two arguments.')
varname = args[0] varname = args[0]
if isinstance(varname, Disabler):
return varname
if not isinstance(varname, str): if not isinstance(varname, str):
raise InterpreterException('First argument must be a string.') raise InterpreterException('First argument must be a string.')
try: try:

@ -819,7 +819,7 @@ The result of this is undefined and will become a hard error in a future Meson r
def function_call(self, node: mparser.FunctionNode) -> T.Optional[TYPE_var]: def function_call(self, node: mparser.FunctionNode) -> T.Optional[TYPE_var]:
func_name = node.func_name func_name = node.func_name
(posargs, kwargs) = self.reduce_arguments(node.args) (posargs, kwargs) = self.reduce_arguments(node.args)
if is_disabled(posargs, kwargs) and func_name != 'set_variable' and func_name != 'is_disabler': if is_disabled(posargs, kwargs) and func_name not in {'get_variable', 'set_variable', 'is_disabler'}:
return Disabler() return Disabler()
if func_name in self.funcs: if func_name in self.funcs:
func = self.funcs[func_name] func = self.funcs[func_name]

@ -9,6 +9,7 @@ d2 = dependency(d)
d3 = (d == d2) d3 = (d == d2)
d4 = d + 0 d4 = d + 0
d5 = d2 or true d5 = d2 or true
set_variable('d6', disabler())
has_not_changed = false has_not_changed = false
if is_disabler(d) if is_disabler(d)
@ -23,12 +24,14 @@ assert(is_disabler(d2), 'Function laundered disabler was not identified correctl
assert(is_disabler(d3), 'Disabler comparison should yield disabler.') assert(is_disabler(d3), 'Disabler comparison should yield disabler.')
assert(is_disabler(d4), 'Disabler addition should yield disabler.') assert(is_disabler(d4), 'Disabler addition should yield disabler.')
assert(is_disabler(d5), 'Disabler logic op should yield disabler.') assert(is_disabler(d5), 'Disabler logic op should yield disabler.')
assert(is_disabler(d6), 'set_variable with a disabler should set variable to disabler.')
assert(d, 'Disabler did not cause this to be skipped.') assert(d, 'Disabler did not cause this to be skipped.')
assert(d2, 'Function laundered disabler did not cause this to be skipped.') assert(d2, 'Function laundered disabler did not cause this to be skipped.')
assert(d3, 'Disabler comparison should yield disabler and thus this would not be called.') assert(d3, 'Disabler comparison should yield disabler and thus this would not be called.')
assert(d4, 'Disabler addition should yield disabler and thus this would not be called.') assert(d4, 'Disabler addition should yield disabler and thus this would not be called.')
assert(d5, 'Disabler logic op should yield disabler and thus this would not be called.') assert(d5, 'Disabler logic op should yield disabler and thus this would not be called.')
assert(d6, 'set_variable with a disabler did not cause this to be skipped.')
number = 0 number = 0
@ -80,6 +83,31 @@ else
endif endif
assert(has_not_changed, 'App has changed.') assert(has_not_changed, 'App has changed.')
assert(not is_disabler(is_variable('d6')), 'is_variable should not return a disabler')
assert(is_variable('d6'), 'is_variable for a disabler should return true')
if_is_not_disabled = false
if is_variable('d6')
if_is_not_disabled = true
else
if_is_not_disabled = true
endif
assert(if_is_not_disabled, 'Disabler in is_variable should not skip blocks')
get_d = get_variable('d6')
assert(is_disabler(get_d), 'get_variable should yield a disabler')
get_fallback_d = get_variable('nonexistant', disabler())
assert(is_disabler(get_fallback_d), 'get_variable fallback should yield a disabler')
var_true = true
get_no_fallback_d = get_variable('var_true', disabler())
assert(not is_disabler(get_no_fallback_d), 'get_variable should not fallback to disabler')
assert(get_no_fallback_d, 'get_variable should yield true')
assert(is_disabler(get_variable(disabler())), 'get_variable should yield a disabler')
assert(is_disabler(get_variable(disabler(), var_true)), 'get_variable should yield a disabler')
if_is_disabled = true if_is_disabled = true
if disabler() if disabler()
if_is_disabled = false if_is_disabled = false

Loading…
Cancel
Save