2 # General packaging help functions
5 PKGDEST = "${WORKDIR}/install"
7 def legitimize_package_name(s):
9 Make sure package names are legitimate strings
16 return ('\u%s' % cp).decode('unicode_escape').encode('utf-8')
18 # Handle unicode codepoints encoded as <U0123>, as in glibc locale files.
19 s = re.sub('<U([0-9A-Fa-f]{1,4})>', fixutf, s)
21 # Remaining package name validity fixes
22 return s.lower().replace('_', '-').replace('@', '+').replace(',', '+').replace('/', '-')
24 def do_split_packages(d, root, file_regex, output_pattern, description, postinst=None, recursive=False, hook=None, extra_depends=None, aux_files_pattern=None, postrm=None, allow_dirs=False, prepend=False, match_path=False, aux_files_pattern_verbatim=None):
26 Used in .bb files to split up dynamically generated subpackages of a
27 given package, usually plugins or modules.
29 import os, os.path, bb
31 dvar = bb.data.getVar('D', d, 1)
33 bb.error("D not defined")
36 packages = bb.data.getVar('PACKAGES', d, 1).split()
39 postinst = '#!/bin/sh\n' + postinst + '\n'
41 postrm = '#!/bin/sh\n' + postrm + '\n'
43 objs = os.listdir(dvar + root)
46 for walkroot, dirs, files in os.walk(dvar + root):
48 relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1)
52 if extra_depends == None:
53 # This is *really* broken
55 # At least try and patch it up I guess...
56 if mainpkg.find('-dbg'):
57 mainpkg = mainpkg.replace('-dbg', '')
58 if mainpkg.find('-dev'):
59 mainpkg = mainpkg.replace('-dev', '')
60 extra_depends = mainpkg
65 m = re.match(file_regex, o)
67 m = re.match(file_regex, os.path.basename(o))
71 f = os.path.join(dvar + root, o)
72 mode = os.lstat(f).st_mode
73 if not (stat.S_ISREG(mode) or (allow_dirs and stat.S_ISDIR(mode))):
75 on = legitimize_package_name(m.group(1))
76 pkg = output_pattern % on
77 if not pkg in packages:
79 packages = [pkg] + packages
82 the_files = [os.path.join(root, o)]
84 if type(aux_files_pattern) is list:
85 for fp in aux_files_pattern:
86 the_files.append(fp % on)
88 the_files.append(aux_files_pattern % on)
89 if aux_files_pattern_verbatim:
90 if type(aux_files_pattern_verbatim) is list:
91 for fp in aux_files_pattern_verbatim:
92 the_files.append(fp % m.group(1))
94 the_files.append(aux_files_pattern_verbatim % m.group(1))
95 bb.data.setVar('FILES_' + pkg, " ".join(the_files), d)
96 if extra_depends != '':
97 the_depends = bb.data.getVar('RDEPENDS_' + pkg, d, 1)
99 the_depends = '%s %s' % (the_depends, extra_depends)
101 the_depends = extra_depends
102 bb.data.setVar('RDEPENDS_' + pkg, the_depends, d)
103 bb.data.setVar('DESCRIPTION_' + pkg, description % on, d)
105 bb.data.setVar('pkg_postinst_' + pkg, postinst, d)
107 bb.data.setVar('pkg_postrm_' + pkg, postrm, d)
109 oldfiles = bb.data.getVar('FILES_' + pkg, d, 1)
111 bb.fatal("Package '%s' exists but has no files" % pkg)
112 bb.data.setVar('FILES_' + pkg, oldfiles + " " + os.path.join(root, o), d)
114 hook(f, pkg, file_regex, output_pattern, m.group(1))
116 bb.data.setVar('PACKAGES', ' '.join(packages), d)
118 PACKAGE_DEPENDS += "file-native"
122 if bb.data.getVar('PACKAGES', d, True) != '':
123 deps = bb.data.getVarFlag('do_package', 'depends', d) or ""
124 for dep in (bb.data.getVar('PACKAGE_DEPENDS', d, True) or "").split():
125 deps += " %s:do_populate_staging" % dep
126 bb.data.setVarFlag('do_package', 'depends', deps, d)
128 deps = (bb.data.getVarFlag('do_package', 'deptask', d) or "").split()
129 # shlibs requires any DEPENDS to have already packaged for the *.list files
130 deps.append("do_package")
131 bb.data.setVarFlag('do_package', 'deptask', " ".join(deps), d)
134 def runstrip(file, d):
135 # Function to strip a single file, called from populate_packages below
136 # A working 'file' (one which works on the target architecture)
137 # is necessary for this stuff to work, hence the addition to do_package[depends]
139 import bb, os, commands, stat
141 pathprefix = "export PATH=%s; " % bb.data.getVar('PATH', d, 1)
143 ret, result = commands.getstatusoutput("%sfile '%s'" % (pathprefix, file))
146 bb.error("runstrip: 'file %s' failed (forced strip)" % file)
148 if "not stripped" not in result:
149 bb.debug(1, "runstrip: skip %s" % file)
152 # If the file is in a .debug directory it was already stripped,
153 # don't do it again...
154 if os.path.dirname(file).endswith(".debug"):
155 bb.note("Already ran strip")
158 strip = bb.data.getVar("STRIP", d, 1)
159 objcopy = bb.data.getVar("OBJCOPY", d, 1)
162 if not os.access(file, os.W_OK):
163 origmode = os.stat(file)[stat.ST_MODE]
164 newmode = origmode | stat.S_IWRITE
165 os.chmod(file, newmode)
168 if ".so" in file and "shared" in result:
169 extraflags = "--remove-section=.comment --remove-section=.note --strip-unneeded"
170 elif "shared" in result or "executable" in result:
171 extraflags = "--remove-section=.comment --remove-section=.note"
173 bb.mkdirhier(os.path.join(os.path.dirname(file), ".debug"))
174 debugfile=os.path.join(os.path.dirname(file), ".debug", os.path.basename(file))
176 stripcmd = "'%s' %s '%s'" % (strip, extraflags, file)
177 bb.debug(1, "runstrip: %s" % stripcmd)
179 os.system("%s'%s' --only-keep-debug '%s' '%s'" % (pathprefix, objcopy, file, debugfile))
180 ret = os.system("%s%s" % (pathprefix, stripcmd))
181 os.system("%s'%s' --add-gnu-debuglink='%s' '%s'" % (pathprefix, objcopy, debugfile, file))
184 os.chmod(file, origmode)
187 bb.error("runstrip: '%s' strip command failed" % stripcmd)
192 # Package data handling routines
195 def get_package_mapping (pkg, d):
198 data = read_subpkgdata(pkg, d)
206 def runtime_mapping_rename (varname, d):
209 #bb.note("%s before: %s" % (varname, bb.data.getVar(varname, d, 1)))
212 for depend in explode_deps(bb.data.getVar(varname, d, 1) or ""):
213 # Have to be careful with any version component of the depend
214 split_depend = depend.split(' (')
215 new_depend = get_package_mapping(split_depend[0].strip(), d)
216 if len(split_depend) > 1:
217 new_depends.append("%s (%s" % (new_depend, split_depend[1]))
219 new_depends.append(new_depend)
221 bb.data.setVar(varname, " ".join(new_depends) or None, d)
223 #bb.note("%s after: %s" % (varname, bb.data.getVar(varname, d, 1)))
226 # Package functions suitable for inclusion in PACKAGEFUNCS
229 python package_do_split_locales() {
232 if (bb.data.getVar('PACKAGE_NO_LOCALE', d, 1) == '1'):
233 bb.debug(1, "package requested not splitting locales")
236 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
238 datadir = bb.data.getVar('datadir', d, 1)
240 bb.note("datadir not defined")
243 dvar = bb.data.getVar('D', d, 1)
245 bb.error("D not defined")
248 pn = bb.data.getVar('PN', d, 1)
250 bb.error("PN not defined")
253 if pn + '-locale' in packages:
254 packages.remove(pn + '-locale')
256 localedir = os.path.join(dvar + datadir, 'locale')
258 if not os.path.isdir(localedir):
259 bb.debug(1, "No locale files in this package")
262 locales = os.listdir(localedir)
264 # This is *really* broken
265 mainpkg = packages[0]
266 # At least try and patch it up I guess...
267 if mainpkg.find('-dbg'):
268 mainpkg = mainpkg.replace('-dbg', '')
269 if mainpkg.find('-dev'):
270 mainpkg = mainpkg.replace('-dev', '')
273 ln = legitimize_package_name(l)
274 pkg = pn + '-locale-' + ln
276 bb.data.setVar('FILES_' + pkg, os.path.join(datadir, 'locale', l), d)
277 bb.data.setVar('RDEPENDS_' + pkg, '%s virtual-locale-%s' % (mainpkg, ln), d)
278 bb.data.setVar('RPROVIDES_' + pkg, '%s-locale %s-translation' % (pn, ln), d)
279 bb.data.setVar('DESCRIPTION_' + pkg, '%s translation for %s' % (l, pn), d)
281 bb.data.setVar('PACKAGES', ' '.join(packages), d)
283 # Disabled by RP 18/06/07
284 # Wildcards aren't supported in debian
285 # They break with ipkg since glibc-locale* will mean that
286 # glibc-localedata-translit* won't install as a dependency
287 # for some other package which breaks meta-toolchain
288 # Probably breaks since virtual-locale- isn't provided anywhere
289 #rdep = (bb.data.getVar('RDEPENDS_%s' % mainpkg, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or "").split()
290 #rdep.append('%s-locale*' % pn)
291 #bb.data.setVar('RDEPENDS_%s' % mainpkg, ' '.join(rdep), d)
294 python populate_packages () {
295 import glob, stat, errno, re
297 workdir = bb.data.getVar('WORKDIR', d, 1)
299 bb.error("WORKDIR not defined, unable to package")
302 import os # path manipulations
303 outdir = bb.data.getVar('DEPLOY_DIR', d, 1)
305 bb.error("DEPLOY_DIR not defined, unable to package")
309 dvar = bb.data.getVar('D', d, 1)
311 bb.error("D not defined, unable to package")
315 packages = bb.data.getVar('PACKAGES', d, 1)
317 pn = bb.data.getVar('PN', d, 1)
319 bb.error("PN not defined")
327 except (os.error, AttributeError):
329 return (s[stat.ST_MODE] & stat.S_IEXEC)
331 # Sanity check PACKAGES for duplicates - should be moved to
332 # sanity.bbclass once we have the infrastucture
334 for pkg in packages.split():
335 if pkg in package_list:
336 bb.error("-------------------")
337 bb.error("%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg)
338 bb.error("Please fix the metadata/report this as bug to OE bugtracker.")
339 bb.error("-------------------")
341 package_list.append(pkg)
343 if (bb.data.getVar('INHIBIT_PACKAGE_STRIP', d, 1) != '1'):
344 for root, dirs, files in os.walk(dvar):
346 file = os.path.join(root, f)
347 if not os.path.islink(file) and not os.path.isdir(file) and isexec(file):
350 pkgdest = bb.data.getVar('PKGDEST', d, 1)
351 os.system('rm -rf %s' % pkgdest)
355 for pkg in package_list:
356 localdata = bb.data.createCopy(d)
357 root = os.path.join(pkgdest, pkg)
360 bb.data.setVar('PKG', pkg, localdata)
361 overrides = bb.data.getVar('OVERRIDES', localdata, 1)
363 raise bb.build.FuncFailed('OVERRIDES not defined')
364 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
365 bb.data.update_data(localdata)
367 filesvar = bb.data.getVar('FILES', localdata, 1) or ""
368 files = filesvar.split()
370 if os.path.isabs(file):
372 if not os.path.islink(file):
373 if os.path.isdir(file):
374 newfiles = [ os.path.join(file,x) for x in os.listdir(file) ]
378 globbed = glob.glob(file)
380 if [ file ] != globbed:
383 if (not os.path.islink(file)) and (not os.path.exists(file)):
388 if os.path.isdir(file) and not os.path.islink(file):
389 bb.mkdirhier(os.path.join(root,file))
390 os.chmod(os.path.join(root,file), os.stat(file).st_mode)
392 fpath = os.path.join(root,file)
393 dpath = os.path.dirname(fpath)
395 ret = bb.copyfile(file, fpath)
396 if ret is False or ret == 0:
397 raise bb.build.FuncFailed("File population failed")
402 for root, dirs, files in os.walk(dvar):
404 path = os.path.join(root[len(dvar):], f)
405 if ('.' + path) not in seen:
406 unshipped.append(path)
409 bb.note("the following files were installed but not shipped in any package:")
413 bb.build.exec_func("package_name_hook", d)
415 for pkg in package_list:
416 pkgname = bb.data.getVar('PKG_%s' % pkg, d, 1)
418 bb.data.setVar('PKG_%s' % pkg, pkg, d)
422 for pkg in package_list:
423 dangling_links[pkg] = []
425 inst_root = os.path.join(pkgdest, pkg)
426 for root, dirs, files in os.walk(inst_root):
428 path = os.path.join(root, f)
429 rpath = path[len(inst_root):]
430 pkg_files[pkg].append(rpath)
433 except OSError, (err, strerror):
434 if err != errno.ENOENT:
436 target = os.readlink(path)
438 target = os.path.join(root[len(inst_root):], target)
439 dangling_links[pkg].append(os.path.normpath(target))
441 for pkg in package_list:
442 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or "")
443 for l in dangling_links[pkg]:
445 bb.debug(1, "%s contains dangling link %s" % (pkg, l))
446 for p in package_list:
447 for f in pkg_files[p]:
450 bb.debug(1, "target found in %s" % p)
453 if not p in rdepends:
457 bb.note("%s contains dangling symlink to %s" % (pkg, l))
458 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
460 populate_packages[dirs] = "${D}"
462 python emit_pkgdata() {
463 from glob import glob
465 def write_if_exists(f, pkg, var):
468 c = codecs.getencoder("string_escape")
471 val = bb.data.getVar('%s_%s' % (var, pkg), d, 1)
473 f.write('%s_%s: %s\n' % (var, pkg, encode(val)))
475 packages = bb.data.getVar('PACKAGES', d, True)
476 pkgdatadir = bb.data.getVar('PKGDATA_DIR', d, True)
478 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
479 if pstageactive == "1":
480 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
482 data_file = pkgdatadir + bb.data.expand("/${PN}" , d)
483 f = open(data_file, 'w')
484 f.write("PACKAGES: %s\n" % packages)
486 package_stagefile(data_file, d)
488 workdir = bb.data.getVar('WORKDIR', d, 1)
490 for pkg in packages.split():
491 subdata_file = pkgdatadir + "/runtime/%s" % pkg
492 sf = open(subdata_file, 'w')
493 write_if_exists(sf, pkg, 'PN')
494 write_if_exists(sf, pkg, 'PR')
495 write_if_exists(sf, pkg, 'DESCRIPTION')
496 write_if_exists(sf, pkg, 'RDEPENDS')
497 write_if_exists(sf, pkg, 'RPROVIDES')
498 write_if_exists(sf, pkg, 'RRECOMMENDS')
499 write_if_exists(sf, pkg, 'RSUGGESTS')
500 write_if_exists(sf, pkg, 'RREPLACES')
501 write_if_exists(sf, pkg, 'RCONFLICTS')
502 write_if_exists(sf, pkg, 'PKG')
503 write_if_exists(sf, pkg, 'ALLOW_EMPTY')
504 write_if_exists(sf, pkg, 'FILES')
505 write_if_exists(sf, pkg, 'pkg_postinst')
506 write_if_exists(sf, pkg, 'pkg_postrm')
507 write_if_exists(sf, pkg, 'pkg_preinst')
508 write_if_exists(sf, pkg, 'pkg_prerm')
511 package_stagefile(subdata_file, d)
513 # bb.copyfile(subdata_file, pkgdatadir2 + "/runtime/%s" % pkg)
515 allow_empty = bb.data.getVar('ALLOW_EMPTY_%s' % pkg, d, 1)
517 allow_empty = bb.data.getVar('ALLOW_EMPTY', d, 1)
518 root = "%s/install/%s" % (workdir, pkg)
521 if g or allow_empty == "1":
522 packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg
523 file(packagedfile, 'w').close()
524 package_stagefile(packagedfile, d)
525 if pstageactive == "1":
526 bb.utils.unlockfile(lf)
528 emit_pkgdata[dirs] = "${PKGDATA_DIR}/runtime"
530 ldconfig_postinst_fragment() {
531 if [ x"$D" = "x" ]; then
532 [ -x /sbin/ldconfig ] && /sbin/ldconfig
536 SHLIBSDIR = "${STAGING_DIR_HOST}/shlibs"
538 python package_do_shlibs() {
539 import os, re, os.path
541 exclude_shlibs = bb.data.getVar('EXCLUDE_FROM_SHLIBS', d, 0)
543 bb.note("not generating shlibs")
546 lib_re = re.compile("^lib.*\.so")
547 libdir_re = re.compile(".*/lib$")
549 packages = bb.data.getVar('PACKAGES', d, 1)
551 workdir = bb.data.getVar('WORKDIR', d, 1)
553 bb.error("WORKDIR not defined")
556 ver = bb.data.getVar('PV', d, 1)
558 bb.error("PV not defined")
561 pkgdest = bb.data.getVar('PKGDEST', d, 1)
563 shlibs_dir = bb.data.getVar('SHLIBSDIR', d, 1)
564 bb.mkdirhier(shlibs_dir)
566 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
567 if pstageactive == "1":
568 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
571 private_libs = bb.data.getVar('PRIVATE_LIBS', d, 1)
572 for pkg in packages.split():
573 needs_ldconfig = False
574 bb.debug(2, "calculating shlib provides for %s" % pkg)
578 top = os.path.join(pkgdest, pkg)
579 for root, dirs, files in os.walk(top):
582 path = os.path.join(root, file)
583 if os.access(path, os.X_OK) or lib_re.match(file):
584 cmd = bb.data.getVar('OBJDUMP', d, 1) + " -p " + path + " 2>/dev/null"
585 cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', d, 1), cmd)
587 lines = fd.readlines()
590 m = re.match("\s+NEEDED\s+([^\s]*)", l)
592 needed[pkg].append(m.group(1))
593 m = re.match("\s+SONAME\s+([^\s]*)", l)
594 if m and not m.group(1) in sonames:
595 # if library is private (only used by package) then do not build shlib for it
596 if not private_libs or -1 == private_libs.find(m.group(1)):
597 sonames.append(m.group(1))
598 if m and libdir_re.match(root):
599 needs_ldconfig = True
600 shlibs_file = os.path.join(shlibs_dir, pkg + ".list")
601 if os.path.exists(shlibs_file):
602 os.remove(shlibs_file)
603 shver_file = os.path.join(shlibs_dir, pkg + ".ver")
604 if os.path.exists(shver_file):
605 os.remove(shver_file)
607 fd = open(shlibs_file, 'w')
611 package_stagefile(shlibs_file, d)
612 fd = open(shver_file, 'w')
615 package_stagefile(shver_file, d)
617 bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg)
618 postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1)
620 postinst = '#!/bin/sh\n'
621 postinst += bb.data.getVar('ldconfig_postinst_fragment', d, 1)
622 bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
624 if pstageactive == "1":
625 bb.utils.unlockfile(lf)
628 list_re = re.compile('^(.*)\.list$')
629 for dir in [shlibs_dir]:
630 if not os.path.exists(dir):
632 for file in os.listdir(dir):
633 m = list_re.match(file)
636 fd = open(os.path.join(dir, file))
637 lines = fd.readlines()
639 ver_file = os.path.join(dir, dep_pkg + '.ver')
641 if os.path.exists(ver_file):
643 lib_ver = fd.readline().rstrip()
646 shlib_provider[l.rstrip()] = (dep_pkg, lib_ver)
648 assumed_libs = bb.data.getVar('ASSUME_SHLIBS', d, 1)
650 for e in assumed_libs.split():
651 l, dep_pkg = e.split(":")
653 dep_pkg = dep_pkg.rsplit("_", 1)
654 if len(dep_pkg) == 2:
657 shlib_provider[l] = (dep_pkg, lib_ver)
659 for pkg in packages.split():
660 bb.debug(2, "calculating shlib requirements for %s" % pkg)
663 for n in needed[pkg]:
664 if n in shlib_provider.keys():
665 (dep_pkg, ver_needed) = shlib_provider[n]
671 dep = "%s (>= %s)" % (dep_pkg, ver_needed)
677 bb.note("Couldn't find shared library provider for %s" % n)
679 deps_file = os.path.join(pkgdest, pkg + ".shlibdeps")
680 if os.path.exists(deps_file):
683 fd = open(deps_file, 'w')
689 python package_do_pkgconfig () {
692 packages = bb.data.getVar('PACKAGES', d, 1)
694 workdir = bb.data.getVar('WORKDIR', d, 1)
696 bb.error("WORKDIR not defined")
699 pkgdest = bb.data.getVar('PKGDEST', d, 1)
701 shlibs_dir = bb.data.getVar('SHLIBSDIR', d, 1)
702 bb.mkdirhier(shlibs_dir)
704 pc_re = re.compile('(.*)\.pc$')
705 var_re = re.compile('(.*)=(.*)')
706 field_re = re.compile('(.*): (.*)')
708 pkgconfig_provided = {}
709 pkgconfig_needed = {}
710 for pkg in packages.split():
711 pkgconfig_provided[pkg] = []
712 pkgconfig_needed[pkg] = []
713 top = os.path.join(pkgdest, pkg)
714 for root, dirs, files in os.walk(top):
716 m = pc_re.match(file)
720 pkgconfig_provided[pkg].append(name)
721 path = os.path.join(root, file)
722 if not os.access(path, os.R_OK):
725 lines = f.readlines()
732 bb.data.setVar(name, bb.data.expand(val, pd), pd)
734 m = field_re.match(l)
737 exp = bb.data.expand(m.group(2), pd)
738 if hdr == 'Requires':
739 pkgconfig_needed[pkg] += exp.replace(',', ' ').split()
741 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
742 if pstageactive == "1":
743 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
745 for pkg in packages.split():
746 pkgs_file = os.path.join(shlibs_dir, pkg + ".pclist")
747 if os.path.exists(pkgs_file):
749 if pkgconfig_provided[pkg] != []:
750 f = open(pkgs_file, 'w')
751 for p in pkgconfig_provided[pkg]:
754 package_stagefile(pkgs_file, d)
756 for dir in [shlibs_dir]:
757 if not os.path.exists(dir):
759 for file in os.listdir(dir):
760 m = re.match('^(.*)\.pclist$', file)
763 fd = open(os.path.join(dir, file))
764 lines = fd.readlines()
766 pkgconfig_provided[pkg] = []
768 pkgconfig_provided[pkg].append(l.rstrip())
770 for pkg in packages.split():
772 for n in pkgconfig_needed[pkg]:
774 for k in pkgconfig_provided.keys():
775 if n in pkgconfig_provided[k]:
776 if k != pkg and not (k in deps):
780 bb.note("couldn't find pkgconfig module '%s' in any package" % n)
781 deps_file = os.path.join(pkgdest, pkg + ".pcdeps")
782 if os.path.exists(deps_file):
785 fd = open(deps_file, 'w')
789 package_stagefile(deps_file, d)
791 if pstageactive == "1":
792 bb.utils.unlockfile(lf)
795 python read_shlibdeps () {
796 packages = bb.data.getVar('PACKAGES', d, 1).split()
798 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
799 for extension in ".shlibdeps", ".pcdeps", ".clilibdeps":
800 depsfile = bb.data.expand("${PKGDEST}/" + pkg + extension, d)
801 if os.access(depsfile, os.R_OK):
803 lines = fd.readlines()
806 rdepends.append(l.rstrip())
807 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
810 python package_depchains() {
812 For a given set of prefix and postfix modifiers, make those packages
813 RRECOMMENDS on the corresponding packages for its RDEPENDS.
815 Example: If package A depends upon package B, and A's .bb emits an
816 A-dev package, this would make A-dev Recommends: B-dev.
818 If only one of a given suffix is specified, it will take the RRECOMMENDS
819 based on the RDEPENDS of *all* other packages. If more than one of a given
820 suffix is specified, its will only use the RDEPENDS of the single parent
824 packages = bb.data.getVar('PACKAGES', d, 1)
825 postfixes = (bb.data.getVar('DEPCHAIN_POST', d, 1) or '').split()
826 prefixes = (bb.data.getVar('DEPCHAIN_PRE', d, 1) or '').split()
828 def pkg_adddeprrecs(pkg, base, suffix, getname, depends, d):
830 #bb.note('depends for %s is %s' % (base, depends))
831 rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, 1) or bb.data.getVar('RRECOMMENDS', d, 1) or "")
833 for depend in depends:
834 if depend.find('-native') != -1 or depend.find('-cross') != -1 or depend.startswith('virtual/'):
835 #bb.note("Skipping %s" % depend)
837 if depend.endswith('-dev'):
838 depend = depend.replace('-dev', '')
839 if depend.endswith('-dbg'):
840 depend = depend.replace('-dbg', '')
841 pkgname = getname(depend, suffix)
842 #bb.note("Adding %s for %s" % (pkgname, depend))
843 if not pkgname in rreclist:
844 rreclist.append(pkgname)
846 #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
847 bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
849 def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d):
851 #bb.note('rdepends for %s is %s' % (base, rdepends))
852 rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, 1) or bb.data.getVar('RRECOMMENDS', d, 1) or "")
854 for depend in rdepends:
855 if depend.endswith('-dev'):
856 depend = depend.replace('-dev', '')
857 if depend.endswith('-dbg'):
858 depend = depend.replace('-dbg', '')
859 pkgname = getname(depend, suffix)
860 if not pkgname in rreclist:
861 rreclist.append(pkgname)
863 #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
864 bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
866 def add_dep(list, dep):
867 dep = dep.split(' (')[0].strip()
872 for dep in explode_deps(bb.data.getVar('DEPENDS', d, 1) or ""):
873 add_dep(depends, dep)
876 for dep in explode_deps(bb.data.getVar('RDEPENDS', d, 1) or ""):
877 add_dep(rdepends, dep)
879 for pkg in packages.split():
880 for dep in explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 1) or ""):
881 add_dep(rdepends, dep)
883 #bb.note('rdepends is %s' % rdepends)
885 def post_getname(name, suffix):
886 return '%s%s' % (name, suffix)
887 def pre_getname(name, suffix):
888 return '%s%s' % (suffix, name)
891 for pkg in packages.split():
892 for postfix in postfixes:
893 if pkg.endswith(postfix):
894 if not postfix in pkgs:
896 pkgs[postfix][pkg] = (pkg[:-len(postfix)], post_getname)
898 for prefix in prefixes:
899 if pkg.startswith(prefix):
900 if not prefix in pkgs:
902 pkgs[prefix][pkg] = (pkg[:-len(prefix)], pre_getname)
905 for pkg in pkgs[suffix]:
906 (base, func) = pkgs[suffix][pkg]
907 if suffix == "-dev" and not pkg.startswith("kernel-module-"):
908 pkg_adddeprrecs(pkg, base, suffix, func, depends, d)
909 if len(pkgs[suffix]) == 1:
910 pkg_addrrecs(pkg, base, suffix, func, rdepends, d)
913 for dep in explode_deps(bb.data.getVar('RDEPENDS_' + base, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or ""):
915 pkg_addrrecs(pkg, base, suffix, func, rdeps, d)
919 PACKAGEFUNCS ?= "package_do_split_locales \
922 package_do_pkgconfig \
927 python package_do_package () {
928 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
929 if len(packages) < 1:
930 bb.debug(1, "No packages to build, skipping do_package")
933 for f in (bb.data.getVar('PACKAGEFUNCS', d, 1) or '').split():
934 bb.build.exec_func(f, d)
936 do_package[dirs] = "${D}"
937 addtask package before do_build after do_install
939 # Dummy task to mark when all packaging is complete
940 do_package_write () {
943 addtask package_write before do_build after do_package
945 EXPORT_FUNCTIONS do_package do_package_write
948 # Helper functions for the package writing classes
951 python package_mapping_rename_hook () {
953 Rewrite variables to account for package renaming in things
954 like debian.bbclass or manual PKG variable name changes
956 runtime_mapping_rename("RDEPENDS", d)
957 runtime_mapping_rename("RRECOMMENDS", d)
958 runtime_mapping_rename("RSUGGESTS", d)
959 runtime_mapping_rename("RPROVIDES", d)
960 runtime_mapping_rename("RREPLACES", d)
961 runtime_mapping_rename("RCONFLICTS", d)
964 EXPORT_FUNCTIONS mapping_rename_hook