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)
11 PACKAGE_DBG_DESC = "Debugging files for %s"
12 PACKAGE_DBG_EXCLUDE = "${PN}-locale* ${PN}-doc ${PN}-dev *-dbg"
16 """ Given a directory, recurses into that directory,
17 returning all files. """
20 from os.path import join
22 for root, dirs, files in walk(dir):
24 yield join(root, file)
26 def __package_get_files(pkg, d):
27 """ Obtains a list of files to be included in a package.
29 Starting from the FILES_<pkg> variable, it expands any globs in the list,
30 which removes missing files, and traverses any directories in the list.
32 It does *not* remove files which are also in other packages, it's left
33 to the user's discretion whether to allow overlap. """
36 from os.path import join, isdir, islink
38 installdir = d.getVar("D", True)
39 installdirlen = len(installdir)
41 files = (d.getVar("FILES_%s" % pkg, True) or "").split()
42 for globbed in (glob(join(installdir, file[1:])) for file in files):
44 if isdir(path) and not islink(path):
45 for file in __find(path):
46 yield file[installdirlen:]
48 yield path[installdirlen:]
50 def add_dbg_packages(d):
51 from fnmatch import fnmatch
53 packages = d.getVar("PACKAGES", True).split()
54 excludes = d.getVar("PACKAGE_DBG_EXCLUDE", True).split()
56 for pkg in tuple(packages):
57 if any(fnmatch(pkg, excluded) for excluded in excludes):
60 dbgpkg = "%s-dbg" % pkg
61 if not dbgpkg in packages:
62 packages.insert(0, dbgpkg)
64 d.setVar("PACKAGES", " ".join(packages))
67 # Add the -dbg packages to PACKAGES
69 from bb.data import inherits_class as inherits
71 # Task handles its own -dbg versions of its packages at the moment
72 if not inherits("task", d):
73 dynpkgs = d.getVar("PACKAGES_DYNAMIC", True).split()
74 dynpkgs += ["%s-dbg" % dyn for dyn in dynpkgs]
75 d.setVar("PACKAGES_DYNAMIC", " ".join(dynpkgs))
80 python populate_packages_prepend () {
81 from bb.data import inherits_class as inherits
83 if not inherits("task", d):
84 bb.build.exec_func("package_do_dbg", d)
87 # Populate the -dbg subpackage metadata
88 python package_do_dbg() {
89 """ Populate the -dbg subpackage metadata. """
91 from os.path import join, basename, dirname
94 if d.getVar(key, val) is None:
98 packages = d.getVar("PACKAGES", True).split()
99 desc = d.getVar("PACKAGE_DBG_DESC", True)
102 for pkgname in tuple(packages):
103 files = tuple(__package_get_files(pkgname, d))
104 dbg = [join(dirname(file), ".debug", basename(file))
110 setVar("FILES_%s-dbg" % pkgname, " ".join(dbg))
111 setVar("DESCRIPTION_%s-dbg" % pkgname, desc % pkgname)
112 setVar("RDEPENDS_%s-dbg" % pkgname, pkgname)
115 packages.remove("%s-dbg" % pkgname)
118 d.setVar("PACKAGES", " ".join(packages))