Skip to content

Commit

Permalink
mintro: Add license and license_files to project introspection data
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi authored and jpakkane committed Oct 13, 2024
1 parent 83d9b21 commit ec7a81a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
20 changes: 18 additions & 2 deletions mesonbuild/ast/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,30 @@ def func_project(self, node: BaseNode, args: T.List[TYPE_var], kwargs: T.Dict[st
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):
Expand Down
6 changes: 4 additions & 2 deletions mesonbuild/mintro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
11 changes: 10 additions & 1 deletion unittests/allplatformstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,8 @@ def test_introspect_projectinfo_subprojects(self):
expected = {
'descriptive_name': 'proj',
'version': 'undefined',
'license': ['unknown'],
'license_files': [],
'subproject_dir': 'subprojects',
'subprojects': [
{
Expand Down Expand Up @@ -3415,7 +3417,14 @@ def assertKeyTypes(key_type_list, obj, strict: bool = True):
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 = {
Expand Down

0 comments on commit ec7a81a

Please sign in to comment.