mintro: Dependencies from source

pull/4949/head
Daniel Mensinger 6 years ago
parent 8a1411a1e8
commit f9b41d5ecb
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 3
      mesonbuild/ast/__init__.py
  2. 8
      mesonbuild/ast/introspection.py
  3. 30
      mesonbuild/ast/postprocess.py
  4. 11
      mesonbuild/mintro.py
  5. 4
      mesonbuild/rewriter.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

@ -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
}]

@ -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

@ -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()

@ -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 = []

Loading…
Cancel
Save