graph-depends improvements (branch yem/graphs)
v4 cover graph-depends improvements (branch yem/graphs)
From: "Yann E. MORIN" <[email protected]>
Hello All!
This series brings a few improvements to the graph-depends utility:
- add option to remove transitive dependencies
- add option to pas arbitrary args to the dot utility
- cleanup and re-arrange the code
This series is open for discusion, especially on how we pass options to the graph generators:
- support/scripts/graph-depends: needs to know whether to generate transitive dependencies or not, and how deep to limit the dependencies
- the 'dot' utility: needs to know whether to graph top-down or left-right (or whatever), the type of graph (tree, circle...) and so on...
Currently, environment variables are used, but that is not in the tastes of some (me including), but I can't see a better way.
Peter suggested using kconfig knobs, but it does not scale when you want different settings for different graphs (e.g, different depth level for different packages).
Samuel suggested using a config file, but it has the same issues as the kconfig options. He also suggested pasing a single environment variable, but that does not work since some options are for graph-depends shile others are for dot.
So I went for adding a new variable to pass options to dot.
Changes v3 -> v4:
- include Fran?ois' host-package colours (Fran?ois)
- fix commit log (Thomas)
- add option for colours, add to manual
Changes v2 -> v3:
- pythonise even further the handling of --depth (Samuel)
- rename BR2_GRAPH_DEPTH to BR2_GRAPH_DEPS_OPTS
- introduce BR2_GRAPH_DOT_OPTS
- update manual accordingly
Changes v1 -> v2:
- complete rewrite, split into a series
Regards,
Yann E. MORIN.
The following changes since commit ed1182641812986f529b2150635f1e93c799a419:
xserver_xorg-server: add support for xtensa architecture (2014-06-08 15:51:00 +0200)
are available in the git repository at:
git://gitorious.org/buildroot/buildroot.git yem/graphs
for you to fetch changes up to fa5477ea2ced52b952961623097578564a7247b6:
manual: document the new graph-depends options (2014-06-08 15:58:27 +0200)
----------------------------------------------------------------
Francois Perrad (1):
graph-depends: refactor with more colors
Yann E. MORIN (8):
graphs: add option to remove transitive dependencies in dependency graph
graphs-depends: merge redundant-dependencies elimination
graph-depends: handle the depth argument in a more pythonic way
graph-depends: add option to set the colours
graph-depends: document the 'transitive' variable
graph-depends: rename the mode constants
graph-depends: add option to pass arbitrary dot options
manual: document the new graph-depends options
Makefile | 2 +- docs/manual/common-usage.txt | 11 ++- package/pkg-generic.mk | 2 +- support/scripts/graph-depends | 161 +++++++++++++++++++++++++++--------------- 4 files changed, 115 insertions(+), 61 deletions(-)
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH v4 1/9 graph-depends: refactor with more colors
From: Francois Perrad <[email protected]>
Do not use the same colors for toolchain, host and target packages.
--- support/scripts/graph-depends | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
support/scripts/graph-depends +14 -7
@@ -222,15 +222,22 @@ for dep in dependencies: # Print the attributes of a node: label and fill-color def print_attrs(pkg): + name = pkg_node_name(pkg) if pkg == 'all': - print "all [label = \"ALL\"]" - print "all [color=lightblue,style=filled]" - return - print "%s [label = \"%s\"]" % (pkg_node_name(pkg), pkg) - if mode == PKG_MODE and pkg == rootpkg: - print "%s [color=lightblue,style=filled]" % pkg_node_name(rootpkg) + label = 'ALL' + else: + label = pkg + if pkg == 'all' or (mode == PKG_MODE and pkg == rootpkg): + color = 'lightblue' else: - print "%s [color=grey,style=filled]" % pkg_node_name(pkg) + if pkg.startswith('host') \ + or pkg.startswith('toolchain') \ + or pkg.startswith('rootfs'): + color = 'gainsboro' + else: + color = 'grey' + print "%s [label = \"%s\"]" % (name, label) + print "%s [color=%s,style=filled]" % (name, color) # Print the dependency graph of a package def print_pkg_deps(depth, pkg):
Signature · 1 line
1.8.3.2
PATCH v4 2/9 graphs: add option to remove transitive dependencies in dependency graph
In reply to Yann E. MORINFrom: "Yann E. MORIN" <[email protected]>
Currently, all the dependencies of a package are drawn on the dependency graph, including transitive dependencies (e.g. A->B->C and A->C).
For very big graphs, with lots of packages with lots of dependencies, the dependency graph can be very dense, and transitive dependencies are cluttering the graph.
In some cases, only getting the "build-order" dependencies is enough (e.g. to see what impact a package rebuild would have).
Add a new environment variable to disable drawing transitive dependencies.
Basically, it would turn this graph:
pkg1 ---> pkg2 ---> pkg3 -------------------.
|\__________/ \ \
|\____________________ \ \
| \ \ \
`-> pkg4 ---> pkg5 ---> pkg6 ---> pkg7 ---> pkg8
\__________/into that graph:
pkg1 ---> pkg2 ---> pkg3 -----------.
| \
`-> pkg4 ---> pkg5 ---> pkg6 ---> pkg7 ---> pkg8[Thanks to Samuel for the parser hints]
--- support/scripts/graph-depends | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
support/scripts/graph-depends +49 -0
@@ -40,6 +40,10 @@ parser.add_argument("--package", '-p', metavar="PACKAGE", help="Graph the dependencies of PACKAGE") parser.add_argument("--depth", '-d', metavar="DEPTH", help="Limit the dependency graph to DEPTH levels") +parser.add_argument("--transitive", dest="transitive", action='store_true', + default=True) +parser.add_argument("--no-transitive", dest="transitive", action='store_false', + help="Draw (do not draw) transitive dependencies") args = parser.parse_args() if args.package is None:
@@ -51,6 +55,8 @@ else: if args.depth is not None: max_depth = int(args.depth) +transitive = args.transitive + allpkgs = [] # Execute the "make show-targets" command to get the list of the main
@@ -220,6 +226,49 @@ for dep in dependencies: dict_deps[dep[0]] = [] dict_deps[dep[0]].append(dep[1]) +# This function return True if pkg is a dependency (direct or +# transitive) of pkg2, dependencies being listed in the deps +# dictionary. Returns False otherwise. +def is_dep(pkg,pkg2,deps): + if deps.has_key(pkg2): + for p in deps[pkg2]: + if pkg == p: + return True + if is_dep(pkg,p,deps): + return True + return False + +# This function eliminates transitive dependencies; for example, given +# these dependency chain: A->{B,C} and B->{C}, the A->{C} dependency is +# already covered by B->{C}, so C is a transitive dependency of A, via B. +# The functions does: +# - for each dependency d[i] of the package pkg +# - if d[i] is a dependency of any of the other dependencies d[j] +# - do not keep d[i] +# - otherwise keep d[i] +def remove_transitive_deps(pkg,deps): + d = deps[pkg] + new_d = [] + for i in range(len(d)): + keep_me = True + for j in range(len(d)): + if j==i: + continue + if is_dep(d[i],d[j],deps): + keep_me = False + if keep_me: + new_d.append(d[i]) + return new_d + +# This functions trims down the dependency list of all packages. +def remove_extra_deps(deps): + for pkg in deps.keys(): + if not transitive: + deps[pkg] = remove_transitive_deps(pkg,deps) + return deps + +dict_deps = remove_extra_deps(dict_deps) + # Print the attributes of a node: label and fill-color def print_attrs(pkg): name = pkg_node_name(pkg)
Signature · 1 line
1.8.3.2
PATCH v4 3/9 graphs-depends: merge redundant-dependencies elimination
In reply to Yann E. MORINFrom: "Yann E. MORIN" <[email protected]>
Merge the redundant-dependencies elimination into the newly introduced transitive-dependencies elimination.
This makes the code cleaner and much shorter, because:
- the ('all',pkg) redundant dependency is in fact a transitive dependency, and we now have code to deal with that
- the (pkg,'toolchain') dependency is easy enough to deal with that having a separate function for that is overkill
--- support/scripts/graph-depends | 46 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 37 deletions(-)
support/scripts/graph-depends +9 -37
@@ -146,40 +146,6 @@ def get_all_depends(pkgs): def pkg_node_name(pkg): return pkg.replace("-","") -# Helper function for remove_redundant_deps(). This function tells -# whether package "pkg" is the dependency of another package that is -# not the special "all" package. -def has_redundant_deps(deps, pkg): - for dep in deps: - if dep[0] != "all" and dep[1] == pkg: - return True - return False - -# This function removes redundant dependencies of the special "all" -# package. This "all" package is created to reflect the origin of the -# selection for all packages that are not themselves selected by any -# other package. So for example if you enable libpng, zlib is enabled -# as a dependency. But zlib being selected by libpng, it also appears -# as a dependency of the "all" package. This needlessly complicates -# the generated dependency graph. So when we have the dependency list -# (all -> zlib, all -> libpn, libpng -> zlib), we get rid of the 'all -# -> zlib' dependency, because zlib is already a dependency of a -# regular package. -def remove_redundant_deps(deps): - newdeps = [] - for dep in deps: - if dep[0] == "all" and dep[1] == "toolchain": - newdeps.append(dep) - continue - if dep[0] != "all" and dep[1] != "toolchain": - newdeps.append(dep) - continue - if not has_redundant_deps(deps, dep[1]): - newdeps.append(dep) - continue - sys.stderr.write("Removing redundant dep %s -> %s\n" % (dep[0],dep[1])) - return newdeps - TARGET_EXCEPTIONS = [ "target-generic-securetty", "target-generic-issue",
@@ -217,8 +183,6 @@ if mode == FULL_MODE: elif mode == PKG_MODE: dependencies = get_all_depends([rootpkg]) -dependencies = remove_redundant_deps(dependencies) - # Make the dependencies a dictionnary { 'pkg':[dep1, dep2, ...] } dict_deps = {} for dep in dependencies:
@@ -260,10 +224,18 @@ def remove_transitive_deps(pkg,deps): new_d.append(d[i]) return new_d +# This function removes the dependency on the 'toolchain' package +def remove_toolchain_deps(pkg,deps): + return [p for p in deps[pkg] if not p == 'toolchain'] + # This functions trims down the dependency list of all packages. +# It applies in sequence all the dependency-elimination methods. def remove_extra_deps(deps): for pkg in deps.keys(): - if not transitive: + if not pkg == 'all': + deps[pkg] = remove_toolchain_deps(pkg,deps) + for pkg in deps.keys(): + if not transitive or pkg == 'all': deps[pkg] = remove_transitive_deps(pkg,deps) return deps
Signature · 1 line
1.8.3.2
PATCH v4 4/9 graph-depends: handle the depth argument in a more pythonic way
In reply to Yann E. MORINFrom: "Yann E. MORIN" <[email protected]>
Add some comment as well, enhance help text.
[thanks to Samuel for the hints to make it even more pythonic]
--- support/scripts/graph-depends | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
support/scripts/graph-depends +5 -4
@@ -33,13 +33,15 @@ FULL_MODE = 1 PKG_MODE = 2 mode = 0 + +# Limit drawing the dependency graph to this depth. 0 means 'no limit'. max_depth = 0 parser = argparse.ArgumentParser(description="Graph pacakges dependencies") parser.add_argument("--package", '-p', metavar="PACKAGE", help="Graph the dependencies of PACKAGE") -parser.add_argument("--depth", '-d', metavar="DEPTH", - help="Limit the dependency graph to DEPTH levels") +parser.add_argument("--depth", '-d', metavar="DEPTH", dest="depth", type=int, default=0, + help="Limit the dependency graph to DEPTH levels; 0 means no limit.") parser.add_argument("--transitive", dest="transitive", action='store_true', default=True) parser.add_argument("--no-transitive", dest="transitive", action='store_false',
@@ -52,8 +54,7 @@ else: mode = PKG_MODE rootpkg = args.package -if args.depth is not None: - max_depth = int(args.depth) +max_depth = args.depth transitive = args.transitive
Signature · 1 line
1.8.3.2
PATCH v4 5/9 graph-depends: add option to set the colours
In reply to Yann E. MORINFrom: "Yann E. MORIN" <[email protected]>
--- support/scripts/graph-depends | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
support/scripts/graph-depends +20 -3
@@ -42,6 +42,12 @@ parser.add_argument("--package", '-p', metavar="PACKAGE", help="Graph the dependencies of PACKAGE") parser.add_argument("--depth", '-d', metavar="DEPTH", dest="depth", type=int, default=0, help="Limit the dependency graph to DEPTH levels; 0 means no limit.") +parser.add_argument("--colours", "-c", metavar="COLOR_LIST", dest="colours", + default="lightblue,grey,gainsboro", + help="Comma-separated list of the three colours to use" \ + + " to draw the top-level package, the target" \ + + " packages, and the host packages, in this order." \ + + " Defaults to: 'lightblue,grey,gainsboro'") parser.add_argument("--transitive", dest="transitive", action='store_true', default=True) parser.add_argument("--no-transitive", dest="transitive", action='store_false',
@@ -58,6 +64,17 @@ max_depth = args.depth transitive = args.transitive +# Get the colours: we need exactly three colours, +# so no need not split more than 4 +# We'll let 'dot' validate the colours... +colours = args.colours.split(',',4) +if len(colours) != 3: + sys.stderr.write("Error: incorrect colour list '%s'\n" % args.colours) + sys.exit(1) +root_colour = colours[0] +target_colour = colours[1] +host_colour = colours[2] + allpkgs = [] # Execute the "make show-targets" command to get the list of the main
@@ -250,14 +267,14 @@ def print_attrs(pkg): else: label = pkg if pkg == 'all' or (mode == PKG_MODE and pkg == rootpkg): - color = 'lightblue' + color = root_colour else: if pkg.startswith('host') \ or pkg.startswith('toolchain') \ or pkg.startswith('rootfs'): - color = 'gainsboro' + color = host_colour else: - color = 'grey' + color = target_colour print "%s [label = \"%s\"]" % (name, label) print "%s [color=%s,style=filled]" % (name, color)
Signature · 1 line
1.8.3.2
PATCH v4 6/9 graph-depends: document the 'transitive' variable
In reply to Yann E. MORINFrom: "Yann E. MORIN" <[email protected]>
Although unnecessary (we already have initialisation via the parser), initialise the 'transitive' option, and document it at the same time.
---
Changes v3 -> v4:
- fix commit log s/max_depth/transitive/ (Thomas)
--- support/scripts/graph-depends | 3 +++ 1 file changed, 3 insertions(+)
support/scripts/graph-depends +3 -0
@@ -37,6 +37,9 @@ mode = 0 # Limit drawing the dependency graph to this depth. 0 means 'no limit'. max_depth = 0 +# Whether to draw the transitive dependencies +transitive = True + parser = argparse.ArgumentParser(description="Graph pacakges dependencies") parser.add_argument("--package", '-p', metavar="PACKAGE", help="Graph the dependencies of PACKAGE")
Signature · 1 line
1.8.3.2
PATCH v4 7/9 graph-depends: rename the mode constants
In reply to Yann E. MORINFrom: "Yann E. MORIN" <[email protected]>
This is ugly, since Python does not have enum constructs, so by moving the 'type' of the constant ('MODE' here) to the beginning, we get an artificial 'namespace' for the constants.
--- support/scripts/graph-depends | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
support/scripts/graph-depends +8 -12
@@ -25,13 +25,9 @@ import sys import subprocess import argparse -# In FULL_MODE, we draw the full dependency graph for all selected -# packages -FULL_MODE = 1 - -# In PKG_MODE, we only draw the dependency graph for a given package -PKG_MODE = 2 - +# Modes of operation: +MODE_FULL = 1 # draw full dependency graph for all selected packages +MODE_PKG = 2 # draw dependency graph for a given package mode = 0 # Limit drawing the dependency graph to this depth. 0 means 'no limit'.
@@ -58,9 +54,9 @@ parser.add_argument("--no-transitive", dest="transitive", action='store_false', args = parser.parse_args() if args.package is None: - mode = FULL_MODE + mode = MODE_FULL else: - mode = PKG_MODE + mode = MODE_PKG rootpkg = args.package max_depth = args.depth
@@ -183,7 +179,7 @@ TARGET_EXCEPTIONS = [ # 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 == FULL_MODE: +if mode == MODE_FULL: targets = get_targets() dependencies = [] allpkgs.append('all')
@@ -201,7 +197,7 @@ if mode == FULL_MODE: # In pkg mode, start directly with get_all_depends() on the requested # package -elif mode == PKG_MODE: +elif mode == MODE_PKG: dependencies = get_all_depends([rootpkg]) # Make the dependencies a dictionnary { 'pkg':[dep1, dep2, ...] }
@@ -269,7 +265,7 @@ def print_attrs(pkg): label = 'ALL' else: label = pkg - if pkg == 'all' or (mode == PKG_MODE and pkg == rootpkg): + if pkg == 'all' or (mode == MODE_PKG and pkg == rootpkg): color = root_colour else: if pkg.startswith('host') \
Signature · 1 line
1.8.3.2
PATCH v4 8/9 graph-depends: add option to pass arbitrary dot options
In reply to Yann E. MORINFrom: "Yann E. MORIN" <[email protected]>
Kids nowaday seem to prefer a left-to-right drawing rather than the more conventional and historical top-down drawing.
Rather than multiply the number of environment variables, just add a single one where the user can pass arbitrary dot options, such as:
make BR2_GRAPH_DOT_OPTS=-Grankdir=LR graph-depends
--- Makefile | 2 +- package/pkg-generic.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Makefile +1 -1
@@ -675,7 +675,7 @@ graph-depends: @cd "$(CONFIG_DIR)"; \ $(TOPDIR)/support/scripts/graph-depends $(BR2_GRAPH_DEPS_OPTS) \ |tee $(O)/graphs/$(@).dot \ - |dot -T$(BR_GRAPH_OUT) -o $(O)/graphs/$(@).$(BR_GRAPH_OUT) + |dot $(BR2_GRAPH_DOT_OPTS) -T$(BR_GRAPH_OUT) -o $(O)/graphs/$(@).$(BR_GRAPH_OUT) else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
package/pkg-generic.mk +1 -1
@@ -533,7 +533,7 @@ $(1)-graph-depends: @cd "$(CONFIG_DIR)"; \ $(TOPDIR)/support/scripts/graph-depends -p $(1) $(BR2_GRAPH_DEPS_OPTS) \ |tee $(O)/graphs/$$(@).dot \ - |dot -T$(BR_GRAPH_OUT) -o $(O)/graphs/$$(@).$(BR_GRAPH_OUT) + |dot $(BR2_GRAPH_DOT_OPTS) -T$(BR_GRAPH_OUT) -o $(O)/graphs/$$(@).$(BR_GRAPH_OUT) $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
Signature · 1 line
1.8.3.2
PATCH v4 9/9 manual: document the new graph-depends options
In reply to Yann E. MORINFrom: "Yann E. MORIN" <[email protected]>
--- docs/manual/common-usage.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
docs/manual/common-usage.txt +10 -1
@@ -94,6 +94,8 @@ to +make+ or set in the environment: default), or +png+. * +BR2_GRAPH_DEPS_OPTS+ to pass extra options to the dependency graph; see xref:graph-depends[] for the accepted options +* +BR2_GRAPH_DOT_OPTS+ is passed verbatim as options to the +dot+ utility to + draw the dependency graph. An example that uses config files located in the toplevel directory and in your $HOME:
@@ -204,8 +206,15 @@ The +graph-depends+ behaviour can be controlled by setting options in the * +--depth N+, +-d N+, to limit the dependency depth to +N+ levels. The default, +0+, means no limit. +* +--transitive+, +--no-transitive+, to draw (or not) the transitive + dependencies. The default is to draw transitive dependencies. + +* +--colours R,T,H+, the comma-separated list of colours to draw the + root package (+R+), the target packages (+T+) and the host packages + (+H+). Defaults to: +lightblue,grey,gainsboro+ + -------------------------------- -BR2_GRAPH_DEPS_OPTS='-d 3' make graph-depends +BR2_GRAPH_DEPS_OPTS='-d 3 --no-transitive --colours=red,green,blue' make graph-depends -------------------------------- === Graphing the build duration
Signature · 1 line
1.8.3.2
v4 cover graph-depends improvements (branch yem/graphs)
In reply to Yann E. MORINDear Yann E. MORIN,
Quoted 5 lines · Yann E. MORIN
This series brings a few improvements to the graph-depends utility:
- add option to remove transitive dependencies
- add option to pas arbitrary args to the dot utility
- cleanup and re-arrange the code
Patches applied, thanks a lot!
A few comments though:
- I believe we should make the transitive option the default one. It really makes the graph a lot more readable.
- I saw some discussions about the colors, and I agree with Yann that the default colors chosen to distinguish the various types of packages (host, target, toolchain, rootfs) are too close to each other. Initially, I did not even notice the difference between colors.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com