From patchwork Sun Apr 13 20:42:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yann E. MORIN" X-Patchwork-Id: 338789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137]) by ozlabs.org (Postfix) with ESMTP id 235A81400DA for ; Mon, 14 Apr 2014 06:43:14 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id A59BC8B73D; Sun, 13 Apr 2014 20:43:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aBsGvrG148YY; Sun, 13 Apr 2014 20:43:08 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 4A6D78B74A; Sun, 13 Apr 2014 20:43:06 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 2EE9E1BF867 for ; Sun, 13 Apr 2014 20:42:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2B20F319C1 for ; Sun, 13 Apr 2014 20:42:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VCGdniT1iWd7 for ; Sun, 13 Apr 2014 20:42:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-we0-f172.google.com (mail-we0-f172.google.com [74.125.82.172]) by silver.osuosl.org (Postfix) with ESMTPS id E05E030ED0 for ; Sun, 13 Apr 2014 20:42:52 +0000 (UTC) Received: by mail-we0-f172.google.com with SMTP id t61so7422280wes.17 for ; Sun, 13 Apr 2014 13:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=3I6Qzhk5mXsrUfwC+bx+0MCxihP6WRAFuUT8OoXzqoA=; b=iZPqc3g8ekqe8xL6h7X9+amTup8pxmGKnaO5Slp/e5UXPSe9ERMKHXsH+0ozdjqkyT Y1C3Y0tNjMS3Ujh0tRpoaUN2cTz+FfA3W2i5vOJ3r2GZRzwrlzxLAwx0rYc7umCH08al bBfM9vqH1UTxfTKeIwa7R+6+gJvGPz2TesRhMuwCJs8CGUeuZUO/OP1bN3jpEm2k3m1K 8btc6reN7Zg2MkzkI45CWWvxQoqPHEhP23QlJp4X7R63Y66fMFedLL0b0NcBdCCa/g78 H18st7XGtu1xDWuznsJRV2JP8q1wKyRxWQx8xZqgvproQsPZlGcmTVBLqd9+x1pK4nPn a2sw== X-Received: by 10.180.11.36 with SMTP id n4mr6882812wib.4.1397421771428; Sun, 13 Apr 2014 13:42:51 -0700 (PDT) Received: from gourin.bzh.lan (ks3095497.kimsufi.com. [94.23.60.27]) by mx.google.com with ESMTPSA id cw2sm21801083wjb.39.2014.04.13.13.42.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Apr 2014 13:42:50 -0700 (PDT) From: "Yann E. MORIN" To: buildroot@buildroot.org Date: Sun, 13 Apr 2014 22:42:39 +0200 Message-Id: <388c5a2b6f32ea7e20bfcb968703ef7d5cd3af26.1397421554.git.yann.morin.1998@free.fr> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: References: Cc: Thomas Petazzoni , "Yann E. MORIN" Subject: [Buildroot] [PATCH 3/6] support/graph-depends: add option to limit the depth of the graph X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net From: "Yann E. MORIN" Currently, the complete dependency chain of a package is used to generate the dependency graph. When this dependency chain is long, the generated graph becomes almost unreadable. However, it is often sufficient to get the first few levels of dependency of a package. Add a new variable BR2_GRAPH_DEPTH, that the user can set to limit the depth of the dependency list. Signed-off-by: "Yann E. MORIN" Cc: Thomas Petazzoni --- Makefile | 3 ++- package/pkg-generic.mk | 2 +- support/scripts/graph-depends | 49 ++++++++++++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index b0eec7f..467e21c 100644 --- a/Makefile +++ b/Makefile @@ -150,6 +150,7 @@ endif # Need that early, before we scan packages # Avoids doing the $(or...) everytime BR_GRAPH_OUT := $(or $(BR2_GRAPH_OUT),pdf) +BR_GRAPH_DEPTH := $(or $(BR2_GRAPH_DEPTH),0) BUILD_DIR:=$(BASE_DIR)/build BINARIES_DIR:=$(BASE_DIR)/images @@ -672,7 +673,7 @@ graph-build: $(O)/build/build-time.log graph-depends: @$(INSTALL) -d $(O)/graphs @cd "$(CONFIG_DIR)"; \ - $(TOPDIR)/support/scripts/graph-depends \ + $(TOPDIR)/support/scripts/graph-depends -d $(BR_GRAPH_DEPTH) \ |dot -T$(BR_GRAPH_OUT) -o $(O)/graphs/$(@).$(BR_GRAPH_OUT) else # ifeq ($(BR2_HAVE_DOT_CONFIG),y) diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk index 080ee56..c162902 100644 --- a/package/pkg-generic.mk +++ b/package/pkg-generic.mk @@ -495,7 +495,7 @@ $(1)-show-depends: $(1)-graph-depends: @$(INSTALL) -d $(O)/graphs @cd "$(CONFIG_DIR)"; \ - $(TOPDIR)/support/scripts/graph-depends -p $(1) \ + $(TOPDIR)/support/scripts/graph-depends -p $(1) -d $(BR_GRAPH_DEPTH) \ |dot -T$(BR_GRAPH_OUT) -o $(O)/graphs/$$(@).$(BR_GRAPH_OUT) $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN) diff --git a/support/scripts/graph-depends b/support/scripts/graph-depends index fc3cadd..ebf511b 100755 --- a/support/scripts/graph-depends +++ b/support/scripts/graph-depends @@ -8,6 +8,8 @@ # dependencies for the current configuration. # If '-p ' is specified, graph-depends will draw a graph # of dependencies for the given package name. +# If '-d ' is specified, graph-depends will limit the depth of +# the dependency graph to 'depth' levels. # # Limitations # @@ -31,10 +33,13 @@ FULL_MODE = 1 PKG_MODE = 2 mode = 0 +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") args = parser.parse_args() if args.package == None: @@ -43,6 +48,9 @@ else: mode = PKG_MODE rootpkg = args.package +if args.depth != None: + max_depth = int(args.depth) + allpkgs = [] # Execute the "make show-targets" command to get the list of the main @@ -193,6 +201,7 @@ if mode == FULL_MODE: deps = get_all_depends(filtered_targets) if deps != None: dependencies += deps + rootpkg = 'all' # In pkg mode, start directly with get_all_depends() on the requested # package @@ -201,26 +210,42 @@ elif mode == PKG_MODE: dependencies = remove_redundant_deps(dependencies) -# Start printing the graph data -print "digraph G {" - -# First, the dependencies. Usage of set allows to remove duplicated -# dependencies in the graph -for dep in set(dependencies): - print "%s -> %s" % (pkg_node_name(dep[0]), pkg_node_name(dep[1])) +# Make the dependencies a dictionnary { 'pkg':[dep1, dep2, ...] } +dict_deps = {} +for dep in dependencies: + if not dict_deps.has_key(dep[0]): + dict_deps[dep[0]] = [] + dict_deps[dep[0]].append(dep[1]) -# Then, the node attributes: color, style and label. -for pkg in allpkgs: +# Print the attributes of a node: label and fill-color +def print_attrs(pkg): if pkg == 'all': print "all [label = \"ALL\"]" print "all [color=lightblue,style=filled]" - continue - + 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) else: print "%s [color=grey,style=filled]" % pkg_node_name(pkg) +# Print the dependency graph of a package +def print_pkg_deps(depth, pkg): + if pkg in done_deps: + return + done_deps.append(pkg) + print_attrs(pkg) + if not dict_deps.has_key(pkg): + return + if max_depth == 0 or depth < max_depth: + for d in dict_deps[pkg]: + print "%s -> %s" % (pkg_node_name(pkg), pkg_node_name(d)) + print_pkg_deps(depth+1, d) + +# Start printing the graph data +print "digraph G {" + +done_deps = [] +print_pkg_deps(0, rootpkg) + print "}"