Target introspection from source

pull/4949/head
Daniel Mensinger 6 years ago
parent 98e60f59ac
commit 8a1411a1e8
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 6
      mesonbuild/ast/introspection.py
  2. 43
      mesonbuild/mintro.py

@ -180,11 +180,11 @@ class IntrospectionInterpreter(AstInterpreter):
source_nodes += [curr] source_nodes += [curr]
# Make sure nothing can crash when creating the build class # 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 is_cross = False
objects = [] objects = []
empty_sources = [] # Passing the unresolved sources list causes errors 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 += [{ self.targets += [{
'name': target.get_basename(), 'name': target.get_basename(),
@ -193,6 +193,8 @@ class IntrospectionInterpreter(AstInterpreter):
'defined_in': os.path.normpath(os.path.join(self.source_root, self.subdir, environment.build_filename)), 'defined_in': os.path.normpath(os.path.join(self.source_root, self.subdir, environment.build_filename)),
'subdir': self.subdir, 'subdir': self.subdir,
'build_by_default': target.build_by_default, 'build_by_default': target.build_by_default,
'installed': target.should_install(),
'outputs': target.get_outputs(),
'sources': source_nodes, 'sources': source_nodes,
'kwargs': kwargs, 'kwargs': kwargs,
'node': node, 'node': node,

@ -22,9 +22,10 @@ project files and don't need this info."""
import json import json
from . import build, coredata as cdata from . import build, coredata as cdata
from . import mesonlib from . import mesonlib
from .ast import IntrospectionInterpreter from .ast import IntrospectionInterpreter, build_target_functions
from . import mlog from . import mlog
from .backend import backends from .backend import backends
from .mparser import FunctionNode, ArrayNode, ArgumentNode, StringNode
import sys, os import sys, os
import pathlib import pathlib
@ -75,6 +76,7 @@ def get_meson_introspection_types(coredata: cdata.CoreData = None, builddata: bu
}, },
'targets': { 'targets': {
'func': lambda: list_targets(builddata, installdata, backend), 'func': lambda: list_targets(builddata, installdata, backend),
'no_bd': lambda intr: list_targets_from_source(intr),
'desc': 'List top level targets.', 'desc': 'List top level targets.',
}, },
'tests': { 'tests': {
@ -115,6 +117,45 @@ def list_installed(installdata):
res[path] = os.path.join(installdata.prefix, installpath) res[path] = os.path.join(installdata.prefix, installpath)
return res return res
def list_targets_from_source(intr: IntrospectionInterpreter):
tlist = []
for i in intr.targets:
sources = []
for n in i['sources']:
args = []
if isinstance(n, FunctionNode):
args = list(n.args.arguments)
if n.func_name in build_target_functions:
args.pop(0)
elif isinstance(n, ArrayNode):
args = n.args.arguments
elif isinstance(n, ArgumentNode):
args = n.arguments
for j in args:
if isinstance(j, StringNode):
sources += [j.value]
elif isinstance(j, str):
sources += [j]
tlist += [{
'name': i['name'],
'id': i['id'],
'type': i['type'],
'defined_in': i['defined_in'],
'filename': [os.path.join(i['subdir'], x) for x in i['outputs']],
'build_by_default': i['build_by_default'],
'target_sources': [{
'language': 'unknown',
'compiler': [],
'parameters': [],
'sources': [os.path.normpath(os.path.join(os.path.abspath(intr.source_root), i['subdir'], x)) for x in sources],
'generated_sources': []
}],
'installed': i['installed']
}]
return tlist
def list_targets(builddata: build.Build, installdata, backend: backends.Backend): def list_targets(builddata: build.Build, installdata, backend: backends.Backend):
tlist = [] tlist = []
build_dir = builddata.environment.get_build_dir() build_dir = builddata.environment.get_build_dir()

Loading…
Cancel
Save