From f9b41d5ecbed3adabb6a0433892ea801b531c412 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Mon, 18 Feb 2019 16:43:48 +0100 Subject: [PATCH] mintro: Dependencies from source --- mesonbuild/ast/__init__.py | 3 ++- mesonbuild/ast/introspection.py | 8 ++++++++ mesonbuild/ast/postprocess.py | 30 ++++++++++++++++++++++++++++++ mesonbuild/mintro.py | 11 +++++++++-- mesonbuild/rewriter.py | 4 ++-- 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/mesonbuild/ast/__init__.py b/mesonbuild/ast/__init__.py index a9370dc6e..48de5231a 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 da2f740bb..225f43c95 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 e913b4f04..8e8732f3e 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 diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index ed747811c..349a399d7 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -22,7 +22,7 @@ project files and don't need this info.""" import json from . import build, coredata as cdata from . import mesonlib -from .ast import IntrospectionInterpreter, build_target_functions +from .ast import IntrospectionInterpreter, build_target_functions, AstConditionLevel, AstIDGenerator, AstIndentationGenerator from . import mlog from .backend import backends from .mparser import FunctionNode, ArrayNode, ArgumentNode, StringNode @@ -63,6 +63,7 @@ def get_meson_introspection_types(coredata: cdata.CoreData = None, builddata: bu }, 'dependencies': { 'func': lambda: list_deps(coredata), + 'no_bd': lambda intr: list_deps_from_source(intr), 'desc': 'List external dependencies.', }, 'installed': { @@ -286,6 +287,12 @@ def list_buildsystem_files(builddata: build.Build): filelist = [os.path.join(src_dir, x) for x in filelist] return filelist +def list_deps_from_source(intr: IntrospectionInterpreter): + result = [] + for i in intr.dependencies: + result += [{k: v for k, v in i.items() if k in ['name', 'required', 'has_fallback', 'conditional']}] + return result + def list_deps(coredata: cdata.CoreData): result = [] for d in coredata.deps.values(): @@ -377,7 +384,7 @@ def run(options): # Make sure that log entries in other parts of meson don't interfere with the JSON output mlog.disable() backend = backends.get_backend_from_name(options.backend, None) - intr = IntrospectionInterpreter(sourcedir, '', backend.name) + intr = IntrospectionInterpreter(sourcedir, '', backend.name, visitors = [AstIDGenerator(), AstIndentationGenerator(), AstConditionLevel()]) intr.analyze() # Reenable logging just in case mlog.enable() diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py index ec785214d..c99743400 100644 --- a/mesonbuild/rewriter.py +++ b/mesonbuild/rewriter.py @@ -23,7 +23,7 @@ # - move targets # - reindent? -from .ast import IntrospectionInterpreter, build_target_functions, AstIDGenerator, AstIndentationGenerator, AstPrinter +from .ast import IntrospectionInterpreter, build_target_functions, AstConditionLevel, AstIDGenerator, AstIndentationGenerator, AstPrinter from mesonbuild.mesonlib import MesonException from . import mlog, mparser, environment from functools import wraps @@ -324,7 +324,7 @@ rewriter_func_kwargs = { class Rewriter: def __init__(self, sourcedir: str, generator: str = 'ninja'): self.sourcedir = sourcedir - self.interpreter = IntrospectionInterpreter(sourcedir, '', generator, visitors = [AstIDGenerator(), AstIndentationGenerator()]) + self.interpreter = IntrospectionInterpreter(sourcedir, '', generator, visitors = [AstIDGenerator(), AstIndentationGenerator(), AstConditionLevel()]) self.modefied_nodes = [] self.to_remove_nodes = [] self.to_add_nodes = []