Repository: mesonbuild/meson

Issue:
mesonintrospect --dependencies returns list instead of dictionary
Reported it breaking completely in #1963 .

When I got around to testing the fix just now I noticed that the root object for mesonintrospect --dependencies now is a list instead of an object like it used to be prior to 0.41. Probably not what is wanted.

Example output (added newlines to make it easier to read):

```shell
$ mesonintrospect --dependencies <build path>
["threads", {"compile_args": [], "link_args": []},
 "libjpeg", {"compile_args": [], "link_args": ["-ljpeg"]},
 "libpng", {"compile_args": ["-I/usr/include/libpng16"], "link_args": ["-lpng16"]},
 "libwebp", {"compile_args": [], "link_args": ["-lwebp"]}]
```


Discussion:
@nirbheek I see that you turned this into a list in ac1c929f66bde7209f1bd7e2d995dbd3949e1d8b . The commit message ("Print all deps, not just those with the same name") does not make sense to me though. When it was a dictionary only deps with the same name were printed is what the message reads as to me... ?

Do we want this as a list? It makes it a bit more hard to iterate over dependencies in tools that parse this output. (Have to know that a dependency is described with to consecutive elements in the list and that name is the first.)

I think it makes more sense to have this as a dictionary but I do not understand what it was you were trying to fix.
The dependency name is not a unique identifier. You can have two dependency objects with the same name and different version requirements, or different modules enabled (qt, boost), etc. Earlier we would drop these because the dict is keyed by dependency name.
OK. Should something be done about making it easier to iterate over them though? Maybe add a "name" key so a single element in the list describes a single dependency fully instead of having a list with mixed element types. E.g. the above would then be:

```
[{ "name": "threads", "compile_args": [], "link_args": []},
 { "name": "libjpeg", "compile_args": [], "link_args": ["-ljpeg"]},
 { "name": "libpng", "compile_args": ["-I/usr/include/libpng16"], "link_args": ["-lpng16"]},
 { "name": "libwebp", "compile_args": [], "link_args": ["-lwebp"]}]
```

Resolving patch:
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -160,9 +160,9 @@ def list_deps(coredata):
     result = []
     for d in coredata.deps.values():
         if d.found():
-            args = {'compile_args': d.get_compile_args(),
-                    'link_args': d.get_link_args()}
-            result += [d.name, args]
+            result += [{'name': d.name,
+                        'compile_args': d.get_compile_args(),
+                        'link_args': d.get_link_args()}]
     print(json.dumps(result))
 
 def list_tests(testdata):
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1828,6 +1828,28 @@ def test_order_of_l_arguments(self):
                     return
         raise RuntimeError('Linker entries not found in the Ninja file.')
 
+    def test_introspect_dependencies(self):
+        '''
+        Tests that mesonintrospect --dependencies returns expected output.
+        '''
+        testdir = os.path.join(self.framework_test_dir, '7 gnome')
+        self.init(testdir)
+        glib_found = False
+        gobject_found = False
+        deps = self.introspect('--dependencies')
+        self.assertIsInstance(deps, list)
+        for dep in deps:
+            self.assertIsInstance(dep, dict)
+            self.assertIn('name', dep)
+            self.assertIn('compile_args', dep)
+            self.assertIn('link_args', dep)
+            if dep['name'] == 'glib-2.0':
+                glib_found = True
+            elif dep['name'] == 'gobject-2.0':
+                gobject_found = True
+        self.assertTrue(glib_found)
+        self.assertTrue(gobject_found)
+
 class LinuxArmCrossCompileTests(BasePlatformTests):
     '''
     Tests that verify cross-compilation to Linux/ARM


Test patch: