From: Yann E. MORIN Date: Sun, 7 Feb 2016 21:34:25 +0000 (+0100) Subject: support/graph-depends: add option to specify output file X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a3f75bcc764d5136fe79f2b734c37068270dde28;p=buildroot.git support/graph-depends: add option to specify output file Currently, graph-depends outputs the dotfile program to stdout, and uses stderr to trace the dependencies it is currently looking for. Redirection was done because the output was directly piped into the dot program to generate the final PDF/SVG/... dependency graph, but that meant that an error in the graph-depends script was never caught (because shell pipes only return the final command exit status, and an empty dot program is perfectly valid so dot would not complain). Add an option to tell graph-depends where to store the generated dot program, and keep stdout as the default if not specified. Signed-off-by: "Yann E. MORIN" Cc: Thomas Petazzoni Cc: Samuel Martin [Thomas: rename metavar from DOT_FILE to OUT_FILE for consistency with the rest of the new option naming.] Signed-off-by: Thomas Petazzoni --- diff --git a/support/scripts/graph-depends b/support/scripts/graph-depends index fd8ad2f590..c0c6a94a21 100755 --- a/support/scripts/graph-depends +++ b/support/scripts/graph-depends @@ -38,6 +38,8 @@ max_depth = 0 transitive = True parser = argparse.ArgumentParser(description="Graph packages dependencies") +parser.add_argument("--outfile", "-o", metavar="OUT_FILE", dest="outfile", + help="File in which to generate the dot representation") 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, @@ -60,6 +62,11 @@ parser.add_argument("--no-transitive", dest="transitive", action='store_false', help="Draw (do not draw) transitive dependencies") args = parser.parse_args() +if args.outfile is None: + outfile = sys.stdout +else: + outfile = open(args.outfile, "wb") + if args.package is None: mode = MODE_FULL else: @@ -339,10 +346,10 @@ def print_attrs(pkg): color = target_colour version = dict_version.get(pkg) if version == "virtual": - print("%s [label = <%s>]" % (name, label)) + outfile.write("%s [label = <%s>]\n" % (name, label)) else: - print("%s [label = \"%s\"]" % (name, label)) - print("%s [color=%s,style=filled]" % (name, color)) + outfile.write("%s [label = \"%s\"]\n" % (name, label)) + outfile.write("%s [color=%s,style=filled]\n" % (name, color)) # Print the dependency graph of a package def print_pkg_deps(depth, pkg): @@ -369,13 +376,13 @@ def print_pkg_deps(depth, pkg): add = False break if add: - print("%s -> %s" % (pkg_node_name(pkg), pkg_node_name(d))) + outfile.write("%s -> %s\n" % (pkg_node_name(pkg), pkg_node_name(d))) print_pkg_deps(depth+1, d) # Start printing the graph data -print("digraph G {") +outfile.write("digraph G {\n") done_deps = [] print_pkg_deps(0, rootpkg) -print("}") +outfile.write("}\n")