diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-01-21 21:52:18 +0100 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-01-22 16:41:06 +0100 |
commit | 86d5799bc4d945927e26fdcb6e239905e0aa8146 (patch) | |
tree | 39b2d3fc51788df1007658565edd6ce19c60adb0 /mesonbuild/ast/introspection.py | |
parent | f6339d6361c89f7b79cbf91e8eb56089f3c1a592 (diff) | |
download | meson-86d5799bc4d945927e26fdcb6e239905e0aa8146.zip meson-86d5799bc4d945927e26fdcb6e239905e0aa8146.tar.gz meson-86d5799bc4d945927e26fdcb6e239905e0aa8146.tar.bz2 |
First rewriter test case
Diffstat (limited to 'mesonbuild/ast/introspection.py')
-rw-r--r-- | mesonbuild/ast/introspection.py | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py index fde9cc1..11496db 100644 --- a/mesonbuild/ast/introspection.py +++ b/mesonbuild/ast/introspection.py @@ -20,9 +20,11 @@ from .. import compilers, environment, mesonlib, mparser, optinterpreter from .. import coredata as cdata from ..interpreterbase import InvalidArguments from ..build import Executable, CustomTarget, Jar, RunTarget, SharedLibrary, SharedModule, StaticLibrary - +from pprint import pprint import sys, os +build_target_functions = ['executable', 'jar', 'library', 'shared_library', 'shared_module', 'static_library', 'both_libraries'] + class IntrospectionHelper: # mimic an argparse namespace def __init__(self, cross_file): @@ -127,12 +129,36 @@ class IntrospectionInterpreter(AstInterpreter): def build_target(self, node, args, kwargs, targetclass): if not args: return - args = self.flatten_args(args, True) kwargs = self.flatten_kwargs(kwargs, True) - name = args[0] - sources = args[1:] + name = self.flatten_args(args)[0] + srcqueue = [node] if 'sources' in kwargs: - sources += self.flatten_args(kwargs['sources']) + srcqueue += kwargs['sources'] + + source_nodes = [] + while srcqueue: + curr = srcqueue.pop(0) + arg_node = None + if isinstance(curr, mparser.FunctionNode): + arg_node = curr.args + elif isinstance(curr, mparser.ArrayNode): + arg_node = curr.args + elif isinstance(curr, mparser.IdNode): + # Try to resolve the ID and append the node to the queue + id = curr.value + if id in self.assignments and self.assignments[id]: + node = self.assignments[id][0] + if isinstance(node, (mparser.ArrayNode, mparser.IdNode, mparser.FunctionNode)): + srcqueue += [node] + if arg_node is None: + continue + elemetary_nodes = list(filter(lambda x: isinstance(x, (str, mparser.StringNode)), arg_node.arguments)) + srcqueue += list(filter(lambda x: isinstance(x, (mparser.FunctionNode, mparser.ArrayNode, mparser.IdNode)), arg_node.arguments)) + # Pop the first element if the function is a build target function + if isinstance(curr, mparser.FunctionNode) and curr.func_name in build_target_functions: + elemetary_nodes.pop(0) + if elemetary_nodes: + source_nodes += [curr] # Filter out kwargs from other target types. For example 'soversion' # passed to library() when default_library == 'static'. @@ -140,7 +166,8 @@ class IntrospectionInterpreter(AstInterpreter): is_cross = False objects = [] - target = targetclass(name, self.subdir, self.subproject, is_cross, sources, objects, self.environment, kwargs) + empty_sources = [] # Passing the unresolved sources list causes errors + target = targetclass(name, self.subdir, self.subproject, is_cross, empty_sources, objects, self.environment, kwargs) self.targets += [{ 'name': target.get_basename(), @@ -149,7 +176,7 @@ class IntrospectionInterpreter(AstInterpreter): 'defined_in': os.path.normpath(os.path.join(self.source_root, self.subdir, environment.build_filename)), 'subdir': self.subdir, 'build_by_default': target.build_by_default, - 'sources': sources, + 'sources': source_nodes, 'kwargs': kwargs, 'node': node, }] |