aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase.py
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/interpreterbase.py')
-rw-r--r--mesonbuild/interpreterbase.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 7e732be..4268597 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -19,6 +19,42 @@ from . import mparser, mesonlib, mlog
from . import environment, dependencies
import os, copy, re
+from functools import wraps
+
+# Decorators for method calls.
+
+def check_stringlist(a, msg='Arguments must be strings.'):
+ if not isinstance(a, list):
+ mlog.debug('Not a list:', str(a))
+ raise InvalidArguments('Argument not a list.')
+ if not all(isinstance(s, str) for s in a):
+ mlog.debug('Element not a string:', str(a))
+ raise InvalidArguments(msg)
+
+def noPosargs(f):
+ @wraps(f)
+ def wrapped(self, node, args, kwargs):
+ if len(args) != 0:
+ raise InvalidArguments('Function does not take positional arguments.')
+ return f(self, node, args, kwargs)
+ return wrapped
+
+def noKwargs(f):
+ @wraps(f)
+ def wrapped(self, node, args, kwargs):
+ if len(kwargs) != 0:
+ raise InvalidArguments('Function does not take keyword arguments.')
+ return f(self, node, args, kwargs)
+ return wrapped
+
+def stringArgs(f):
+ @wraps(f)
+ def wrapped(self, node, args, kwargs):
+ assert(isinstance(args, list))
+ check_stringlist(args)
+ return f(self, node, args, kwargs)
+ return wrapped
+
class InterpreterException(mesonlib.MesonException):
pass
@@ -159,6 +195,26 @@ class InterpreterBase:
raise InvalidCode('Keyword arguments are invalid in array construction.')
return arguments
+ def evaluate_notstatement(self, cur):
+ v = self.evaluate_statement(cur.value)
+ if isinstance(v, mparser.BooleanNode):
+ v = v.value
+ if not isinstance(v, bool):
+ raise InterpreterException('Argument to "not" is not a boolean.')
+ return not v
+
+
+ def evaluate_if(self, node):
+ assert(isinstance(node, mparser.IfClauseNode))
+ for i in node.ifs:
+ result = self.evaluate_statement(i.condition)
+ if not(isinstance(result, bool)):
+ raise InvalidCode('If clause {!r} does not evaluate to true or false.'.format(result))
+ if result:
+ self.evaluate_codeblock(i.block)
+ return
+ if not isinstance(node.elseblock, mparser.EmptyNode):
+ self.evaluate_codeblock(node.elseblock)
def function_call(self, node):
func_name = node.func_name
@@ -247,3 +303,49 @@ class InterpreterBase:
return isinstance(value, (InterpreterObject, dependencies.Dependency,
str, int, list, mesonlib.File))
+ def func_build_target(self, node, args, kwargs):
+ if 'target_type' not in kwargs:
+ raise InterpreterException('Missing target_type keyword argument')
+ target_type = kwargs.pop('target_type')
+ if target_type == 'executable':
+ return self.func_executable(node, args, kwargs)
+ elif target_type == 'shared_library':
+ return self.func_shared_lib(node, args, kwargs)
+ elif target_type == 'static_library':
+ return self.func_static_lib(node, args, kwargs)
+ elif target_type == 'library':
+ return self.func_library(node, args, kwargs)
+ elif target_type == 'jar':
+ return self.func_jar(node, args, kwargs)
+ else:
+ raise InterpreterException('Unknown target_type.')
+
+ def func_set_variable(self, node, args, kwargs):
+ if len(args) != 2:
+ raise InvalidCode('Set_variable takes two arguments.')
+ varname = args[0]
+ value = self.to_native(args[1])
+ self.set_variable(varname, value)
+
+# @noKwargs
+ def func_get_variable(self, node, args, kwargs):
+ if len(args)<1 or len(args)>2:
+ raise InvalidCode('Get_variable takes one or two arguments.')
+ varname = args[0]
+ if not isinstance(varname, str):
+ raise InterpreterException('First argument must be a string.')
+ try:
+ return self.variables[varname]
+ except KeyError:
+ pass
+ if len(args) == 2:
+ return args[1]
+ raise InterpreterException('Tried to get unknown variable "%s".' % varname)
+
+ @stringArgs
+ @noKwargs
+ def func_is_variable(self, node, args, kwargs):
+ if len(args) != 1:
+ raise InvalidCode('Is_variable takes two arguments.')
+ varname = args[0]
+ return varname in self.variables