aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Nicolodi <daniele@grinta.net>2024-10-12 13:00:03 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2024-10-13 19:35:58 +0300
commitec7a81ad8620ef0f94be7f84eb946bc90ad1446c (patch)
tree7184c729122630cb97e91e466c919b4794dbd2cc
parent83d9b21401ec338efeff231316c06aa78e862843 (diff)
downloadmeson-ec7a81ad8620ef0f94be7f84eb946bc90ad1446c.zip
meson-ec7a81ad8620ef0f94be7f84eb946bc90ad1446c.tar.gz
meson-ec7a81ad8620ef0f94be7f84eb946bc90ad1446c.tar.bz2
mintro: Add license and license_files to project introspection data
-rw-r--r--mesonbuild/ast/introspection.py20
-rw-r--r--mesonbuild/mintro.py6
-rw-r--r--unittests/allplatformstests.py11
3 files changed, 32 insertions, 5 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index 89df1d2..b2eb1f8 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.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):
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 07ad533..810a2b6 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -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 = []
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index ca4b194..afea397 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -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 = {