mintro: Add license and license_files to project introspection data

pull/13788/head
Daniele Nicolodi 1 month ago committed by Jussi Pakkanen
parent 83d9b21401
commit ec7a81ad86
  1. 20
      mesonbuild/ast/introspection.py
  2. 6
      mesonbuild/mintro.py
  3. 11
      unittests/allplatformstests.py

@ -93,14 +93,30 @@ class IntrospectionInterpreter(AstInterpreter):
if len(args) < 1:
raise InvalidArguments('Not enough arguments to project(). Needs at least the project name.')
def _str_list(node: T.Any) -> T.Optional[T.List[str]]:
if isinstance(node, ArrayNode):
r = []
for v in node.args.arguments:
if not isinstance(v, StringNode):
return None
r.append(v.value)
return r
if isinstance(node, StringNode):
return [node.value]
return None
proj_name = args[0]
proj_vers = kwargs.get('version', 'undefined')
proj_langs = self.flatten_args(args[1:])
if isinstance(proj_vers, ElementaryNode):
proj_vers = proj_vers.value
if not isinstance(proj_vers, str):
proj_vers = 'undefined'
self.project_data = {'descriptive_name': proj_name, 'version': proj_vers}
proj_langs = self.flatten_args(args[1:])
# Match the value returned by ``meson.project_license()`` when
# no ``license`` argument is specified in the ``project()`` call.
proj_license = _str_list(kwargs.get('license', None)) or ['unknown']
proj_license_files = _str_list(kwargs.get('license_files', None)) or []
self.project_data = {'descriptive_name': proj_name, 'version': proj_vers, 'license': proj_license, 'license_files': proj_license_files}
optfile = os.path.join(self.source_root, self.subdir, 'meson.options')
if not os.path.exists(optfile):

@ -470,10 +470,12 @@ def list_machines(builddata: build.Build) -> T.Dict[str, T.Dict[str, T.Union[str
machines[m]['object_suffix'] = machine.get_object_suffix()
return machines
def list_projinfo(builddata: build.Build) -> T.Dict[str, T.Union[str, T.List[T.Dict[str, str]]]]:
result: T.Dict[str, T.Union[str, T.List[T.Dict[str, str]]]] = {
def list_projinfo(builddata: build.Build) -> T.Dict[str, T.Union[str, T.List[str], T.List[T.Dict[str, str]]]]:
result: T.Dict[str, T.Union[str, T.List[str], T.List[T.Dict[str, str]]]] = {
'version': builddata.project_version,
'descriptive_name': builddata.project_name,
'license': builddata.dep_manifest[builddata.project_name].license,
'license_files': [f[1].fname for f in builddata.dep_manifest[builddata.project_name].license_files],
'subproject_dir': builddata.subproject_dir,
}
subprojects = []

@ -3021,6 +3021,8 @@ class AllPlatformTests(BasePlatformTests):
expected = {
'descriptive_name': 'proj',
'version': 'undefined',
'license': ['unknown'],
'license_files': [],
'subproject_dir': 'subprojects',
'subprojects': [
{
@ -3415,7 +3417,14 @@ class AllPlatformTests(BasePlatformTests):
self.assertListEqual(dependencies_to_find, [])
# Check projectinfo
self.assertDictEqual(res['projectinfo'], {'version': '1.2.3', 'descriptive_name': 'introspection', 'subproject_dir': 'subprojects', 'subprojects': []})
self.assertDictEqual(res['projectinfo'], {
'version': '1.2.3',
'license': ['unknown'],
'license_files': [],
'descriptive_name': 'introspection',
'subproject_dir': 'subprojects',
'subprojects': []
})
# Check targets
targets_to_find = {

Loading…
Cancel
Save