2 # General packaging help functions
5 PKGDEST = "${WORKDIR}/install"
7 def build_package_revision(d):
9 file_pr = bb.data.getVar('PR', d, True)
10 distro_pr = bb.data.getVar('DISTRO_PR', d, True) or ""
11 return "%s%s" % (file_pr, distro_pr)
14 def legitimize_package_name(s):
16 Make sure package names are legitimate strings
23 return ('\u%s' % cp).decode('unicode_escape').encode('utf-8')
25 # Handle unicode codepoints encoded as <U0123>, as in glibc locale files.
26 s = re.sub('<U([0-9A-Fa-f]{1,4})>', fixutf, s)
28 # Remaining package name validity fixes
29 return s.lower().replace('_', '-').replace('@', '+').replace(',', '+').replace('/', '-')
31 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, allow_links=False):
33 Used in .bb files to split up dynamically generated subpackages of a
34 given package, usually plugins or modules.
36 import os, os.path, bb
38 dvar = bb.data.getVar('D', d, 1)
40 bb.error("D not defined")
43 packages = bb.data.getVar('PACKAGES', d, 1).split()
46 postinst = '#!/bin/sh\n' + postinst + '\n'
48 postrm = '#!/bin/sh\n' + postrm + '\n'
50 objs = os.listdir(dvar + root)
53 for walkroot, dirs, files in os.walk(dvar + root):
55 relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1)
59 if extra_depends == None:
60 # This is *really* broken
62 # At least try and patch it up I guess...
63 if mainpkg.find('-dbg'):
64 mainpkg = mainpkg.replace('-dbg', '')
65 if mainpkg.find('-dev'):
66 mainpkg = mainpkg.replace('-dev', '')
67 extra_depends = mainpkg
72 m = re.match(file_regex, o)
74 m = re.match(file_regex, os.path.basename(o))
78 f = os.path.join(dvar + root, o)
79 mode = os.lstat(f).st_mode
80 if not (stat.S_ISREG(mode) or (allow_links and stat.S_ISLNK(mode)) or (allow_dirs and stat.S_ISDIR(mode))):
82 on = legitimize_package_name(m.group(1))
83 pkg = output_pattern % on
84 if not pkg in packages:
86 packages = [pkg] + packages
89 the_files = [os.path.join(root, o)]
91 if type(aux_files_pattern) is list:
92 for fp in aux_files_pattern:
93 the_files.append(fp % on)
95 the_files.append(aux_files_pattern % on)
96 if aux_files_pattern_verbatim:
97 if type(aux_files_pattern_verbatim) is list:
98 for fp in aux_files_pattern_verbatim:
99 the_files.append(fp % m.group(1))
101 the_files.append(aux_files_pattern_verbatim % m.group(1))
102 bb.data.setVar('FILES_' + pkg, " ".join(the_files), d)
103 if extra_depends != '':
104 the_depends = bb.data.getVar('RDEPENDS_' + pkg, d, 1)
106 the_depends = '%s %s' % (the_depends, extra_depends)
108 the_depends = extra_depends
109 bb.data.setVar('RDEPENDS_' + pkg, the_depends, d)
110 bb.data.setVar('DESCRIPTION_' + pkg, description % on, d)
112 bb.data.setVar('pkg_postinst_' + pkg, postinst, d)
114 bb.data.setVar('pkg_postrm_' + pkg, postrm, d)
116 oldfiles = bb.data.getVar('FILES_' + pkg, d, 1)
118 bb.fatal("Package '%s' exists but has no files" % pkg)
119 bb.data.setVar('FILES_' + pkg, oldfiles + " " + os.path.join(root, o), d)
121 hook(f, pkg, file_regex, output_pattern, m.group(1))
123 bb.data.setVar('PACKAGES', ' '.join(packages), d)
125 PACKAGE_DEPENDS += "file-native"
127 def package_stash_hook(func, name, d):
129 body = bb.data.getVar(func, d, True)
130 pn = bb.data.getVar('PN', d, True)
131 staging = bb.data.getVar('PKGDATA_DIR', d, True)
132 dirname = os.path.join(staging, 'hooks', name)
133 bb.mkdirhier(dirname)
134 fn = os.path.join(dirname, pn)
136 f.write("python () {\n");
143 if bb.data.getVar('PACKAGES', d, True) != '':
144 deps = bb.data.getVarFlag('do_package', 'depends', d) or ""
145 for dep in (bb.data.getVar('PACKAGE_DEPENDS', d, True) or "").split():
146 deps += " %s:do_populate_staging" % dep
147 bb.data.setVarFlag('do_package', 'depends', deps, d)
149 deps = (bb.data.getVarFlag('do_package', 'deptask', d) or "").split()
150 # shlibs requires any DEPENDS to have already packaged for the *.list files
151 deps.append("do_package")
152 bb.data.setVarFlag('do_package', 'deptask', " ".join(deps), d)
155 def runstrip(file, d):
156 # Function to strip a single file, called from populate_packages below
157 # A working 'file' (one which works on the target architecture)
158 # is necessary for this stuff to work, hence the addition to do_package[depends]
160 import bb, os, commands, stat
162 pathprefix = "export PATH=%s; " % bb.data.getVar('PATH', d, 1)
164 ret, result = commands.getstatusoutput("%sfile '%s'" % (pathprefix, file))
167 bb.error("runstrip: 'file %s' failed (forced strip)" % file)
169 if "not stripped" not in result:
170 bb.debug(1, "runstrip: skip %s" % file)
173 # If the file is in a .debug directory it was already stripped,
174 # don't do it again...
175 if os.path.dirname(file).endswith(".debug"):
176 bb.note("Already ran strip")
179 strip = bb.data.getVar("STRIP", d, 1)
180 objcopy = bb.data.getVar("OBJCOPY", d, 1)
183 if not os.access(file, os.W_OK):
184 origmode = os.stat(file)[stat.ST_MODE]
185 newmode = origmode | stat.S_IWRITE
186 os.chmod(file, newmode)
189 if ".so" in file and "shared" in result:
190 extraflags = "--remove-section=.comment --remove-section=.note --strip-unneeded"
191 elif "shared" in result or "executable" in result:
192 extraflags = "--remove-section=.comment --remove-section=.note"
194 bb.mkdirhier(os.path.join(os.path.dirname(file), ".debug"))
195 debugfile=os.path.join(os.path.dirname(file), ".debug", os.path.basename(file))
197 stripcmd = "'%s' %s '%s'" % (strip, extraflags, file)
198 bb.debug(1, "runstrip: %s" % stripcmd)
200 os.system("%s'%s' --only-keep-debug '%s' '%s'" % (pathprefix, objcopy, file, debugfile))
201 ret = os.system("%s%s" % (pathprefix, stripcmd))
202 os.system("%s'%s' --add-gnu-debuglink='%s' '%s'" % (pathprefix, objcopy, debugfile, file))
205 os.chmod(file, origmode)
208 bb.error("runstrip: '%s' strip command failed" % stripcmd)
213 # Package data handling routines
216 def get_package_mapping (pkg, d):
219 data = read_subpkgdata(pkg, d)
227 def runtime_mapping_rename (varname, d):
230 #bb.note("%s before: %s" % (varname, bb.data.getVar(varname, d, 1)))
233 for depend in explode_deps(bb.data.getVar(varname, d, 1) or ""):
234 # Have to be careful with any version component of the depend
235 split_depend = depend.split(' (')
236 new_depend = get_package_mapping(split_depend[0].strip(), d)
237 if len(split_depend) > 1:
238 new_depends.append("%s (%s" % (new_depend, split_depend[1]))
240 new_depends.append(new_depend)
242 bb.data.setVar(varname, " ".join(new_depends) or None, d)
244 #bb.note("%s after: %s" % (varname, bb.data.getVar(varname, d, 1)))
247 # Package functions suitable for inclusion in PACKAGEFUNCS
250 python package_do_split_locales() {
253 if (bb.data.getVar('PACKAGE_NO_LOCALE', d, 1) == '1'):
254 bb.debug(1, "package requested not splitting locales")
257 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
259 datadir = bb.data.getVar('datadir', d, 1)
261 bb.note("datadir not defined")
264 dvar = bb.data.getVar('D', d, 1)
266 bb.error("D not defined")
269 pn = bb.data.getVar('PN', d, 1)
271 bb.error("PN not defined")
274 if pn + '-locale' in packages:
275 packages.remove(pn + '-locale')
277 localedir = os.path.join(dvar + datadir, 'locale')
279 if not os.path.isdir(localedir):
280 bb.debug(1, "No locale files in this package")
283 locales = os.listdir(localedir)
285 # This is *really* broken
286 mainpkg = packages[0]
287 # At least try and patch it up I guess...
288 if mainpkg.find('-dbg'):
289 mainpkg = mainpkg.replace('-dbg', '')
290 if mainpkg.find('-dev'):
291 mainpkg = mainpkg.replace('-dev', '')
294 ln = legitimize_package_name(l)
295 pkg = pn + '-locale-' + ln
297 bb.data.setVar('FILES_' + pkg, os.path.join(datadir, 'locale', l), d)
298 bb.data.setVar('RDEPENDS_' + pkg, '%s virtual-locale-%s' % (mainpkg, ln), d)
299 bb.data.setVar('RPROVIDES_' + pkg, '%s-locale %s-translation' % (pn, ln), d)
300 bb.data.setVar('DESCRIPTION_' + pkg, '%s translation for %s' % (l, pn), d)
302 bb.data.setVar('PACKAGES', ' '.join(packages), d)
304 # Disabled by RP 18/06/07
305 # Wildcards aren't supported in debian
306 # They break with ipkg since glibc-locale* will mean that
307 # glibc-localedata-translit* won't install as a dependency
308 # for some other package which breaks meta-toolchain
309 # Probably breaks since virtual-locale- isn't provided anywhere
310 #rdep = (bb.data.getVar('RDEPENDS_%s' % mainpkg, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or "").split()
311 #rdep.append('%s-locale*' % pn)
312 #bb.data.setVar('RDEPENDS_%s' % mainpkg, ' '.join(rdep), d)
315 python populate_packages () {
316 import glob, stat, errno, re
318 workdir = bb.data.getVar('WORKDIR', d, 1)
320 bb.error("WORKDIR not defined, unable to package")
323 import os # path manipulations
324 outdir = bb.data.getVar('DEPLOY_DIR', d, 1)
326 bb.error("DEPLOY_DIR not defined, unable to package")
330 dvar = bb.data.getVar('D', d, 1)
332 bb.error("D not defined, unable to package")
336 packages = bb.data.getVar('PACKAGES', d, 1)
338 pn = bb.data.getVar('PN', d, 1)
340 bb.error("PN not defined")
348 except (os.error, AttributeError):
350 return (s[stat.ST_MODE] & stat.S_IEXEC)
352 # Sanity check PACKAGES for duplicates - should be moved to
353 # sanity.bbclass once we have the infrastucture
355 for pkg in packages.split():
356 if pkg in package_list:
357 bb.error("-------------------")
358 bb.error("%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg)
359 bb.error("Please fix the metadata/report this as bug to OE bugtracker.")
360 bb.error("-------------------")
362 package_list.append(pkg)
364 if (bb.data.getVar('INHIBIT_PACKAGE_STRIP', d, 1) != '1'):
365 for root, dirs, files in os.walk(dvar):
367 file = os.path.join(root, f)
368 if not os.path.islink(file) and not os.path.isdir(file) and isexec(file):
371 pkgdest = bb.data.getVar('PKGDEST', d, 1)
372 os.system('rm -rf %s' % pkgdest)
376 main_pkg = bb.data.getVar('PN', d, 1)
378 for pkg in package_list:
379 localdata = bb.data.createCopy(d)
380 root = os.path.join(pkgdest, pkg)
383 bb.data.setVar('PKG', pkg, localdata)
384 overrides = bb.data.getVar('OVERRIDES', localdata, 1)
386 raise bb.build.FuncFailed('OVERRIDES not defined')
387 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
388 bb.data.update_data(localdata)
390 filesvar = bb.data.getVar('FILES', localdata, 1) or ""
391 files = filesvar.split()
393 if os.path.isabs(file):
395 if not os.path.islink(file):
396 if os.path.isdir(file):
397 newfiles = [ os.path.join(file,x) for x in os.listdir(file) ]
401 globbed = glob.glob(file)
403 if [ file ] != globbed:
406 if (not os.path.islink(file)) and (not os.path.exists(file)):
408 if file[-4:] == '.pyo':
413 if os.path.isdir(file) and not os.path.islink(file):
414 bb.mkdirhier(os.path.join(root,file))
415 os.chmod(os.path.join(root,file), os.stat(file).st_mode)
417 fpath = os.path.join(root,file)
418 dpath = os.path.dirname(fpath)
420 ret = bb.copyfile(file, fpath)
421 if ret is False or ret == 0:
422 raise bb.build.FuncFailed("File population failed")
423 if pkg == main_pkg and main_is_empty:
429 for root, dirs, files in os.walk(dvar):
431 path = os.path.join(root[len(dvar):], f)
432 if ('.' + path) not in seen:
433 unshipped.append(path)
436 bb.note("the following files were installed but not shipped in any package:")
440 bb.build.exec_func("package_name_hook", d)
442 for pkg in package_list:
443 pkgname = bb.data.getVar('PKG_%s' % pkg, d, 1)
445 bb.data.setVar('PKG_%s' % pkg, pkg, d)
449 for pkg in package_list:
450 dangling_links[pkg] = []
452 inst_root = os.path.join(pkgdest, pkg)
453 for root, dirs, files in os.walk(inst_root):
455 path = os.path.join(root, f)
456 rpath = path[len(inst_root):]
457 pkg_files[pkg].append(rpath)
460 except OSError, (err, strerror):
461 if err != errno.ENOENT:
463 target = os.readlink(path)
465 target = os.path.join(root[len(inst_root):], target)
466 dangling_links[pkg].append(os.path.normpath(target))
468 for pkg in package_list:
469 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
471 remstr = "${PN} (= ${DEBPV})"
472 if main_is_empty and remstr in rdepends:
473 rdepends.remove(remstr)
474 for l in dangling_links[pkg]:
476 bb.debug(1, "%s contains dangling link %s" % (pkg, l))
477 for p in package_list:
478 for f in pkg_files[p]:
481 bb.debug(1, "target found in %s" % p)
484 if not p in rdepends:
488 bb.note("%s contains dangling symlink to %s" % (pkg, l))
489 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
491 populate_packages[dirs] = "${D}"
493 python emit_pkgdata() {
494 from glob import glob
496 def write_if_exists(f, pkg, var):
499 c = codecs.getencoder("string_escape")
502 val = bb.data.getVar('%s_%s' % (var, pkg), d, 1)
504 f.write('%s_%s: %s\n' % (var, pkg, encode(val)))
506 packages = bb.data.getVar('PACKAGES', d, True)
507 pkgdatadir = bb.data.getVar('PKGDATA_DIR', d, True)
509 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
510 if pstageactive == "1":
511 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
513 data_file = pkgdatadir + bb.data.expand("/${PN}" , d)
514 f = open(data_file, 'w')
515 f.write("PACKAGES: %s\n" % packages)
517 package_stagefile(data_file, d)
519 workdir = bb.data.getVar('WORKDIR', d, 1)
521 for pkg in packages.split():
522 subdata_file = pkgdatadir + "/runtime/%s" % pkg
523 sf = open(subdata_file, 'w')
524 write_if_exists(sf, pkg, 'PN')
525 write_if_exists(sf, pkg, 'PR')
526 write_if_exists(sf, pkg, 'DESCRIPTION')
527 write_if_exists(sf, pkg, 'RDEPENDS')
528 write_if_exists(sf, pkg, 'RPROVIDES')
529 write_if_exists(sf, pkg, 'RRECOMMENDS')
530 write_if_exists(sf, pkg, 'RSUGGESTS')
531 write_if_exists(sf, pkg, 'RREPLACES')
532 write_if_exists(sf, pkg, 'RCONFLICTS')
533 write_if_exists(sf, pkg, 'PKG')
534 write_if_exists(sf, pkg, 'ALLOW_EMPTY')
535 write_if_exists(sf, pkg, 'FILES')
536 write_if_exists(sf, pkg, 'pkg_postinst')
537 write_if_exists(sf, pkg, 'pkg_postrm')
538 write_if_exists(sf, pkg, 'pkg_preinst')
539 write_if_exists(sf, pkg, 'pkg_prerm')
542 package_stagefile(subdata_file, d)
544 # bb.copyfile(subdata_file, pkgdatadir2 + "/runtime/%s" % pkg)
546 allow_empty = bb.data.getVar('ALLOW_EMPTY_%s' % pkg, d, 1)
548 allow_empty = bb.data.getVar('ALLOW_EMPTY', d, 1)
549 root = "%s/install/%s" % (workdir, pkg)
552 if g or allow_empty == "1":
553 packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg
554 file(packagedfile, 'w').close()
555 package_stagefile(packagedfile, d)
556 if pstageactive == "1":
557 bb.utils.unlockfile(lf)
559 emit_pkgdata[dirs] = "${PKGDATA_DIR}/runtime"
561 ldconfig_postinst_fragment() {
562 if [ x"$D" = "x" ]; then
563 [ -x /sbin/ldconfig ] && /sbin/ldconfig
567 SHLIBSDIR = "${STAGING_DIR_HOST}/shlibs"
569 python package_do_shlibs() {
570 import os, re, os.path
572 exclude_shlibs = bb.data.getVar('EXCLUDE_FROM_SHLIBS', d, 0)
574 bb.note("not generating shlibs")
577 lib_re = re.compile("^lib.*\.so")
578 libdir_re = re.compile(".*/lib$")
580 packages = bb.data.getVar('PACKAGES', d, 1)
582 workdir = bb.data.getVar('WORKDIR', d, 1)
584 bb.error("WORKDIR not defined")
587 ver = bb.data.getVar('PV', d, 1)
589 bb.error("PV not defined")
592 pkgdest = bb.data.getVar('PKGDEST', d, 1)
594 shlibs_dir = bb.data.getVar('SHLIBSDIR', d, 1)
595 bb.mkdirhier(shlibs_dir)
597 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
598 if pstageactive == "1":
599 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
601 if bb.data.getVar('PACKAGE_SNAP_LIB_SYMLINKS', d, True) == "1":
604 snap_symlinks = False
606 if (bb.data.getVar('USE_LDCONFIG', d, True) or "1") == "1":
612 private_libs = bb.data.getVar('PRIVATE_LIBS', d, 1)
613 for pkg in packages.split():
614 needs_ldconfig = False
615 bb.debug(2, "calculating shlib provides for %s" % pkg)
619 top = os.path.join(pkgdest, pkg)
621 for root, dirs, files in os.walk(top):
624 path = os.path.join(root, file)
625 if os.access(path, os.X_OK) or lib_re.match(file):
626 cmd = bb.data.getVar('OBJDUMP', d, 1) + " -p " + path + " 2>/dev/null"
627 cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', d, 1), cmd)
629 lines = fd.readlines()
632 m = re.match("\s+NEEDED\s+([^\s]*)", l)
634 needed[pkg].append(m.group(1))
635 m = re.match("\s+SONAME\s+([^\s]*)", l)
637 this_soname = m.group(1)
638 if not this_soname in sonames:
639 # if library is private (only used by package) then do not build shlib for it
640 if not private_libs or -1 == private_libs.find(this_soname):
641 sonames.append(this_soname)
642 if libdir_re.match(root):
643 needs_ldconfig = True
644 if snap_symlinks and (file != soname):
645 renames.append((path, os.path.join(root, this_soname)))
646 for (old, new) in renames:
648 shlibs_file = os.path.join(shlibs_dir, pkg + ".list")
649 if os.path.exists(shlibs_file):
650 os.remove(shlibs_file)
651 shver_file = os.path.join(shlibs_dir, pkg + ".ver")
652 if os.path.exists(shver_file):
653 os.remove(shver_file)
655 fd = open(shlibs_file, 'w')
659 package_stagefile(shlibs_file, d)
660 fd = open(shver_file, 'w')
663 package_stagefile(shver_file, d)
664 if needs_ldconfig and use_ldconfig:
665 bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg)
666 postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1)
668 postinst = '#!/bin/sh\n'
669 postinst += bb.data.getVar('ldconfig_postinst_fragment', d, 1)
670 bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
672 if pstageactive == "1":
673 bb.utils.unlockfile(lf)
676 list_re = re.compile('^(.*)\.list$')
677 for dir in [shlibs_dir]:
678 if not os.path.exists(dir):
680 for file in os.listdir(dir):
681 m = list_re.match(file)
684 fd = open(os.path.join(dir, file))
685 lines = fd.readlines()
687 ver_file = os.path.join(dir, dep_pkg + '.ver')
689 if os.path.exists(ver_file):
691 lib_ver = fd.readline().rstrip()
694 shlib_provider[l.rstrip()] = (dep_pkg, lib_ver)
696 assumed_libs = bb.data.getVar('ASSUME_SHLIBS', d, 1)
698 for e in assumed_libs.split():
699 l, dep_pkg = e.split(":")
701 dep_pkg = dep_pkg.rsplit("_", 1)
702 if len(dep_pkg) == 2:
705 shlib_provider[l] = (dep_pkg, lib_ver)
708 for pkg in packages.split():
709 bb.debug(2, "calculating shlib requirements for %s" % pkg)
712 for n in needed[pkg]:
713 if n in shlib_provider.keys():
714 (dep_pkg, ver_needed) = shlib_provider[n]
720 dep = "%s (>= %s)" % (dep_pkg, ver_needed)
725 if not dep_pkg in dep_packages:
726 dep_packages.append(dep_pkg)
729 bb.note("Couldn't find shared library provider for %s" % n)
731 deps_file = os.path.join(pkgdest, pkg + ".shlibdeps")
732 if os.path.exists(deps_file):
735 fd = open(deps_file, 'w')
741 python package_do_pkgconfig () {
744 packages = bb.data.getVar('PACKAGES', d, 1)
746 workdir = bb.data.getVar('WORKDIR', d, 1)
748 bb.error("WORKDIR not defined")
751 pkgdest = bb.data.getVar('PKGDEST', d, 1)
753 shlibs_dir = bb.data.getVar('SHLIBSDIR', d, 1)
754 bb.mkdirhier(shlibs_dir)
756 pc_re = re.compile('(.*)\.pc$')
757 var_re = re.compile('(.*)=(.*)')
758 field_re = re.compile('(.*): (.*)')
760 pkgconfig_provided = {}
761 pkgconfig_needed = {}
762 for pkg in packages.split():
763 pkgconfig_provided[pkg] = []
764 pkgconfig_needed[pkg] = []
765 top = os.path.join(pkgdest, pkg)
766 for root, dirs, files in os.walk(top):
768 m = pc_re.match(file)
772 pkgconfig_provided[pkg].append(name)
773 path = os.path.join(root, file)
774 if not os.access(path, os.R_OK):
777 lines = f.readlines()
784 bb.data.setVar(name, bb.data.expand(val, pd), pd)
786 m = field_re.match(l)
789 exp = bb.data.expand(m.group(2), pd)
790 if hdr == 'Requires':
791 pkgconfig_needed[pkg] += exp.replace(',', ' ').split()
793 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
794 if pstageactive == "1":
795 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
797 for pkg in packages.split():
798 pkgs_file = os.path.join(shlibs_dir, pkg + ".pclist")
799 if os.path.exists(pkgs_file):
801 if pkgconfig_provided[pkg] != []:
802 f = open(pkgs_file, 'w')
803 for p in pkgconfig_provided[pkg]:
806 package_stagefile(pkgs_file, d)
808 for dir in [shlibs_dir]:
809 if not os.path.exists(dir):
811 for file in os.listdir(dir):
812 m = re.match('^(.*)\.pclist$', file)
815 fd = open(os.path.join(dir, file))
816 lines = fd.readlines()
818 pkgconfig_provided[pkg] = []
820 pkgconfig_provided[pkg].append(l.rstrip())
822 for pkg in packages.split():
824 for n in pkgconfig_needed[pkg]:
826 for k in pkgconfig_provided.keys():
827 if n in pkgconfig_provided[k]:
828 if k != pkg and not (k in deps):
832 bb.note("couldn't find pkgconfig module '%s' in any package" % n)
833 deps_file = os.path.join(pkgdest, pkg + ".pcdeps")
834 if os.path.exists(deps_file):
837 fd = open(deps_file, 'w')
841 package_stagefile(deps_file, d)
843 if pstageactive == "1":
844 bb.utils.unlockfile(lf)
847 python read_shlibdeps () {
848 packages = bb.data.getVar('PACKAGES', d, 1).split()
850 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
851 for extension in ".shlibdeps", ".pcdeps", ".clilibdeps":
852 depsfile = bb.data.expand("${PKGDEST}/" + pkg + extension, d)
853 if os.access(depsfile, os.R_OK):
855 lines = fd.readlines()
858 rdepends.append(l.rstrip())
859 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
862 python package_depchains() {
864 For a given set of prefix and postfix modifiers, make those packages
865 RRECOMMENDS on the corresponding packages for its RDEPENDS.
867 Example: If package A depends upon package B, and A's .bb emits an
868 A-dev package, this would make A-dev Recommends: B-dev.
870 If only one of a given suffix is specified, it will take the RRECOMMENDS
871 based on the RDEPENDS of *all* other packages. If more than one of a given
872 suffix is specified, its will only use the RDEPENDS of the single parent
876 packages = bb.data.getVar('PACKAGES', d, 1)
877 postfixes = (bb.data.getVar('DEPCHAIN_POST', d, 1) or '').split()
878 prefixes = (bb.data.getVar('DEPCHAIN_PRE', d, 1) or '').split()
880 def pkg_adddeprrecs(pkg, base, suffix, getname, depends, d):
882 #bb.note('depends for %s is %s' % (base, depends))
883 rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, 1) or bb.data.getVar('RRECOMMENDS', d, 1) or "")
885 for depend in depends:
886 if depend.find('-native') != -1 or depend.find('-cross') != -1 or depend.startswith('virtual/'):
887 #bb.note("Skipping %s" % depend)
889 if depend.endswith('-dev'):
890 depend = depend.replace('-dev', '')
891 if depend.endswith('-dbg'):
892 depend = depend.replace('-dbg', '')
893 pkgname = getname(depend, suffix)
894 #bb.note("Adding %s for %s" % (pkgname, depend))
895 if not pkgname in rreclist:
896 rreclist.append(pkgname)
898 #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
899 bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
901 def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d):
903 #bb.note('rdepends for %s is %s' % (base, rdepends))
904 rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, 1) or bb.data.getVar('RRECOMMENDS', d, 1) or "")
906 for depend in rdepends:
907 if depend.endswith('-dev'):
908 depend = depend.replace('-dev', '')
909 if depend.endswith('-dbg'):
910 depend = depend.replace('-dbg', '')
911 pkgname = getname(depend, suffix)
912 if not pkgname in rreclist:
913 rreclist.append(pkgname)
915 #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
916 bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
918 def add_dep(list, dep):
919 dep = dep.split(' (')[0].strip()
924 for dep in explode_deps(bb.data.getVar('DEPENDS', d, 1) or ""):
925 add_dep(depends, dep)
928 for dep in explode_deps(bb.data.getVar('RDEPENDS', d, 1) or ""):
929 add_dep(rdepends, dep)
931 for pkg in packages.split():
932 for dep in explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 1) or ""):
933 add_dep(rdepends, dep)
935 #bb.note('rdepends is %s' % rdepends)
937 def post_getname(name, suffix):
938 return '%s%s' % (name, suffix)
939 def pre_getname(name, suffix):
940 return '%s%s' % (suffix, name)
943 for pkg in packages.split():
944 for postfix in postfixes:
945 if pkg.endswith(postfix):
946 if not postfix in pkgs:
948 pkgs[postfix][pkg] = (pkg[:-len(postfix)], post_getname)
950 for prefix in prefixes:
951 if pkg.startswith(prefix):
952 if not prefix in pkgs:
954 pkgs[prefix][pkg] = (pkg[:-len(prefix)], pre_getname)
957 for pkg in pkgs[suffix]:
958 (base, func) = pkgs[suffix][pkg]
959 if suffix == "-dev" and not pkg.startswith("kernel-module-"):
960 pkg_adddeprrecs(pkg, base, suffix, func, depends, d)
961 if len(pkgs[suffix]) == 1:
962 pkg_addrrecs(pkg, base, suffix, func, rdepends, d)
965 for dep in explode_deps(bb.data.getVar('RDEPENDS_' + base, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or ""):
967 pkg_addrrecs(pkg, base, suffix, func, rdeps, d)
971 PACKAGEFUNCS ?= "package_do_split_locales \
974 package_do_pkgconfig \
979 def package_run_hooks(f, d):
981 staging = bb.data.getVar('PKGDATA_DIR', d, True)
982 dn = os.path.join(staging, 'hooks', f)
983 if os.access(dn, os.R_OK):
984 for f in os.listdir(dn):
985 fn = os.path.join(dn, f)
988 for l in fp.readlines():
990 bb.parse.parse_py.BBHandler.feeder(line, l, fn, os.path.basename(fn), d)
993 anonqueue = bb.data.getVar("__anonqueue", d, 1) or []
994 body = [x['content'] for x in anonqueue]
995 flag = { 'python' : 1, 'func' : 1 }
996 bb.data.setVar("__anonfunc", "\n".join(body), d)
997 bb.data.setVarFlags("__anonfunc", flag, d)
999 t = bb.data.getVar('T', d)
1000 bb.data.setVar('T', '${TMPDIR}/', d)
1001 bb.build.exec_func("__anonfunc", d)
1002 bb.data.delVar('T', d)
1004 bb.data.setVar('T', t, d)
1005 except Exception, e:
1006 bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e)
1008 bb.data.delVar("__anonqueue", d)
1009 bb.data.delVar("__anonfunc", d)
1011 python package_do_package () {
1012 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
1013 if len(packages) < 1:
1014 bb.debug(1, "No packages to build, skipping do_package")
1017 for f in (bb.data.getVar('PACKAGEFUNCS', d, 1) or '').split():
1018 bb.build.exec_func(f, d)
1019 package_run_hooks(f, d)
1021 do_package[dirs] = "${D}"
1022 addtask package before do_build after do_install
1024 # Dummy task to mark when all packaging is complete
1025 do_package_write () {
1028 addtask package_write before do_build after do_package
1030 EXPORT_FUNCTIONS do_package do_package_write
1033 # Helper functions for the package writing classes
1036 python package_mapping_rename_hook () {
1038 Rewrite variables to account for package renaming in things
1039 like debian.bbclass or manual PKG variable name changes
1041 runtime_mapping_rename("RDEPENDS", d)
1042 runtime_mapping_rename("RRECOMMENDS", d)
1043 runtime_mapping_rename("RSUGGESTS", d)
1044 runtime_mapping_rename("RPROVIDES", d)
1045 runtime_mapping_rename("RREPLACES", d)
1046 runtime_mapping_rename("RCONFLICTS", d)
1049 EXPORT_FUNCTIONS mapping_rename_hook