aboutsummaryrefslogtreecommitdiff
path: root/interpreter.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-06-15 00:26:19 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2015-06-15 00:26:19 +0300
commit6d744b13ff205a4a85c298c620525d8a3b685447 (patch)
tree89cbfa3e9f7e63de77d33ba688037e0103700e76 /interpreter.py
parentee0fee2111087a1082baaad3f53e871bd9123c69 (diff)
downloadmeson-6d744b13ff205a4a85c298c620525d8a3b685447.zip
meson-6d744b13ff205a4a85c298c620525d8a3b685447.tar.gz
meson-6d744b13ff205a4a85c298c620525d8a3b685447.tar.bz2
Now can create internal dependencies to simplify subproject usage.
Diffstat (limited to 'interpreter.py')
-rw-r--r--interpreter.py42
1 files changed, 37 insertions, 5 deletions
diff --git a/interpreter.py b/interpreter.py
index 89df630..dea802e 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -22,7 +22,6 @@ import optinterpreter
import wrap
import mesonlib
import os, sys, platform, subprocess, shutil, uuid, re
-from mesonlib import File
from functools import wraps
import importlib
@@ -44,6 +43,14 @@ def check_stringlist(a, msg='Arguments must be strings.'):
if not all(isinstance(s, str) for s in 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):
@@ -215,6 +222,15 @@ class DependencyHolder(InterpreterObject):
def found_method(self, args, kwargs):
return self.held_object.found()
+class InternalDependencyHolder(InterpreterObject):
+ def __init__(self, dep):
+ InterpreterObject.__init__(self)
+ self.held_object = dep
+ self.methods.update({'found' : self.found_method})
+
+ def found_method(self, args, kwargs):
+ return True
+
class ExternalProgramHolder(InterpreterObject):
def __init__(self, ep):
InterpreterObject.__init__(self)
@@ -827,6 +843,7 @@ class Interpreter():
'set_variable' : self.func_set_variable,
'import' : self.func_import,
'files' : self.func_files,
+ 'declare_dependency': self.func_declare_dependency,
}
def module_method_callback(self, invalues):
@@ -930,7 +947,22 @@ class Interpreter():
@stringArgs
@noKwargs
def func_files(self, node, args, kwargs):
- return [File.from_source_file(self.environment.source_dir, self.subdir, fname) for fname in args]
+ return [mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, fname) for fname in args]
+
+ @noPosargs
+ def func_declare_dependency(self, node, args, kwargs):
+ incs = kwargs.get('include_directories', [])
+ if not isinstance(incs, list):
+ incs = [incs]
+ libs = kwargs.get('link_with', [])
+ if not isinstance(libs, list):
+ libs = [libs]
+ sources = kwargs.get('sources', [])
+ if not isinstance(sources, list):
+ sources = [sources]
+ sources = self.source_strings_to_files(self.flatten(sources))
+ dep = dependencies.InternalDependency(incs, libs, sources)
+ return InternalDependencyHolder(dep)
def set_variable(self, varname, variable):
if variable is None:
@@ -1571,13 +1603,13 @@ class Interpreter():
def source_strings_to_files(self, sources):
results = []
for s in sources:
- if isinstance(s, File) or isinstance(s, GeneratedListHolder) or \
+ if isinstance(s, mesonlib.File) or isinstance(s, GeneratedListHolder) or \
isinstance(s, CustomTargetHolder):
pass
elif isinstance(s, str):
- s = File.from_source_file(self.environment.source_dir, self.subdir, s)
+ s = mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s)
else:
- raise InterpreterException("Argument list is invalid.")
+ raise InterpreterException("Source item is not string or File-type object.")
results.append(s)
return results