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"
120 def package_stash_hook(func, name, d):
122 body = bb.data.getVar(func, d, True)
123 pn = bb.data.getVar('PN', d, True)
124 staging = bb.data.getVar('PKGDATA_DIR', d, True)
125 dirname = os.path.join(staging, 'hooks', name)
126 bb.mkdirhier(dirname)
127 fn = os.path.join(dirname, pn)
129 f.write("python () {\n");
136 if bb.data.getVar('PACKAGES', d, True) != '':
137 deps = bb.data.getVarFlag('do_package', 'depends', d) or ""
138 for dep in (bb.data.getVar('PACKAGE_DEPENDS', d, True) or "").split():
139 deps += " %s:do_populate_staging" % dep
140 bb.data.setVarFlag('do_package', 'depends', deps, d)
142 deps = (bb.data.getVarFlag('do_package', 'deptask', d) or "").split()
143 # shlibs requires any DEPENDS to have already packaged for the *.list files
144 deps.append("do_package")
145 bb.data.setVarFlag('do_package', 'deptask', " ".join(deps), d)
148 def runstrip(file, d):
149 # Function to strip a single file, called from populate_packages below
150 # A working 'file' (one which works on the target architecture)
151 # is necessary for this stuff to work, hence the addition to do_package[depends]
153 import bb, os, commands, stat
155 pathprefix = "export PATH=%s; " % bb.data.getVar('PATH', d, 1)
157 ret, result = commands.getstatusoutput("%sfile '%s'" % (pathprefix, file))
160 bb.error("runstrip: 'file %s' failed (forced strip)" % file)
162 if "not stripped" not in result:
163 bb.debug(1, "runstrip: skip %s" % file)
166 # If the file is in a .debug directory it was already stripped,
167 # don't do it again...
168 if os.path.dirname(file).endswith(".debug"):
169 bb.note("Already ran strip")
172 strip = bb.data.getVar("STRIP", d, 1)
173 objcopy = bb.data.getVar("OBJCOPY", d, 1)
176 if not os.access(file, os.W_OK):
177 origmode = os.stat(file)[stat.ST_MODE]
178 newmode = origmode | stat.S_IWRITE
179 os.chmod(file, newmode)
182 if ".so" in file and "shared" in result:
183 extraflags = "--remove-section=.comment --remove-section=.note --strip-unneeded"
184 elif "shared" in result or "executable" in result:
185 extraflags = "--remove-section=.comment --remove-section=.note"
187 bb.mkdirhier(os.path.join(os.path.dirname(file), ".debug"))
188 debugfile=os.path.join(os.path.dirname(file), ".debug", os.path.basename(file))
190 stripcmd = "'%s' %s '%s'" % (strip, extraflags, file)
191 bb.debug(1, "runstrip: %s" % stripcmd)
193 os.system("%s'%s' --only-keep-debug '%s' '%s'" % (pathprefix, objcopy, file, debugfile))
194 ret = os.system("%s%s" % (pathprefix, stripcmd))
195 os.system("%s'%s' --add-gnu-debuglink='%s' '%s'" % (pathprefix, objcopy, debugfile, file))
198 os.chmod(file, origmode)
201 bb.error("runstrip: '%s' strip command failed" % stripcmd)
206 # Package data handling routines
209 def get_package_mapping (pkg, d):
212 data = read_subpkgdata(pkg, d)
220 def runtime_mapping_rename (varname, d):
223 #bb.note("%s before: %s" % (varname, bb.data.getVar(varname, d, 1)))
226 for depend in explode_deps(bb.data.getVar(varname, d, 1) or ""):
227 # Have to be careful with any version component of the depend
228 split_depend = depend.split(' (')
229 new_depend = get_package_mapping(split_depend[0].strip(), d)
230 if len(split_depend) > 1:
231 new_depends.append("%s (%s" % (new_depend, split_depend[1]))
233 new_depends.append(new_depend)
235 bb.data.setVar(varname, " ".join(new_depends) or None, d)
237 #bb.note("%s after: %s" % (varname, bb.data.getVar(varname, d, 1)))
240 # Package functions suitable for inclusion in PACKAGEFUNCS
243 python package_do_split_locales() {
246 if (bb.data.getVar('PACKAGE_NO_LOCALE', d, 1) == '1'):
247 bb.debug(1, "package requested not splitting locales")
250 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
252 datadir = bb.data.getVar('datadir', d, 1)
254 bb.note("datadir not defined")
257 dvar = bb.data.getVar('D', d, 1)
259 bb.error("D not defined")
262 pn = bb.data.getVar('PN', d, 1)
264 bb.error("PN not defined")
267 if pn + '-locale' in packages:
268 packages.remove(pn + '-locale')
270 localedir = os.path.join(dvar + datadir, 'locale')
272 if not os.path.isdir(localedir):
273 bb.debug(1, "No locale files in this package")
276 locales = os.listdir(localedir)
278 # This is *really* broken
279 mainpkg = packages[0]
280 # At least try and patch it up I guess...
281 if mainpkg.find('-dbg'):
282 mainpkg = mainpkg.replace('-dbg', '')
283 if mainpkg.find('-dev'):
284 mainpkg = mainpkg.replace('-dev', '')
287 ln = legitimize_package_name(l)
288 pkg = pn + '-locale-' + ln
290 bb.data.setVar('FILES_' + pkg, os.path.join(datadir, 'locale', l), d)
291 bb.data.setVar('RDEPENDS_' + pkg, '%s virtual-locale-%s' % (mainpkg, ln), d)
292 bb.data.setVar('RPROVIDES_' + pkg, '%s-locale %s-translation' % (pn, ln), d)
293 bb.data.setVar('DESCRIPTION_' + pkg, '%s translation for %s' % (l, pn), d)
295 bb.data.setVar('PACKAGES', ' '.join(packages), d)
297 # Disabled by RP 18/06/07
298 # Wildcards aren't supported in debian
299 # They break with ipkg since glibc-locale* will mean that
300 # glibc-localedata-translit* won't install as a dependency
301 # for some other package which breaks meta-toolchain
302 # Probably breaks since virtual-locale- isn't provided anywhere
303 #rdep = (bb.data.getVar('RDEPENDS_%s' % mainpkg, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or "").split()
304 #rdep.append('%s-locale*' % pn)
305 #bb.data.setVar('RDEPENDS_%s' % mainpkg, ' '.join(rdep), d)
308 python populate_packages () {
309 import glob, stat, errno, re
311 workdir = bb.data.getVar('WORKDIR', d, 1)
313 bb.error("WORKDIR not defined, unable to package")
316 import os # path manipulations
317 outdir = bb.data.getVar('DEPLOY_DIR', d, 1)
319 bb.error("DEPLOY_DIR not defined, unable to package")
323 dvar = bb.data.getVar('D', d, 1)
325 bb.error("D not defined, unable to package")
329 packages = bb.data.getVar('PACKAGES', d, 1)
331 pn = bb.data.getVar('PN', d, 1)
333 bb.error("PN not defined")
341 except (os.error, AttributeError):
343 return (s[stat.ST_MODE] & stat.S_IEXEC)
345 # Sanity check PACKAGES for duplicates - should be moved to
346 # sanity.bbclass once we have the infrastucture
348 for pkg in packages.split():
349 if pkg in package_list:
350 bb.error("-------------------")
351 bb.error("%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg)
352 bb.error("Please fix the metadata/report this as bug to OE bugtracker.")
353 bb.error("-------------------")
355 package_list.append(pkg)
357 if (bb.data.getVar('INHIBIT_PACKAGE_STRIP', d, 1) != '1'):
358 for root, dirs, files in os.walk(dvar):
360 file = os.path.join(root, f)
361 if not os.path.islink(file) and not os.path.isdir(file) and isexec(file):
364 pkgdest = bb.data.getVar('PKGDEST', d, 1)
365 os.system('rm -rf %s' % pkgdest)
369 for pkg in package_list:
370 localdata = bb.data.createCopy(d)
371 root = os.path.join(pkgdest, pkg)
374 bb.data.setVar('PKG', pkg, localdata)
375 overrides = bb.data.getVar('OVERRIDES', localdata, 1)
377 raise bb.build.FuncFailed('OVERRIDES not defined')
378 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
379 bb.data.update_data(localdata)
381 filesvar = bb.data.getVar('FILES', localdata, 1) or ""
382 files = filesvar.split()
384 if os.path.isabs(file):
386 if not os.path.islink(file):
387 if os.path.isdir(file):
388 newfiles = [ os.path.join(file,x) for x in os.listdir(file) ]
392 globbed = glob.glob(file)
394 if [ file ] != globbed:
397 if (not os.path.islink(file)) and (not os.path.exists(file)):
402 if os.path.isdir(file) and not os.path.islink(file):
403 bb.mkdirhier(os.path.join(root,file))
404 os.chmod(os.path.join(root,file), os.stat(file).st_mode)
406 fpath = os.path.join(root,file)
407 dpath = os.path.dirname(fpath)
409 ret = bb.copyfile(file, fpath)
410 if ret is False or ret == 0:
411 raise bb.build.FuncFailed("File population failed")
416 for root, dirs, files in os.walk(dvar):
418 path = os.path.join(root[len(dvar):], f)
419 if ('.' + path) not in seen:
420 unshipped.append(path)
423 bb.note("the following files were installed but not shipped in any package:")
427 bb.build.exec_func("package_name_hook", d)
429 for pkg in package_list:
430 pkgname = bb.data.getVar('PKG_%s' % pkg, d, 1)
432 bb.data.setVar('PKG_%s' % pkg, pkg, d)
436 for pkg in package_list:
437 dangling_links[pkg] = []
439 inst_root = os.path.join(pkgdest, pkg)
440 for root, dirs, files in os.walk(inst_root):
442 path = os.path.join(root, f)
443 rpath = path[len(inst_root):]
444 pkg_files[pkg].append(rpath)
447 except OSError, (err, strerror):
448 if err != errno.ENOENT:
450 target = os.readlink(path)
452 target = os.path.join(root[len(inst_root):], target)
453 dangling_links[pkg].append(os.path.normpath(target))
455 for pkg in package_list:
456 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or "")
457 for l in dangling_links[pkg]:
459 bb.debug(1, "%s contains dangling link %s" % (pkg, l))
460 for p in package_list:
461 for f in pkg_files[p]:
464 bb.debug(1, "target found in %s" % p)
467 if not p in rdepends:
471 bb.note("%s contains dangling symlink to %s" % (pkg, l))
472 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
474 populate_packages[dirs] = "${D}"
476 python emit_pkgdata() {
477 from glob import glob
479 def write_if_exists(f, pkg, var):
482 c = codecs.getencoder("string_escape")
485 val = bb.data.getVar('%s_%s' % (var, pkg), d, 1)
487 f.write('%s_%s: %s\n' % (var, pkg, encode(val)))
489 packages = bb.data.getVar('PACKAGES', d, True)
490 pkgdatadir = bb.data.getVar('PKGDATA_DIR', d, True)
492 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
493 if pstageactive == "1":
494 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
496 data_file = pkgdatadir + bb.data.expand("/${PN}" , d)
497 f = open(data_file, 'w')
498 f.write("PACKAGES: %s\n" % packages)
500 package_stagefile(data_file, d)
502 workdir = bb.data.getVar('WORKDIR', d, 1)
504 for pkg in packages.split():
505 subdata_file = pkgdatadir + "/runtime/%s" % pkg
506 sf = open(subdata_file, 'w')
507 write_if_exists(sf, pkg, 'PN')
508 write_if_exists(sf, pkg, 'PR')
509 write_if_exists(sf, pkg, 'DESCRIPTION')
510 write_if_exists(sf, pkg, 'RDEPENDS')
511 write_if_exists(sf, pkg, 'RPROVIDES')
512 write_if_exists(sf, pkg, 'RRECOMMENDS')
513 write_if_exists(sf, pkg, 'RSUGGESTS')
514 write_if_exists(sf, pkg, 'RREPLACES')
515 write_if_exists(sf, pkg, 'RCONFLICTS')
516 write_if_exists(sf, pkg, 'PKG')
517 write_if_exists(sf, pkg, 'ALLOW_EMPTY')
518 write_if_exists(sf, pkg, 'FILES')
519 write_if_exists(sf, pkg, 'pkg_postinst')
520 write_if_exists(sf, pkg, 'pkg_postrm')
521 write_if_exists(sf, pkg, 'pkg_preinst')
522 write_if_exists(sf, pkg, 'pkg_prerm')
525 package_stagefile(subdata_file, d)
527 # bb.copyfile(subdata_file, pkgdatadir2 + "/runtime/%s" % pkg)
529 allow_empty = bb.data.getVar('ALLOW_EMPTY_%s' % pkg, d, 1)
531 allow_empty = bb.data.getVar('ALLOW_EMPTY', d, 1)
532 root = "%s/install/%s" % (workdir, pkg)
535 if g or allow_empty == "1":
536 packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg
537 file(packagedfile, 'w').close()
538 package_stagefile(packagedfile, d)
539 if pstageactive == "1":
540 bb.utils.unlockfile(lf)
542 emit_pkgdata[dirs] = "${PKGDATA_DIR}/runtime"
544 ldconfig_postinst_fragment() {
545 if [ x"$D" = "x" ]; then
546 [ -x /sbin/ldconfig ] && /sbin/ldconfig
550 SHLIBSDIR = "${STAGING_DIR_HOST}/shlibs"
552 python package_do_shlibs() {
553 import os, re, os.path
555 exclude_shlibs = bb.data.getVar('EXCLUDE_FROM_SHLIBS', d, 0)
557 bb.note("not generating shlibs")
560 lib_re = re.compile("^lib.*\.so")
561 libdir_re = re.compile(".*/lib$")
563 packages = bb.data.getVar('PACKAGES', d, 1)
565 workdir = bb.data.getVar('WORKDIR', d, 1)
567 bb.error("WORKDIR not defined")
570 ver = bb.data.getVar('PV', d, 1)
572 bb.error("PV not defined")
575 pkgdest = bb.data.getVar('PKGDEST', d, 1)
577 shlibs_dir = bb.data.getVar('SHLIBSDIR', d, 1)
578 bb.mkdirhier(shlibs_dir)
580 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
581 if pstageactive == "1":
582 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
584 if bb.data.getVar('PACKAGE_SNAP_LIB_SYMLINKS', d, True) == "1":
587 snap_symlinks = False
590 private_libs = bb.data.getVar('PRIVATE_LIBS', d, 1)
591 for pkg in packages.split():
592 needs_ldconfig = False
593 bb.debug(2, "calculating shlib provides for %s" % pkg)
597 top = os.path.join(pkgdest, pkg)
599 for root, dirs, files in os.walk(top):
602 path = os.path.join(root, file)
603 if os.access(path, os.X_OK) or lib_re.match(file):
604 cmd = bb.data.getVar('OBJDUMP', d, 1) + " -p " + path + " 2>/dev/null"
605 cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', d, 1), cmd)
607 lines = fd.readlines()
610 m = re.match("\s+NEEDED\s+([^\s]*)", l)
612 needed[pkg].append(m.group(1))
613 m = re.match("\s+SONAME\s+([^\s]*)", l)
615 this_soname = m.group(1)
616 if not this_soname in sonames:
617 # if library is private (only used by package) then do not build shlib for it
618 if not private_libs or -1 == private_libs.find(this_soname):
619 sonames.append(this_soname)
620 if libdir_re.match(root):
621 needs_ldconfig = True
622 if snap_symlinks and (file != soname):
623 renames.append((path, os.path.join(root, this_soname)))
624 for (old, new) in renames:
626 shlibs_file = os.path.join(shlibs_dir, pkg + ".list")
627 if os.path.exists(shlibs_file):
628 os.remove(shlibs_file)
629 shver_file = os.path.join(shlibs_dir, pkg + ".ver")
630 if os.path.exists(shver_file):
631 os.remove(shver_file)
633 fd = open(shlibs_file, 'w')
637 package_stagefile(shlibs_file, d)
638 fd = open(shver_file, 'w')
641 package_stagefile(shver_file, d)
643 bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg)
644 postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1)
646 postinst = '#!/bin/sh\n'
647 postinst += bb.data.getVar('ldconfig_postinst_fragment', d, 1)
648 bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
650 if pstageactive == "1":
651 bb.utils.unlockfile(lf)
654 list_re = re.compile('^(.*)\.list$')
655 for dir in [shlibs_dir]:
656 if not os.path.exists(dir):
658 for file in os.listdir(dir):
659 m = list_re.match(file)
662 fd = open(os.path.join(dir, file))
663 lines = fd.readlines()
665 ver_file = os.path.join(dir, dep_pkg + '.ver')
667 if os.path.exists(ver_file):
669 lib_ver = fd.readline().rstrip()
672 shlib_provider[l.rstrip()] = (dep_pkg, lib_ver)
674 assumed_libs = bb.data.getVar('ASSUME_SHLIBS', d, 1)
676 for e in assumed_libs.split():
677 l, dep_pkg = e.split(":")
679 dep_pkg = dep_pkg.rsplit("_", 1)
680 if len(dep_pkg) == 2:
683 shlib_provider[l] = (dep_pkg, lib_ver)
686 for pkg in packages.split():
687 bb.debug(2, "calculating shlib requirements for %s" % pkg)
690 for n in needed[pkg]:
691 if n in shlib_provider.keys():
692 (dep_pkg, ver_needed) = shlib_provider[n]
698 dep = "%s (>= %s)" % (dep_pkg, ver_needed)
703 if not dep_pkg in dep_packages:
704 dep_packages.append(dep_pkg)
707 bb.note("Couldn't find shared library provider for %s" % n)
709 deps_file = os.path.join(pkgdest, pkg + ".shlibdeps")
710 if os.path.exists(deps_file):
713 fd = open(deps_file, 'w')
719 python package_do_pkgconfig () {
722 packages = bb.data.getVar('PACKAGES', d, 1)
724 workdir = bb.data.getVar('WORKDIR', d, 1)
726 bb.error("WORKDIR not defined")
729 pkgdest = bb.data.getVar('PKGDEST', d, 1)
731 shlibs_dir = bb.data.getVar('SHLIBSDIR', d, 1)
732 bb.mkdirhier(shlibs_dir)
734 pc_re = re.compile('(.*)\.pc$')
735 var_re = re.compile('(.*)=(.*)')
736 field_re = re.compile('(.*): (.*)')
738 pkgconfig_provided = {}
739 pkgconfig_needed = {}
740 for pkg in packages.split():
741 pkgconfig_provided[pkg] = []
742 pkgconfig_needed[pkg] = []
743 top = os.path.join(pkgdest, pkg)
744 for root, dirs, files in os.walk(top):
746 m = pc_re.match(file)
750 pkgconfig_provided[pkg].append(name)
751 path = os.path.join(root, file)
752 if not os.access(path, os.R_OK):
755 lines = f.readlines()
762 bb.data.setVar(name, bb.data.expand(val, pd), pd)
764 m = field_re.match(l)
767 exp = bb.data.expand(m.group(2), pd)
768 if hdr == 'Requires':
769 pkgconfig_needed[pkg] += exp.replace(',', ' ').split()
771 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
772 if pstageactive == "1":
773 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
775 for pkg in packages.split():
776 pkgs_file = os.path.join(shlibs_dir, pkg + ".pclist")
777 if os.path.exists(pkgs_file):
779 if pkgconfig_provided[pkg] != []:
780 f = open(pkgs_file, 'w')
781 for p in pkgconfig_provided[pkg]:
784 package_stagefile(pkgs_file, d)
786 for dir in [shlibs_dir]:
787 if not os.path.exists(dir):
789 for file in os.listdir(dir):
790 m = re.match('^(.*)\.pclist$', file)
793 fd = open(os.path.join(dir, file))
794 lines = fd.readlines()
796 pkgconfig_provided[pkg] = []
798 pkgconfig_provided[pkg].append(l.rstrip())
800 for pkg in packages.split():
802 for n in pkgconfig_needed[pkg]:
804 for k in pkgconfig_provided.keys():
805 if n in pkgconfig_provided[k]:
806 if k != pkg and not (k in deps):
810 bb.note("couldn't find pkgconfig module '%s' in any package" % n)
811 deps_file = os.path.join(pkgdest, pkg + ".pcdeps")
812 if os.path.exists(deps_file):
815 fd = open(deps_file, 'w')
819 package_stagefile(deps_file, d)
821 if pstageactive == "1":
822 bb.utils.unlockfile(lf)
825 python read_shlibdeps () {
826 packages = bb.data.getVar('PACKAGES', d, 1).split()
828 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
829 for extension in ".shlibdeps", ".pcdeps", ".clilibdeps":
830 depsfile = bb.data.expand("${PKGDEST}/" + pkg + extension, d)
831 if os.access(depsfile, os.R_OK):
833 lines = fd.readlines()
836 rdepends.append(l.rstrip())
837 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
840 python package_depchains() {
842 For a given set of prefix and postfix modifiers, make those packages
843 RRECOMMENDS on the corresponding packages for its RDEPENDS.
845 Example: If package A depends upon package B, and A's .bb emits an
846 A-dev package, this would make A-dev Recommends: B-dev.
848 If only one of a given suffix is specified, it will take the RRECOMMENDS
849 based on the RDEPENDS of *all* other packages. If more than one of a given
850 suffix is specified, its will only use the RDEPENDS of the single parent
854 packages = bb.data.getVar('PACKAGES', d, 1)
855 postfixes = (bb.data.getVar('DEPCHAIN_POST', d, 1) or '').split()
856 prefixes = (bb.data.getVar('DEPCHAIN_PRE', d, 1) or '').split()
858 def pkg_adddeprrecs(pkg, base, suffix, getname, depends, d):
860 #bb.note('depends for %s is %s' % (base, depends))
861 rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, 1) or bb.data.getVar('RRECOMMENDS', d, 1) or "")
863 for depend in depends:
864 if depend.find('-native') != -1 or depend.find('-cross') != -1 or depend.startswith('virtual/'):
865 #bb.note("Skipping %s" % depend)
867 if depend.endswith('-dev'):
868 depend = depend.replace('-dev', '')
869 if depend.endswith('-dbg'):
870 depend = depend.replace('-dbg', '')
871 pkgname = getname(depend, suffix)
872 #bb.note("Adding %s for %s" % (pkgname, depend))
873 if not pkgname in rreclist:
874 rreclist.append(pkgname)
876 #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
877 bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
879 def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d):
881 #bb.note('rdepends for %s is %s' % (base, rdepends))
882 rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, 1) or bb.data.getVar('RRECOMMENDS', d, 1) or "")
884 for depend in rdepends:
885 if depend.endswith('-dev'):
886 depend = depend.replace('-dev', '')
887 if depend.endswith('-dbg'):
888 depend = depend.replace('-dbg', '')
889 pkgname = getname(depend, suffix)
890 if not pkgname in rreclist:
891 rreclist.append(pkgname)
893 #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
894 bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
896 def add_dep(list, dep):
897 dep = dep.split(' (')[0].strip()
902 for dep in explode_deps(bb.data.getVar('DEPENDS', d, 1) or ""):
903 add_dep(depends, dep)
906 for dep in explode_deps(bb.data.getVar('RDEPENDS', d, 1) or ""):
907 add_dep(rdepends, dep)
909 for pkg in packages.split():
910 for dep in explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 1) or ""):
911 add_dep(rdepends, dep)
913 #bb.note('rdepends is %s' % rdepends)
915 def post_getname(name, suffix):
916 return '%s%s' % (name, suffix)
917 def pre_getname(name, suffix):
918 return '%s%s' % (suffix, name)
921 for pkg in packages.split():
922 for postfix in postfixes:
923 if pkg.endswith(postfix):
924 if not postfix in pkgs:
926 pkgs[postfix][pkg] = (pkg[:-len(postfix)], post_getname)
928 for prefix in prefixes:
929 if pkg.startswith(prefix):
930 if not prefix in pkgs:
932 pkgs[prefix][pkg] = (pkg[:-len(prefix)], pre_getname)
935 for pkg in pkgs[suffix]:
936 (base, func) = pkgs[suffix][pkg]
937 if suffix == "-dev" and not pkg.startswith("kernel-module-"):
938 pkg_adddeprrecs(pkg, base, suffix, func, depends, d)
939 if len(pkgs[suffix]) == 1:
940 pkg_addrrecs(pkg, base, suffix, func, rdepends, d)
943 for dep in explode_deps(bb.data.getVar('RDEPENDS_' + base, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or ""):
945 pkg_addrrecs(pkg, base, suffix, func, rdeps, d)
949 PACKAGEFUNCS ?= "package_do_split_locales \
952 package_do_pkgconfig \
957 def package_run_hooks(f, d):
959 staging = bb.data.getVar('PKGDATA_DIR', d, True)
960 dn = os.path.join(staging, 'hooks', f)
961 if os.access(dn, os.R_OK):
962 for f in os.listdir(dn):
963 fn = os.path.join(dn, f)
966 for l in fp.readlines():
968 bb.parse.parse_py.BBHandler.feeder(line, l, fn, os.path.basename(fn), d)
971 anonqueue = bb.data.getVar("__anonqueue", d, 1) or []
972 body = [x['content'] for x in anonqueue]
973 flag = { 'python' : 1, 'func' : 1 }
974 bb.data.setVar("__anonfunc", "\n".join(body), d)
975 bb.data.setVarFlags("__anonfunc", flag, d)
977 t = bb.data.getVar('T', d)
978 bb.data.setVar('T', '${TMPDIR}/', d)
979 bb.build.exec_func("__anonfunc", d)
980 bb.data.delVar('T', d)
982 bb.data.setVar('T', t, d)
984 bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e)
986 bb.data.delVar("__anonqueue", d)
987 bb.data.delVar("__anonfunc", d)
989 python package_do_package () {
990 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
991 if len(packages) < 1:
992 bb.debug(1, "No packages to build, skipping do_package")
995 for f in (bb.data.getVar('PACKAGEFUNCS', d, 1) or '').split():
996 bb.build.exec_func(f, d)
997 package_run_hooks(f, d)
999 do_package[dirs] = "${D}"
1000 addtask package before do_build after do_install
1002 # Dummy task to mark when all packaging is complete
1003 do_package_write () {
1006 addtask package_write before do_build after do_package
1008 EXPORT_FUNCTIONS do_package do_package_write
1011 # Helper functions for the package writing classes
1014 python package_mapping_rename_hook () {
1016 Rewrite variables to account for package renaming in things
1017 like debian.bbclass or manual PKG variable name changes
1019 runtime_mapping_rename("RDEPENDS", d)
1020 runtime_mapping_rename("RRECOMMENDS", d)
1021 runtime_mapping_rename("RSUGGESTS", d)
1022 runtime_mapping_rename("RPROVIDES", d)
1023 runtime_mapping_rename("RREPLACES", d)
1024 runtime_mapping_rename("RCONFLICTS", d)
1027 EXPORT_FUNCTIONS mapping_rename_hook