|
@@ -20,10 +20,10 @@
|
|
# configuration.
|
|
# configuration.
|
|
#
|
|
#
|
|
# Copyright (C) 2010-2013 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
|
# Copyright (C) 2010-2013 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
|
|
|
+# Copyright (C) 2019 Yann E. MORIN <yann.morin.1998@free.fr>
|
|
|
|
|
|
import logging
|
|
import logging
|
|
import sys
|
|
import sys
|
|
-import subprocess
|
|
|
|
import argparse
|
|
import argparse
|
|
from fnmatch import fnmatch
|
|
from fnmatch import fnmatch
|
|
|
|
|
|
@@ -36,63 +36,6 @@ MODE_PKG = 2 # draw dependency graph for a given package
|
|
allpkgs = []
|
|
allpkgs = []
|
|
|
|
|
|
|
|
|
|
-# Execute the "make show-targets" command to get the list of the main
|
|
|
|
-# Buildroot PACKAGES and return it formatted as a Python list. This
|
|
|
|
-# list is used as the starting point for full dependency graphs
|
|
|
|
-def get_targets():
|
|
|
|
- logging.info("Getting targets")
|
|
|
|
- cmd = ["make", "-s", "--no-print-directory", "show-targets"]
|
|
|
|
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
|
|
|
|
- output = p.communicate()[0].strip()
|
|
|
|
- if p.returncode != 0:
|
|
|
|
- return None
|
|
|
|
- if output == '':
|
|
|
|
- return []
|
|
|
|
- return output.split(' ')
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-# Recursive function that builds the tree of dependencies for a given
|
|
|
|
-# list of packages. The dependencies are built in a list called
|
|
|
|
-# 'dependencies', which contains tuples of the form (pkg1 ->
|
|
|
|
-# pkg2_on_which_pkg1_depends, pkg3 -> pkg4_on_which_pkg3_depends) and
|
|
|
|
-# the function finally returns this list.
|
|
|
|
-def get_all_depends(pkgs, get_depends_func):
|
|
|
|
- dependencies = []
|
|
|
|
-
|
|
|
|
- # Filter the packages for which we already have the dependencies
|
|
|
|
- filtered_pkgs = []
|
|
|
|
- for pkg in pkgs:
|
|
|
|
- if pkg in allpkgs:
|
|
|
|
- continue
|
|
|
|
- filtered_pkgs.append(pkg)
|
|
|
|
- allpkgs.append(pkg)
|
|
|
|
-
|
|
|
|
- if len(filtered_pkgs) == 0:
|
|
|
|
- return []
|
|
|
|
-
|
|
|
|
- depends = get_depends_func(filtered_pkgs)
|
|
|
|
-
|
|
|
|
- deps = set()
|
|
|
|
- for pkg in filtered_pkgs:
|
|
|
|
- pkg_deps = depends[pkg]
|
|
|
|
-
|
|
|
|
- # This package has no dependency.
|
|
|
|
- if pkg_deps == []:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # Add dependencies to the list of dependencies
|
|
|
|
- for dep in pkg_deps:
|
|
|
|
- dependencies.append((pkg, dep))
|
|
|
|
- deps.add(dep)
|
|
|
|
-
|
|
|
|
- if len(deps) != 0:
|
|
|
|
- newdeps = get_all_depends(deps, get_depends_func)
|
|
|
|
- if newdeps is not None:
|
|
|
|
- dependencies += newdeps
|
|
|
|
-
|
|
|
|
- return dependencies
|
|
|
|
-
|
|
|
|
-
|
|
|
|
# The Graphviz "dot" utility doesn't like dashes in node names. So for
|
|
# The Graphviz "dot" utility doesn't like dashes in node names. So for
|
|
# node names, we strip all dashes. Also, nodes can't start with a number,
|
|
# node names, we strip all dashes. Also, nodes can't start with a number,
|
|
# so we prepend an underscore.
|
|
# so we prepend an underscore.
|
|
@@ -234,7 +177,7 @@ def remove_extra_deps(deps, rootpkg, transitive, arrow_dir):
|
|
|
|
|
|
|
|
|
|
# Print the attributes of a node: label and fill-color
|
|
# Print the attributes of a node: label and fill-color
|
|
-def print_attrs(outfile, pkg, version, depth, colors):
|
|
|
|
|
|
+def print_attrs(outfile, pkg, pkg_type, pkg_version, depth, colors):
|
|
name = pkg_node_name(pkg)
|
|
name = pkg_node_name(pkg)
|
|
if pkg == 'all':
|
|
if pkg == 'all':
|
|
label = 'ALL'
|
|
label = 'ALL'
|
|
@@ -243,13 +186,11 @@ def print_attrs(outfile, pkg, version, depth, colors):
|
|
if depth == 0:
|
|
if depth == 0:
|
|
color = colors[0]
|
|
color = colors[0]
|
|
else:
|
|
else:
|
|
- if pkg.startswith('host') \
|
|
|
|
- or pkg.startswith('toolchain') \
|
|
|
|
- or pkg.startswith('rootfs'):
|
|
|
|
|
|
+ if pkg_type == "host":
|
|
color = colors[2]
|
|
color = colors[2]
|
|
else:
|
|
else:
|
|
color = colors[1]
|
|
color = colors[1]
|
|
- if version == "virtual":
|
|
|
|
|
|
+ if pkg_version == "virtual":
|
|
outfile.write("%s [label = <<I>%s</I>>]\n" % (name, label))
|
|
outfile.write("%s [label = <<I>%s</I>>]\n" % (name, label))
|
|
else:
|
|
else:
|
|
outfile.write("%s [label = \"%s\"]\n" % (name, label))
|
|
outfile.write("%s [label = \"%s\"]\n" % (name, label))
|
|
@@ -260,13 +201,13 @@ done_deps = []
|
|
|
|
|
|
|
|
|
|
# Print the dependency graph of a package
|
|
# Print the dependency graph of a package
|
|
-def print_pkg_deps(outfile, dict_deps, dict_version, stop_list, exclude_list,
|
|
|
|
|
|
+def print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
|
|
arrow_dir, draw_graph, depth, max_depth, pkg, colors):
|
|
arrow_dir, draw_graph, depth, max_depth, pkg, colors):
|
|
if pkg in done_deps:
|
|
if pkg in done_deps:
|
|
return
|
|
return
|
|
done_deps.append(pkg)
|
|
done_deps.append(pkg)
|
|
if draw_graph:
|
|
if draw_graph:
|
|
- print_attrs(outfile, pkg, dict_version.get(pkg), depth, colors)
|
|
|
|
|
|
+ print_attrs(outfile, pkg, dict_types[pkg], dict_versions[pkg], depth, colors)
|
|
elif depth != 0:
|
|
elif depth != 0:
|
|
outfile.write("%s " % pkg)
|
|
outfile.write("%s " % pkg)
|
|
if pkg not in dict_deps:
|
|
if pkg not in dict_deps:
|
|
@@ -274,17 +215,15 @@ def print_pkg_deps(outfile, dict_deps, dict_version, stop_list, exclude_list,
|
|
for p in stop_list:
|
|
for p in stop_list:
|
|
if fnmatch(pkg, p):
|
|
if fnmatch(pkg, p):
|
|
return
|
|
return
|
|
- if dict_version.get(pkg) == "virtual" and "virtual" in stop_list:
|
|
|
|
|
|
+ if dict_versions[pkg] == "virtual" and "virtual" in stop_list:
|
|
return
|
|
return
|
|
- if pkg.startswith("host-") and "host" in stop_list:
|
|
|
|
|
|
+ if dict_types[pkg] == "host" and "host" in stop_list:
|
|
return
|
|
return
|
|
if max_depth == 0 or depth < max_depth:
|
|
if max_depth == 0 or depth < max_depth:
|
|
for d in dict_deps[pkg]:
|
|
for d in dict_deps[pkg]:
|
|
- if dict_version.get(d) == "virtual" \
|
|
|
|
- and "virtual" in exclude_list:
|
|
|
|
|
|
+ if dict_versions[d] == "virtual" and "virtual" in exclude_list:
|
|
continue
|
|
continue
|
|
- if d.startswith("host-") \
|
|
|
|
- and "host" in exclude_list:
|
|
|
|
|
|
+ if dict_types[d] == "host" and "host" in exclude_list:
|
|
continue
|
|
continue
|
|
add = True
|
|
add = True
|
|
for p in exclude_list:
|
|
for p in exclude_list:
|
|
@@ -294,7 +233,7 @@ def print_pkg_deps(outfile, dict_deps, dict_version, stop_list, exclude_list,
|
|
if add:
|
|
if add:
|
|
if draw_graph:
|
|
if draw_graph:
|
|
outfile.write("%s -> %s [dir=%s]\n" % (pkg_node_name(pkg), pkg_node_name(d), arrow_dir))
|
|
outfile.write("%s -> %s [dir=%s]\n" % (pkg_node_name(pkg), pkg_node_name(d), arrow_dir))
|
|
- print_pkg_deps(outfile, dict_deps, dict_version, stop_list, exclude_list,
|
|
|
|
|
|
+ print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
|
|
arrow_dir, draw_graph, depth + 1, max_depth, d, colors)
|
|
arrow_dir, draw_graph, depth + 1, max_depth, d, colors)
|
|
|
|
|
|
|
|
|
|
@@ -356,6 +295,7 @@ def main():
|
|
|
|
|
|
if args.package is None:
|
|
if args.package is None:
|
|
mode = MODE_FULL
|
|
mode = MODE_FULL
|
|
|
|
+ rootpkg = 'all'
|
|
else:
|
|
else:
|
|
mode = MODE_PKG
|
|
mode = MODE_PKG
|
|
rootpkg = args.package
|
|
rootpkg = args.package
|
|
@@ -374,13 +314,11 @@ def main():
|
|
exclude_list += MANDATORY_DEPS
|
|
exclude_list += MANDATORY_DEPS
|
|
|
|
|
|
if args.direct:
|
|
if args.direct:
|
|
- get_depends_func = brpkgutil.get_depends
|
|
|
|
arrow_dir = "forward"
|
|
arrow_dir = "forward"
|
|
else:
|
|
else:
|
|
if mode == MODE_FULL:
|
|
if mode == MODE_FULL:
|
|
logging.error("--reverse needs a package")
|
|
logging.error("--reverse needs a package")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
- get_depends_func = brpkgutil.get_rdepends
|
|
|
|
arrow_dir = "back"
|
|
arrow_dir = "back"
|
|
|
|
|
|
draw_graph = not args.flat_list
|
|
draw_graph = not args.flat_list
|
|
@@ -393,46 +331,20 @@ def main():
|
|
logging.error("Error: incorrect color list '%s'" % args.colors)
|
|
logging.error("Error: incorrect color list '%s'" % args.colors)
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
- # In full mode, start with the result of get_targets() to get the main
|
|
|
|
- # targets and then use get_all_depends() for all targets
|
|
|
|
- if mode == MODE_FULL:
|
|
|
|
- targets = get_targets()
|
|
|
|
- dependencies = []
|
|
|
|
- allpkgs.append('all')
|
|
|
|
- filtered_targets = []
|
|
|
|
- for tg in targets:
|
|
|
|
- dependencies.append(('all', tg))
|
|
|
|
- filtered_targets.append(tg)
|
|
|
|
- deps = get_all_depends(filtered_targets, get_depends_func)
|
|
|
|
- if deps is not None:
|
|
|
|
- dependencies += deps
|
|
|
|
- rootpkg = 'all'
|
|
|
|
-
|
|
|
|
- # In pkg mode, start directly with get_all_depends() on the requested
|
|
|
|
- # package
|
|
|
|
- elif mode == MODE_PKG:
|
|
|
|
- dependencies = get_all_depends([rootpkg], get_depends_func)
|
|
|
|
-
|
|
|
|
- # Make the dependencies a dictionnary { 'pkg':[dep1, dep2, ...] }
|
|
|
|
- dict_deps = {}
|
|
|
|
- for dep in dependencies:
|
|
|
|
- if dep[0] not in dict_deps:
|
|
|
|
- dict_deps[dep[0]] = []
|
|
|
|
- dict_deps[dep[0]].append(dep[1])
|
|
|
|
|
|
+ deps, rdeps, dict_types, dict_versions = brpkgutil.get_dependency_tree()
|
|
|
|
+ dict_deps = deps if args.direct else rdeps
|
|
|
|
|
|
check_circular_deps(dict_deps)
|
|
check_circular_deps(dict_deps)
|
|
if check_only:
|
|
if check_only:
|
|
sys.exit(0)
|
|
sys.exit(0)
|
|
|
|
|
|
dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, arrow_dir)
|
|
dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, arrow_dir)
|
|
- dict_version = brpkgutil.get_version([pkg for pkg in allpkgs
|
|
|
|
- if pkg != "all" and not pkg.startswith("root")])
|
|
|
|
|
|
|
|
# Start printing the graph data
|
|
# Start printing the graph data
|
|
if draw_graph:
|
|
if draw_graph:
|
|
outfile.write("digraph G {\n")
|
|
outfile.write("digraph G {\n")
|
|
|
|
|
|
- print_pkg_deps(outfile, dict_deps, dict_version, stop_list, exclude_list,
|
|
|
|
|
|
+ print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
|
|
arrow_dir, draw_graph, 0, args.depth, rootpkg, colors)
|
|
arrow_dir, draw_graph, 0, args.depth, rootpkg, colors)
|
|
|
|
|
|
if draw_graph:
|
|
if draw_graph:
|