Repository: mesonbuild/meson

Issue:
introspection: Add version information to 'meson introspect --scan-dependencies'
@mensinda 
Add ability to display required version for dependencies discovered via 'meson introspect --scan-dependencies'


Discussion:

Resolving patch:
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -136,11 +136,15 @@ def func_add_languages(self, node, args, kwargs):
 
     def func_dependency(self, node, args, kwargs):
         args = self.flatten_args(args)
+        kwargs = self.flatten_kwargs(kwargs)
         if not args:
             return
         name = args[0]
         has_fallback = 'fallback' in kwargs
         required = kwargs.get('required', True)
+        version = kwargs.get('version', [])
+        if not isinstance(version, list):
+            version = [version]
         condition_level = node.condition_level if hasattr(node, 'condition_level') else 0
         if isinstance(required, ElementaryNode):
             required = required.value
@@ -149,9 +153,10 @@ def func_dependency(self, node, args, kwargs):
         self.dependencies += [{
             'name': name,
             'required': required,
+            'version': version,
             'has_fallback': has_fallback,
             'conditional': condition_level > 0,
-            'node': node
+            'node': node,
         }]
 
     def build_target(self, node, args, kwargs, targetclass):
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -263,7 +263,14 @@ def list_buildsystem_files(builddata: build.Build) -> List[str]:
 def list_deps_from_source(intr: IntrospectionInterpreter) -> List[Dict[str, Union[str, bool]]]:
     result = []  # type: List[Dict[str, Union[str, bool]]]
     for i in intr.dependencies:
-        result += [{k: v for k, v in i.items() if k in ['name', 'required', 'has_fallback', 'conditional']}]
+        keys = [
+            'name',
+            'required',
+            'version',
+            'has_fallback',
+            'conditional',
+        ]
+        result += [{k: v for k, v in i.items() if k in keys}]
     return result
 
 def list_deps(coredata: cdata.CoreData) -> List[Dict[str, Union[str, List[str]]]]:
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -4063,30 +4063,35 @@ def test_introspect_dependencies_from_source(self):
             {
                 'name': 'threads',
                 'required': True,
+                'version': [],
                 'has_fallback': False,
                 'conditional': False
             },
             {
                 'name': 'zlib',
                 'required': False,
+                'version': [],
                 'has_fallback': False,
                 'conditional': False
             },
             {
                 'name': 'bugDep1',
-                'required': False,
+                'required': True,
+                'version': [],
                 'has_fallback': False,
                 'conditional': False
             },
             {
                 'name': 'somethingthatdoesnotexist',
                 'required': True,
+                'version': ['>=1.2.3'],
                 'has_fallback': False,
                 'conditional': True
             },
             {
                 'name': 'look_i_have_a_fallback',
                 'required': True,
+                'version': ['>=1.0.0', '<=99.9.9'],
                 'has_fallback': True,
                 'conditional': True
             }


Test patch:
diff --git a/test cases/unit/57 introspection/meson.build b/test cases/unit/57 introspection/meson.build
--- a/test cases/unit/57 introspection/meson.build	
+++ b/test cases/unit/57 introspection/meson.build	
@@ -13,8 +13,9 @@ set_variable('list_test_plusassign', [])
 list_test_plusassign += ['bugs everywhere']
 
 if false
-  dependency('somethingthatdoesnotexist', required: true)
-  dependency('look_i_have_a_fallback', fallback: ['oh_no', 'the_subproject_does_not_exist'])
+  vers_str = '<=99.9.9'
+  dependency('somethingthatdoesnotexist', required: true, version: '>=1.2.3')
+  dependency('look_i_have_a_fallback', version: ['>=1.0.0', vers_str], fallback: ['oh_no', 'the_subproject_does_not_exist'])
 endif
 
 subdir('sharedlib')