[Buildroot] [PATCH 11/12 v2] support/scripts: use show-info to extract dependency graph

Yann E. MORIN yann.morin.1998 at free.fr
Sun Apr 14 20:17:22 UTC 2019


Currently, we extract the dependency graph from the aptly named but
ad-hoc show-dependency-graph rule.

We now have a better solution to report package information, with
show-info.

Since show-dependency-graph never went into a release so far, and
show-info does provide the same (and more), swith to using show-info.

Thanks to Adam for suggesting the coding style to have a readable code
that is not ugly but still pleases flake8. Thanks to Arnout for
suggesting the use of dict.get() to further simplify the code.

Reported-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998 at free.fr>
Cc: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
Cc: Thomas De Schampheleire <patrickdepinguin at gmail.com>
Cc: Adam Duskett <aduskett at gmail.com>
Cc: Arnout Vandecappelle <arnout at mind.be>
Cc: Ricardo Martincoski <ricardo.martincoski at gmail.com>
---
 support/scripts/brpkgutil.py | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/support/scripts/brpkgutil.py b/support/scripts/brpkgutil.py
index f65068d348..22ceab2b10 100644
--- a/support/scripts/brpkgutil.py
+++ b/support/scripts/brpkgutil.py
@@ -1,10 +1,10 @@
 # Copyright (C) 2010-2013 Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
 # Copyright (C) 2019 Yann E. MORIN <yann.morin.1998 at free.fr>
 
+import json
 import logging
 import os
 import subprocess
-from collections import defaultdict
 
 
 # This function returns a tuple of four dictionaries, all using package
@@ -19,8 +19,8 @@ from collections import defaultdict
 def get_dependency_tree():
     logging.info("Getting dependency tree...")
 
-    deps = defaultdict(list)
-    rdeps = defaultdict(list)
+    deps = {}
+    rdeps = {}
     types = {}
     versions = {}
 
@@ -29,23 +29,20 @@ def get_dependency_tree():
     types['all'] = 'target'
     versions['all'] = ''
 
-    cmd = ["make", "-s", "--no-print-directory", "show-dependency-tree"]
+    cmd = ["make", "-s", "--no-print-directory", "show-info"]
     with open(os.devnull, 'wb') as devnull:
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=devnull,
                              universal_newlines=True)
-        output = p.communicate()[0]
+        pkg_list = json.loads(p.communicate()[0])
 
-    for l in output.splitlines():
-        if " -> " in l:
-            pkg = l.split(" -> ")[0]
-            deps[pkg] += l.split(" -> ")[1].split()
-            for p in l.split(" -> ")[1].split():
-                rdeps[p].append(pkg)
-        else:
-            pkg, type_version = l.split(": ", 1)
-            t, v = "{} -".format(type_version).split(None, 2)[:2]
-            deps['all'].append(pkg)
-            types[pkg] = t
-            versions[pkg] = v
+    for pkg in pkg_list:
+        deps['all'].append(pkg)
+        types[pkg] = pkg_list[pkg]["type"]
+        deps[pkg] = pkg_list[pkg].get("dependencies", [])
+        rdeps[pkg] = pkg_list[pkg].get("reverse_dependencies", [])
+        versions[pkg] = \
+            None if pkg_list[pkg]["type"] == "rootfs" \
+            else "virtual" if pkg_list[pkg]["virtual"] \
+            else pkg_list[pkg]["version"]
 
     return (deps, rdeps, types, versions)
-- 
2.14.1



More information about the buildroot mailing list