![Yann E. MORIN](/assets/img/avatar_default.png)
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), switch 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. Note: we do not use the reverse_dependencies field because it only contains those packages that have a kconfig option, so we'd miss most host packages. Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Cc: Thomas De Schampheleire <patrickdepinguin@gmail.com> Cc: Adam Duskett <aduskett@gmail.com> Cc: Arnout Vandecappelle <arnout@mind.be> Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
# Copyright (C) 2010-2013 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
|
# Copyright (C) 2019 Yann E. MORIN <yann.morin.1998@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
|
|
# names as keys:
|
|
# - a dictionary which values are the lists of packages that are the
|
|
# dependencies of the package used as key;
|
|
# - a dictionary which values are the lists of packages that are the
|
|
# reverse dependencies of the package used as key;
|
|
# - a dictionary which values are the type of the package used as key;
|
|
# - a dictionary which values are the version of the package used as key,
|
|
# 'virtual' for a virtual package, or the empty string for a rootfs.
|
|
def get_dependency_tree():
|
|
logging.info("Getting dependency tree...")
|
|
|
|
deps = {}
|
|
rdeps = defaultdict(list)
|
|
types = {}
|
|
versions = {}
|
|
|
|
# Special case for the 'all' top-level fake package
|
|
deps['all'] = []
|
|
types['all'] = 'target'
|
|
versions['all'] = ''
|
|
|
|
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)
|
|
pkg_list = json.loads(p.communicate()[0])
|
|
|
|
for pkg in pkg_list:
|
|
deps['all'].append(pkg)
|
|
types[pkg] = pkg_list[pkg]["type"]
|
|
deps[pkg] = pkg_list[pkg].get("dependencies", [])
|
|
for p in deps[pkg]:
|
|
rdeps[p].append(pkg)
|
|
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)
|