diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2019-03-04 01:48:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-04 01:48:58 +0200 |
commit | 0de4f199b3aa30939436742cfcd706412ea498e9 (patch) | |
tree | 9e8e3bae6cee8ce439febfd18a8d26c71eb54380 /mesonbuild/ast | |
parent | 7f9fb6a08481c26698fb9c8ce4920c456e46bbbd (diff) | |
parent | 586ec5a28cc2ea854f726cb7a6075b0918595bf5 (diff) | |
download | meson-0de4f199b3aa30939436742cfcd706412ea498e9.zip meson-0de4f199b3aa30939436742cfcd706412ea498e9.tar.gz meson-0de4f199b3aa30939436742cfcd706412ea498e9.tar.bz2 |
Merge pull request #4949 from mensinda/introTargetNoBD
mintro: Introspect targets and deps without a build directory
Diffstat (limited to 'mesonbuild/ast')
-rw-r--r-- | mesonbuild/ast/__init__.py | 3 | ||||
-rw-r--r-- | mesonbuild/ast/introspection.py | 14 | ||||
-rw-r--r-- | mesonbuild/ast/postprocess.py | 30 |
3 files changed, 44 insertions, 3 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 6ac5929..12cb379 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, ElementaryNode): + required = required.value self.dependencies += [{ 'name': name, + 'required': required, + 'has_fallback': has_fallback, + 'conditional': condition_level > 0, 'node': node }] @@ -180,11 +188,11 @@ class IntrospectionInterpreter(AstInterpreter): source_nodes += [curr] # Make sure nothing can crash when creating the build class - kwargs = {} + kwargs_reduced = {k: v for k, v in kwargs.items() if k in targetclass.known_kwargs and k in ['install', 'build_by_default', 'build_always']} is_cross = False objects = [] empty_sources = [] # Passing the unresolved sources list causes errors - target = targetclass(name, self.subdir, self.subproject, is_cross, empty_sources, objects, self.environment, kwargs) + target = targetclass(name, self.subdir, self.subproject, is_cross, empty_sources, objects, self.environment, kwargs_reduced) self.targets += [{ 'name': target.get_basename(), @@ -193,6 +201,8 @@ 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, + 'installed': target.should_install(), + 'outputs': target.get_outputs(), 'sources': source_nodes, 'kwargs': kwargs, '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 |