aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Hilliard <james.hilliard1@gmail.com>2020-04-26 19:30:42 -0600
committerDylan Baker <dylan@pnwbakers.com>2020-04-30 13:06:56 -0700
commitd7c24ccddd13b4b36d63df1908cfa886f9fb7324 (patch)
tree27b100f4dc16a6f1e5bcb0497ba0e3e0455329b3
parentcd566d2bd5f2f1faa3576b51b6b47c74a7ed0392 (diff)
downloadmeson-d7c24ccddd13b4b36d63df1908cfa886f9fb7324.zip
meson-d7c24ccddd13b4b36d63df1908cfa886f9fb7324.tar.gz
meson-d7c24ccddd13b4b36d63df1908cfa886f9fb7324.tar.bz2
Allow get_variable to still function when the fallback is a disabler.
-rw-r--r--mesonbuild/interpreter.py2
-rw-r--r--mesonbuild/interpreterbase.py2
-rw-r--r--test cases/common/163 disabler/meson.build28
3 files changed, 31 insertions, 1 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index dd1e57b..441f3c4 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -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:
raise InvalidCode('Get_variable takes one or two arguments.')
varname = args[0]
+ if isinstance(varname, Disabler):
+ return varname
if not isinstance(varname, str):
raise InterpreterException('First argument must be a string.')
try:
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 1a7aa38..6246a06 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -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]:
func_name = node.func_name
(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()
if func_name in self.funcs:
func = self.funcs[func_name]
diff --git a/test cases/common/163 disabler/meson.build b/test cases/common/163 disabler/meson.build
index 5554f14..d132e2b 100644
--- a/test cases/common/163 disabler/meson.build
+++ b/test cases/common/163 disabler/meson.build
@@ -9,6 +9,7 @@ d2 = dependency(d)
d3 = (d == d2)
d4 = d + 0
d5 = d2 or true
+set_variable('d6', disabler())
has_not_changed = false
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(d4), 'Disabler addition 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(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(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(d6, 'set_variable with a disabler did not cause this to be skipped.')
number = 0
@@ -80,6 +83,31 @@ else
endif
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 disabler()
if_is_disabled = false