poky/scripts/oe-depends-dot
Robert Yang 1b96585b92 scripts/oe-depends-dot: add it to handle dot files
Add it to handle recipe-depends.dot and task-depends.dot. E.g.:

* Print why rpm is built
  $ oe-depends-dot -k rpm --why/-w recipe-depends.dot
  Because: core-image-sato libdnf libsolv dnf

* Print bzip2-native's depends
  $ oe-depends-dot -k bzip2-native --depends/-d recipe-depends.dot
  Depends: automake-native gnu-config-native libtool-native quilt-native autoconf-native

* Remove duplicated dependencies to reduce the size of the dot files.
  For example, A->B, B->C, A->C, then A->C can be removed. The dot files are too
  big, we nearly couldn't use 'dot -T' to generate pictcures for target recipes,
  remove the duplicated dependencies makes is it possible.
  $ bitbake core-image-sato -g
  $ oe-depends-dot -r recipe-depends.dot
  Saving reduced dot file to recipe-depends-reduced.dot
  $ du -sh recipe-depends*.dot
  608K    recipe-depends.dot
  32K     recipe-depends-reduced.dot

  It has been recuded from 608K to 32K, now we can generate a picture,
  otherwise, it is too big:
  $ dot -Tpng recipe-depends-reduced.dot -O

It also can handle task-depends.dot.

(From OE-Core rev: 7dc7860691304d63e7ad728d2180474906fe0a5c)

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-01-19 12:37:13 +00:00

4.5 KiB
Executable File

#!/usr/bin/env python3

Copyright (C) 2018 Wind River Systems, Inc.

This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License version 2 as

published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program; if not, write to the Free Software

Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import os import sys import argparse import logging import re

class Dot(object): def init(self): parser = argparse.ArgumentParser( description="Analyse recipe-depends.dot generated by bitbake -g", epilog="Use %(prog)s --help to get help") parser.add_argument("dotfile", help = "Specify the dotfile", nargs = 1, action='store', default='') parser.add_argument("-k", "--key", help = "Specify the key, e.g., recipe name", action="store", default='') parser.add_argument("-d", "--depends", help = "Print the key's dependencies", action="store_true", default=False) parser.add_argument("-w", "--why", help = "Print why the key is built", action="store_true", default=False) parser.add_argument("-r", "--remove", help = "Remove duplicated dependencies to reduce the size of the dot files." " For example, A->B, B->C, A->C, then A->C can be removed.", action="store_true", default=False)

    self.args = parser.parse_args()

    if len(sys.argv) != 3 and len(sys.argv) < 5:
        print('ERROR: Not enough args, see --help for usage')

def main(self):
    #print(self.args.dotfile[0])
    # The format is {key: depends}
    depends = {}
    with open(self.args.dotfile[0], 'r') as f:
        for line in f.readlines():
            if ' -> ' not in line:
                continue
            line_no_quotes = line.replace('"', '')
            m = re.match("(.*) -> (.*)", line_no_quotes)
            if not m:
                print('WARNING: Found unexpected line: %s' % line)
                continue
            key = m.group(1)
            if key == "meta-world-pkgdata":
                continue
            dep = m.group(2)
            if key in depends:
                if not key in depends[key]:
                    depends[key].add(dep)
                else:
                    print('WARNING: Fonud duplicated line: %s' % line)
            else:
                depends[key] = set()
                depends[key].add(dep)

    if self.args.remove:
        reduced_depends = {}
        for k, deps in depends.items():
            child_deps = set()
            added = set()
            # Both direct and indirect depends are already in the dict, so
            # we don't have to do this recursively.
            for dep in deps:
                if dep in depends:
                    child_deps |= depends[dep]

            reduced_depends[k] = deps - child_deps
            outfile= '%s-reduced%s' % (self.args.dotfile[0][:-4], self.args.dotfile[0][-4:])
        with open(outfile, 'w') as f:
            print('Saving reduced dot file to %s' % outfile)
            f.write('digraph depends {\n')
            for k, v in reduced_depends.items():
                for dep in v:
                    f.write('"%s" -> "%s"\n' % (k, dep))
            f.write('}\n')
        sys.exit(0)

    if self.args.key not in depends:
        print("ERROR: Can't find key %s in %s" % (self.args.key, self.args.dotfile[0]))
        sys.exit(1)

    if self.args.depends:
        if self.args.key in depends:
            print('Depends: %s' % ' '.join(depends[self.args.key]))

    reverse_deps = []
    if self.args.why:
        for k, v in depends.items():
            if self.args.key in v and not k in reverse_deps:
                reverse_deps.append(k)
        print('Because: %s' % ' '.join(reverse_deps))

if name == "main": try: dot = Dot() ret = dot.main() except Exception as esc: ret = 1 import traceback traceback.print_exc() sys.exit(ret)