diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-02-18 16:43:48 +0100 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-03-03 23:19:03 +0100 |
commit | f9b41d5ecbed3adabb6a0433892ea801b531c412 (patch) | |
tree | c5cce47fdc84b426943dbefba99011e7472551a0 /mesonbuild/ast | |
parent | 8a1411a1e8a8a2c37de0d25ec129aba65703616e (diff) | |
download | meson-f9b41d5ecbed3adabb6a0433892ea801b531c412.zip meson-f9b41d5ecbed3adabb6a0433892ea801b531c412.tar.gz meson-f9b41d5ecbed3adabb6a0433892ea801b531c412.tar.bz2 |
mintro: Dependencies from source
Diffstat (limited to 'mesonbuild/ast')
-rw-r--r-- | mesonbuild/ast/__init__.py | 3 | ||||
-rw-r--r-- | mesonbuild/ast/introspection.py | 8 | ||||
-rw-r--r-- | mesonbuild/ast/postprocess.py | 30 |
3 files changed, 40 insertions, 1 deletions
diff --git a/mesonbuild/ast/__init__.py b/mesonbuild/ast/__init__.py index a9370dc..48de523 100644 --- a/mesonbuild/ast/__init__.py +++ b/mesonbuild/ast/__init__.py @@ -16,6 +16,7 @@ # or an interpreter-based tool. __all__ = [ + 'AstConditionLevel', 'AstInterpreter', 'AstIDGenerator', 'AstIndentationGenerator', @@ -28,5 +29,5 @@ __all__ = [ from .interpreter import AstInterpreter from .introspection import IntrospectionInterpreter, build_target_functions from .visitor import AstVisitor -from .postprocess import AstIDGenerator, AstIndentationGenerator +from .postprocess import AstConditionLevel, AstIDGenerator, AstIndentationGenerator from .printer import AstPrinter diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py index da2f740..225f43c 100644 --- a/mesonbuild/ast/introspection.py +++ b/mesonbuild/ast/introspection.py @@ -137,8 +137,16 @@ class IntrospectionInterpreter(AstInterpreter): if not args: return name = args[0] + has_fallback = 'fallback' in kwargs + required = kwargs.get('required', True) + condition_level = node.condition_level if hasattr(node, 'condition_level') else 0 + if isinstance(required, mparser.ElementaryNode): + required = required.value self.dependencies += [{ 'name': name, + 'required': required, + 'has_fallback': has_fallback, + 'conditional': condition_level > 0, 'node': node }] diff --git a/mesonbuild/ast/postprocess.py b/mesonbuild/ast/postprocess.py index e913b4f..8e8732f 100644 --- a/mesonbuild/ast/postprocess.py +++ b/mesonbuild/ast/postprocess.py @@ -84,3 +84,33 @@ class AstIDGenerator(AstVisitor): self.counter[name] = 0 node.ast_id = name + '#' + str(self.counter[name]) self.counter[name] += 1 + +class AstConditionLevel(AstVisitor): + def __init__(self): + self.condition_level = 0 + + def visit_default_func(self, node: mparser.BaseNode): + node.condition_level = self.condition_level + + def visit_ForeachClauseNode(self, node: mparser.ForeachClauseNode): + self.visit_default_func(node) + self.condition_level += 1 + node.items.accept(self) + node.block.accept(self) + self.condition_level -= 1 + + def visit_IfClauseNode(self, node: mparser.IfClauseNode): + self.visit_default_func(node) + for i in node.ifs: + i.accept(self) + if node.elseblock: + self.condition_level += 1 + node.elseblock.accept(self) + self.condition_level -= 1 + + def visit_IfNode(self, node: mparser.IfNode): + self.visit_default_func(node) + self.condition_level += 1 + node.condition.accept(self) + node.block.accept(self) + self.condition_level -= 1 |