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_DIRS = "${bindir} ${sbindir} \
12 ${libexecdir} ${libdir} \
13 ${base_bindir} ${base_sbindir} \
15 PACKAGE_DBG_DESC = "Debugging files for %s"
16 PACKAGE_DBG_EXCLUDE = "${PN}-locale* ${PN}-doc ${PN}-dev *-dbg"
20 """ Given a directory, recurses into that directory,
21 returning all files. """
24 from os.path import join
26 for root, dirs, files in walk(dir):
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. """
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):
48 if isdir(path) and not islink(path):
49 for file in __find(path):
50 yield file[installdirlen:]
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):
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
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))
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
98 if d.getVar(key, val) is None:
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()
107 for pkgname in tuple(packages):
108 files = tuple(__package_get_files(pkgname, d))
109 dbg = [join(dirname(file), ".debug", basename(file))
111 if not file in done and
112 any(file.startswith(dir) for dir in debug_dirs)]
116 setVar("FILES_%s-dbg" % pkgname, " ".join(dbg))
117 setVar("DESCRIPTION_%s-dbg" % pkgname, desc % pkgname)
118 setVar("RDEPENDS_%s-dbg" % pkgname, pkgname)
121 packages.remove("%s-dbg" % pkgname)
124 d.setVar("PACKAGES", " ".join(packages))