libsdl-x11: use newer sdl.m4 macro from svn
[openembedded.git] / classes / package_dbg.bbclass
blob39dceaf9b345e3c2338610b785ac3cc7e1396d45
1 # package_dbg.bbclass: populate -dbg versions for each package in PACKAGES
3 # Copyright (c) 2009 MontaVista Software, Inc.  All rights reserved.
5 # Released under the MIT license (see LICENSE.MIT for the terms)
8 inherit package
11 PACKAGE_DBG_DIRS = "${bindir} ${sbindir} \
12                     ${libexecdir} ${libdir} \
13                     ${base_bindir} ${base_sbindir} \
14                     ${base_libdir}"
15 PACKAGE_DBG_DESC = "Debugging files for %s"
16 PACKAGE_DBG_EXCLUDE = "${PN}-locale* ${PN}-doc ${PN}-dev *-dbg"
19 def __find(dir):
20     """ Given a directory, recurses into that directory,
21     returning all files. """
23     from os import walk
24     from os.path import join
26     for root, dirs, files in walk(dir):
27         for file in files:
28             yield join(root, file)
30 def __package_get_files(pkg, d):
31     """ Obtains a list of files to be included in a package.
33     Starting from the FILES_<pkg> variable, it expands any globs in the list,
34     which removes missing files, and traverses any directories in the list.
36     It does *not* remove files which are also in other packages, it's left
37     to the user's discretion whether to allow overlap. """
39     from glob import glob
40     from os.path import join, isdir, islink
42     installdir = d.getVar("D", True)
43     installdirlen = len(installdir)
45     files = (d.getVar("FILES_%s" % pkg, True) or "").split()
46     for globbed in (glob(join(installdir, file[1:])) for file in files):
47         for path in globbed:
48             if isdir(path) and not islink(path):
49                 for file in __find(path):
50                     yield file[installdirlen:]
51             else:
52                 yield path[installdirlen:]
54 def add_dbg_packages(d):
55     from fnmatch import fnmatch
57     packages = d.getVar("PACKAGES", True).split()
58     excludes = d.getVar("PACKAGE_DBG_EXCLUDE", True).split()
60     for pkg in tuple(packages):
61         if any(fnmatch(pkg, excluded) for excluded in excludes):
62             continue
64         dbgpkg = "%s-dbg" % pkg
65         if not dbgpkg in packages:
66             packages.insert(0, dbgpkg)
68     d.setVar("PACKAGES", " ".join(packages))
71 # Add the -dbg packages to PACKAGES
72 python () {
73     from bb.data import inherits_class as inherits
75     # Task handles its own -dbg versions of its packages at the moment
76     if not inherits("task", d):
77         dynpkgs = d.getVar("PACKAGES_DYNAMIC", True).split()
78         dynpkgs += ["%s-dbg" % dyn for dyn in dynpkgs]
79         d.setVar("PACKAGES_DYNAMIC", " ".join(dynpkgs))
81         add_dbg_packages(d)
84 python populate_packages_prepend () {
85         from bb.data import inherits_class as inherits
87         if not inherits("task", d):
88                 bb.build.exec_func("package_do_dbg", d)
91 # Populate the -dbg subpackage metadata
92 python package_do_dbg() {
93     """ Populate the -dbg subpackage metadata. """
95     from os.path import join, basename, dirname
97     def setVar(key, val):
98         if d.getVar(key, val) is None:
99             d.setVar(key, val)
101     add_dbg_packages(d)
102     packages = d.getVar("PACKAGES", True).split()
103     desc = d.getVar("PACKAGE_DBG_DESC", True)
104     debug_dirs = d.getVar("PACKAGE_DBG_DIRS", True).split()
106     done = []
107     for pkgname in tuple(packages):
108         files = tuple(__package_get_files(pkgname, d))
109         dbg = [join(dirname(file), ".debug", basename(file))
110                for file in files
111                if not file in done and
112                   any(file.startswith(dir) for dir in debug_dirs)]
113         done.extend(files)
115         if dbg:
116             setVar("FILES_%s-dbg" % pkgname, " ".join(dbg))
117             setVar("DESCRIPTION_%s-dbg" % pkgname, desc % pkgname)
118             setVar("RDEPENDS_%s-dbg" % pkgname, pkgname)
119         else:
120             try:
121                 packages.remove("%s-dbg" % pkgname)
122             except ValueError:
123                 pass
124     d.setVar("PACKAGES", " ".join(packages))