2 # General packaging help functions
5 PKGD = "${WORKDIR}/package"
6 PKGDEST = "${WORKDIR}/packages-split"
9 PKGR ?= "${PR}${DISTRO_PR}"
11 EXTENDPKGEVER = "${@['','${PKGE\x7d:'][bb.data.getVar('PKGE',d,1) > 0]}"
12 EXTENDPKGV ?= "${EXTENDPKGEVER}${PKGV}-${PKGR}"
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.
37 dvar = bb.data.getVar('PKGD', d, True)
39 packages = bb.data.getVar('PACKAGES', d, True).split()
42 postinst = '#!/bin/sh\n' + postinst + '\n'
44 postrm = '#!/bin/sh\n' + postrm + '\n'
46 objs = os.listdir(dvar + root)
49 for walkroot, dirs, files in os.walk(dvar + root):
51 relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1)
55 if extra_depends == None:
56 # This is *really* broken
58 # At least try and patch it up I guess...
59 if mainpkg.find('-dbg'):
60 mainpkg = mainpkg.replace('-dbg', '')
61 if mainpkg.find('-dev'):
62 mainpkg = mainpkg.replace('-dev', '')
63 extra_depends = mainpkg
68 m = re.match(file_regex, o)
70 m = re.match(file_regex, os.path.basename(o))
74 f = os.path.join(dvar + root, o)
75 mode = os.lstat(f).st_mode
76 if not (stat.S_ISREG(mode) or (allow_links and stat.S_ISLNK(mode)) or (allow_dirs and stat.S_ISDIR(mode))):
78 on = legitimize_package_name(m.group(1))
79 pkg = output_pattern % on
80 if not pkg in packages:
82 packages = [pkg] + packages
85 the_files = [os.path.join(root, o)]
87 if type(aux_files_pattern) is list:
88 for fp in aux_files_pattern:
89 the_files.append(fp % on)
91 the_files.append(aux_files_pattern % on)
92 if aux_files_pattern_verbatim:
93 if type(aux_files_pattern_verbatim) is list:
94 for fp in aux_files_pattern_verbatim:
95 the_files.append(fp % m.group(1))
97 the_files.append(aux_files_pattern_verbatim % m.group(1))
98 bb.data.setVar('FILES_' + pkg, " ".join(the_files), d)
99 if extra_depends != '':
100 the_depends = bb.data.getVar('RDEPENDS_' + pkg, d, True)
102 the_depends = '%s %s' % (the_depends, extra_depends)
104 the_depends = extra_depends
105 bb.data.setVar('RDEPENDS_' + pkg, the_depends, d)
106 bb.data.setVar('DESCRIPTION_' + pkg, description % on, d)
108 bb.data.setVar('pkg_postinst_' + pkg, postinst, d)
110 bb.data.setVar('pkg_postrm_' + pkg, postrm, d)
112 oldfiles = bb.data.getVar('FILES_' + pkg, d, True)
114 bb.fatal("Package '%s' exists but has no files" % pkg)
115 bb.data.setVar('FILES_' + pkg, oldfiles + " " + os.path.join(root, o), d)
117 hook(f, pkg, file_regex, output_pattern, m.group(1))
119 bb.data.setVar('PACKAGES', ' '.join(packages), d)
121 PACKAGE_DEPENDS += "file-native"
123 def package_stash_hook(func, name, d):
125 body = bb.data.getVar(func, d, True)
126 pn = bb.data.getVar('PN', d, True)
127 staging = bb.data.getVar('PKGDATA_DIR', d, True)
128 dirname = os.path.join(staging, 'hooks', name)
129 bb.mkdirhier(dirname)
130 fn = os.path.join(dirname, pn)
132 f.write("python () {\n");
138 if bb.data.getVar('PACKAGES', d, True) != '':
139 deps = bb.data.getVarFlag('do_package', 'depends', d) or ""
140 for dep in (bb.data.getVar('PACKAGE_DEPENDS', d, True) or "").split():
141 deps += " %s:do_populate_staging" % dep
142 bb.data.setVarFlag('do_package', 'depends', deps, d)
144 deps = (bb.data.getVarFlag('do_package', 'deptask', d) or "").split()
145 # shlibs requires any DEPENDS to have already packaged for the *.list files
146 deps.append("do_package")
147 bb.data.setVarFlag('do_package', 'deptask', " ".join(deps), d)
150 def runstrip(file, d):
151 # Function to strip a single file, called from populate_packages below
152 # A working 'file' (one which works on the target architecture)
153 # is necessary for this stuff to work, hence the addition to do_package[depends]
155 import commands, stat
157 pathprefix = "export PATH=%s; " % bb.data.getVar('PATH', d, True)
159 ret, result = commands.getstatusoutput("%sfile '%s'" % (pathprefix, file))
162 bb.error("runstrip: 'file %s' failed (forced strip)" % file)
164 if "not stripped" not in result:
165 bb.debug(1, "runstrip: skip %s" % file)
168 # If the file is in a .debug directory it was already stripped,
169 # don't do it again...
170 if os.path.dirname(file).endswith(".debug"):
171 bb.debug(2, "Already ran strip on %s" % file)
174 strip = bb.data.getVar("STRIP", d, True)
175 objcopy = bb.data.getVar("OBJCOPY", d, True)
178 if not os.access(file, os.W_OK):
179 origmode = os.stat(file)[stat.ST_MODE]
180 newmode = origmode | stat.S_IWRITE
181 os.chmod(file, newmode)
184 if ".so" in file and "shared" in result:
185 extraflags = "--remove-section=.comment --remove-section=.note --strip-unneeded"
186 elif "shared" in result or "executable" in result:
187 extraflags = "--remove-section=.comment --remove-section=.note"
188 elif file.endswith(".a"):
189 extraflags = "--remove-section=.comment --strip-debug"
192 bb.mkdirhier(os.path.join(os.path.dirname(file), ".debug"))
193 debugfile=os.path.join(os.path.dirname(file), ".debug", os.path.basename(file))
195 stripcmd = "'%s' %s '%s'" % (strip, extraflags, file)
196 bb.debug(1, "runstrip: %s" % stripcmd)
198 os.system("%s'%s' --only-keep-debug '%s' '%s'" % (pathprefix, objcopy, file, debugfile))
199 ret = os.system("%s%s" % (pathprefix, stripcmd))
200 os.system("%s'%s' --add-gnu-debuglink='%s' '%s'" % (pathprefix, objcopy, debugfile, file))
203 os.chmod(file, origmode)
206 bb.error("runstrip: '%s' strip command failed" % stripcmd)
210 PACKAGESTRIPFUNCS += "do_runstrip"
211 python do_runstrip() {
214 dvar = bb.data.getVar('PKGD', d, True)
218 except (os.error, AttributeError):
220 return (s[stat.ST_MODE] & stat.S_IEXEC)
222 for root, dirs, files in os.walk(dvar):
224 file = os.path.join(root, f)
225 if not os.path.islink(file) and not os.path.isdir(file) and isexec(file):
230 def write_package_md5sums (root, outfile, ignorepaths):
231 # For each regular file under root, writes an md5sum to outfile.
232 # With thanks to patch.bbclass.
243 outf = file(outfile, 'w')
245 # Each output line looks like: "<hex...> <filename without leading slash>"
247 if not root.endswith('/'):
250 for walkroot, dirs, files in os.walk(root):
251 # Skip e.g. the DEBIAN directory
252 if walkroot[striplen:] in ignorepaths:
257 fullpath = os.path.join(walkroot, name)
258 if os.path.islink(fullpath) or (not os.path.isfile(fullpath)):
262 f = file(fullpath, 'rb')
270 print >> outf, "%s %s" % (m.hexdigest(), fullpath[striplen:])
276 # Package data handling routines
279 def get_package_mapping (pkg, d):
280 data = read_subpkgdata(pkg, d)
288 def runtime_mapping_rename (varname, d):
289 #bb.note("%s before: %s" % (varname, bb.data.getVar(varname, d, True)))
292 for depend in explode_deps(bb.data.getVar(varname, d, True) or ""):
293 # Have to be careful with any version component of the depend
294 split_depend = depend.split(' (')
295 new_depend = get_package_mapping(split_depend[0].strip(), d)
296 if len(split_depend) > 1:
297 new_depends.append("%s (%s" % (new_depend, split_depend[1]))
299 new_depends.append(new_depend)
301 bb.data.setVar(varname, " ".join(new_depends) or None, d)
303 #bb.note("%s after: %s" % (varname, bb.data.getVar(varname, d, True)))
306 # Package functions suitable for inclusion in PACKAGEFUNCS
309 python package_do_split_locales() {
310 if (bb.data.getVar('PACKAGE_NO_LOCALE', d, True) == '1'):
311 bb.debug(1, "package requested not splitting locales")
314 packages = (bb.data.getVar('PACKAGES', d, True) or "").split()
316 datadir = bb.data.getVar('datadir', d, True)
318 bb.note("datadir not defined")
321 dvar = bb.data.getVar('PKGD', d, True)
322 pn = bb.data.getVar('PN', d, True)
324 if pn + '-locale' in packages:
325 packages.remove(pn + '-locale')
327 localedir = os.path.join(dvar + datadir, 'locale')
329 if not os.path.isdir(localedir):
330 bb.debug(1, "No locale files in this package")
333 locales = os.listdir(localedir)
335 # This is *really* broken
336 mainpkg = packages[0]
337 # At least try and patch it up I guess...
338 if mainpkg.find('-dbg'):
339 mainpkg = mainpkg.replace('-dbg', '')
340 if mainpkg.find('-dev'):
341 mainpkg = mainpkg.replace('-dev', '')
344 ln = legitimize_package_name(l)
345 pkg = pn + '-locale-' + ln
347 bb.data.setVar('FILES_' + pkg, os.path.join(datadir, 'locale', l), d)
348 bb.data.setVar('RDEPENDS_' + pkg, '%s virtual-locale-%s' % (mainpkg, ln), d)
349 bb.data.setVar('RPROVIDES_' + pkg, '%s-locale %s-translation' % (pn, ln), d)
350 bb.data.setVar('DESCRIPTION_' + pkg, '%s translation for %s' % (l, pn), d)
352 bb.data.setVar('PACKAGES', ' '.join(packages), d)
355 python perform_packagecopy () {
356 dest = bb.data.getVar('D', d, True)
357 dvar = bb.data.getVar('PKGD', d, True)
361 # Start by package population by taking a copy of the installed
362 # files to operate on
363 os.system('rm -rf %s/*' % (dvar))
364 os.system('cp -pPR %s/* %s/' % (dest, dvar))
367 python populate_packages () {
368 import glob, errno, re,os
370 workdir = bb.data.getVar('WORKDIR', d, True)
371 outdir = bb.data.getVar('DEPLOY_DIR', d, True)
372 dvar = bb.data.getVar('PKGD', d, True)
373 packages = bb.data.getVar('PACKAGES', d, True)
374 pn = bb.data.getVar('PN', d, True)
379 # Sanity check PACKAGES for duplicates - should be moved to
380 # sanity.bbclass once we have the infrastucture
382 for pkg in packages.split():
383 if pkg in package_list:
384 bb.error("-------------------")
385 bb.error("%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg)
386 bb.error("Please fix the metadata/report this as bug to OE bugtracker.")
387 bb.error("-------------------")
389 package_list.append(pkg)
392 if (bb.data.getVar('INHIBIT_PACKAGE_STRIP', d, True) != '1'):
393 for f in (bb.data.getVar('PACKAGESTRIPFUNCS', d, True) or '').split():
394 bb.build.exec_func(f, d)
396 pkgdest = bb.data.getVar('PKGDEST', d, True)
397 os.system('rm -rf %s' % pkgdest)
401 main_pkg = bb.data.getVar('PN', d, True)
403 for pkg in package_list:
404 localdata = bb.data.createCopy(d)
405 root = os.path.join(pkgdest, pkg)
408 bb.data.setVar('PKG', pkg, localdata)
409 overrides = bb.data.getVar('OVERRIDES', localdata, True)
411 raise bb.build.FuncFailed('OVERRIDES not defined')
412 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
413 bb.data.update_data(localdata)
415 filesvar = bb.data.getVar('FILES', localdata, True) or ""
416 files = filesvar.split()
418 if os.path.isabs(file):
420 if not os.path.islink(file):
421 if os.path.isdir(file):
422 newfiles = [ os.path.join(file,x) for x in os.listdir(file) ]
426 globbed = glob.glob(file)
428 if [ file ] != globbed:
429 if not file in globbed:
435 if (not os.path.islink(file)) and (not os.path.exists(file)):
440 if os.path.isdir(file) and not os.path.islink(file):
441 bb.mkdirhier(os.path.join(root,file))
442 os.chmod(os.path.join(root,file), os.stat(file).st_mode)
444 fpath = os.path.join(root,file)
445 dpath = os.path.dirname(fpath)
447 ret = bb.copyfile(file, fpath)
449 raise bb.build.FuncFailed("File population failed when copying %s to %s" % (file, fpath))
450 if pkg == main_pkg and main_is_empty:
456 for root, dirs, files in os.walk(dvar):
458 path = os.path.join(root[len(dvar):], f)
459 if ('.' + path) not in seen:
460 unshipped.append(path)
463 bb.note("the following files were installed but not shipped in any package:")
467 bb.build.exec_func("package_name_hook", d)
469 for pkg in package_list:
470 pkgname = bb.data.getVar('PKG_%s' % pkg, d, True)
472 bb.data.setVar('PKG_%s' % pkg, pkg, d)
476 for pkg in package_list:
477 dangling_links[pkg] = []
479 inst_root = os.path.join(pkgdest, pkg)
480 for root, dirs, files in os.walk(inst_root):
482 path = os.path.join(root, f)
483 rpath = path[len(inst_root):]
484 pkg_files[pkg].append(rpath)
487 except OSError, (err, strerror):
488 if err != errno.ENOENT:
490 target = os.readlink(path)
492 target = os.path.join(root[len(inst_root):], target)
493 dangling_links[pkg].append(os.path.normpath(target))
495 for pkg in package_list:
496 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
498 remstr = "${PN} (= ${EXTENDPKGV})"
499 if main_is_empty and remstr in rdepends:
500 rdepends.remove(remstr)
501 for l in dangling_links[pkg]:
503 bb.debug(1, "%s contains dangling link %s" % (pkg, l))
504 for p in package_list:
505 for f in pkg_files[p]:
508 bb.debug(1, "target found in %s" % p)
511 if not p in rdepends:
515 bb.note("%s contains dangling symlink to %s" % (pkg, l))
516 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
518 populate_packages[dirs] = "${D}"
520 python emit_pkgdata() {
521 from glob import glob
523 def write_if_exists(f, pkg, var):
526 c = codecs.getencoder("string_escape")
529 val = bb.data.getVar('%s_%s' % (var, pkg), d, True)
531 f.write('%s_%s: %s\n' % (var, pkg, encode(val)))
533 val = bb.data.getVar('%s' % (var), d, True)
535 f.write('%s: %s\n' % (var, encode(val)))
538 packages = bb.data.getVar('PACKAGES', d, True)
539 pkgdest = bb.data.getVar('PKGDEST', d, 1)
540 pkgdatadir = bb.data.getVar('PKGDATA_DIR', d, True)
542 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
543 if pstageactive == "1":
544 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
546 data_file = pkgdatadir + bb.data.expand("/${PN}" , d)
547 f = open(data_file, 'w')
548 f.write("PACKAGES: %s\n" % packages)
550 package_stagefile(data_file, d)
552 workdir = bb.data.getVar('WORKDIR', d, True)
554 for pkg in packages.split():
555 subdata_file = pkgdatadir + "/runtime/%s" % pkg
556 sf = open(subdata_file, 'w')
557 write_if_exists(sf, pkg, 'PN')
558 write_if_exists(sf, pkg, 'PV')
559 write_if_exists(sf, pkg, 'PR')
560 write_if_exists(sf, pkg, 'PKGV')
561 write_if_exists(sf, pkg, 'PKGR')
562 write_if_exists(sf, pkg, 'DESCRIPTION')
563 write_if_exists(sf, pkg, 'RDEPENDS')
564 write_if_exists(sf, pkg, 'RPROVIDES')
565 write_if_exists(sf, pkg, 'RRECOMMENDS')
566 write_if_exists(sf, pkg, 'RSUGGESTS')
567 write_if_exists(sf, pkg, 'RREPLACES')
568 write_if_exists(sf, pkg, 'RCONFLICTS')
569 write_if_exists(sf, pkg, 'PKG')
570 write_if_exists(sf, pkg, 'ALLOW_EMPTY')
571 write_if_exists(sf, pkg, 'FILES')
572 write_if_exists(sf, pkg, 'pkg_postinst')
573 write_if_exists(sf, pkg, 'pkg_postrm')
574 write_if_exists(sf, pkg, 'pkg_preinst')
575 write_if_exists(sf, pkg, 'pkg_prerm')
578 package_stagefile(subdata_file, d)
580 # bb.copyfile(subdata_file, pkgdatadir2 + "/runtime/%s" % pkg)
582 allow_empty = bb.data.getVar('ALLOW_EMPTY_%s' % pkg, d, True)
584 allow_empty = bb.data.getVar('ALLOW_EMPTY', d, True)
585 root = "%s/%s" % (pkgdest, pkg)
587 g = glob('*') + glob('.[!.]*')
588 if g or allow_empty == "1":
589 packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg
590 file(packagedfile, 'w').close()
591 package_stagefile(packagedfile, d)
592 if pstageactive == "1":
593 bb.utils.unlockfile(lf)
595 emit_pkgdata[dirs] = "${PKGDATA_DIR}/runtime"
597 ldconfig_postinst_fragment() {
598 if [ x"$D" = "x" ]; then
599 if [ -e /etc/ld.so.conf ] ; then
600 [ -x /sbin/ldconfig ] && /sbin/ldconfig
605 SHLIBSDIR = "${STAGING_DIR_HOST}/shlibs"
607 python package_do_shlibs() {
610 exclude_shlibs = bb.data.getVar('EXCLUDE_FROM_SHLIBS', d, 0)
612 bb.debug(1, "not generating shlibs")
615 lib_re = re.compile("^lib.*\.so")
616 libdir_re = re.compile(".*/lib$")
618 packages = bb.data.getVar('PACKAGES', d, True)
620 workdir = bb.data.getVar('WORKDIR', d, True)
622 ver = bb.data.getVar('PKGV', d, True)
624 bb.error("PKGV not defined")
627 pkgdest = bb.data.getVar('PKGDEST', d, True)
629 shlibs_dir = bb.data.getVar('SHLIBSDIR', d, True)
630 bb.mkdirhier(shlibs_dir)
632 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
633 if pstageactive == "1":
634 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
636 if bb.data.getVar('PACKAGE_SNAP_LIB_SYMLINKS', d, True) == "1":
639 snap_symlinks = False
641 if (bb.data.getVar('USE_LDCONFIG', d, True) or "1") == "1":
647 private_libs = bb.data.getVar('PRIVATE_LIBS', d, True)
648 for pkg in packages.split():
649 needs_ldconfig = False
650 bb.debug(2, "calculating shlib provides for %s" % pkg)
652 pkgver = bb.data.getVar('PKGV_' + pkg, d, True)
654 pkgver = bb.data.getVar('PV_' + pkg, d, True)
660 top = os.path.join(pkgdest, pkg)
662 for root, dirs, files in os.walk(top):
665 path = os.path.join(root, file)
666 if (os.access(path, os.X_OK) or lib_re.match(file)) and not os.path.islink(path):
667 cmd = bb.data.getVar('OBJDUMP', d, True) + " -p " + path + " 2>/dev/null"
668 cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', d, True), cmd)
670 lines = fd.readlines()
673 m = re.match("\s+NEEDED\s+([^\s]*)", l)
675 needed[pkg].append(m.group(1))
676 m = re.match("\s+SONAME\s+([^\s]*)", l)
678 this_soname = m.group(1)
679 if not this_soname in sonames:
680 # if library is private (only used by package) then do not build shlib for it
681 if not private_libs or -1 == private_libs.find(this_soname):
682 sonames.append(this_soname)
683 if libdir_re.match(root):
684 needs_ldconfig = True
685 if snap_symlinks and (file != soname):
686 renames.append((path, os.path.join(root, this_soname)))
687 for (old, new) in renames:
689 shlibs_file = os.path.join(shlibs_dir, pkg + ".list")
690 if os.path.exists(shlibs_file):
691 os.remove(shlibs_file)
692 shver_file = os.path.join(shlibs_dir, pkg + ".ver")
693 if os.path.exists(shver_file):
694 os.remove(shver_file)
696 fd = open(shlibs_file, 'w')
700 package_stagefile(shlibs_file, d)
701 fd = open(shver_file, 'w')
702 fd.write(pkgver + '\n')
704 package_stagefile(shver_file, d)
705 if needs_ldconfig and use_ldconfig:
706 bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg)
707 postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, True) or bb.data.getVar('pkg_postinst', d, True)
709 postinst = '#!/bin/sh\n'
710 postinst += bb.data.getVar('ldconfig_postinst_fragment', d, True)
711 bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
713 if pstageactive == "1":
714 bb.utils.unlockfile(lf)
717 list_re = re.compile('^(.*)\.list$')
718 for dir in [shlibs_dir]:
719 if not os.path.exists(dir):
721 for file in os.listdir(dir):
722 m = list_re.match(file)
725 fd = open(os.path.join(dir, file))
726 lines = fd.readlines()
728 ver_file = os.path.join(dir, dep_pkg + '.ver')
730 if os.path.exists(ver_file):
732 lib_ver = fd.readline().rstrip()
735 shlib_provider[l.rstrip()] = (dep_pkg, lib_ver)
737 assumed_libs = bb.data.getVar('ASSUME_SHLIBS', d, True)
739 for e in assumed_libs.split():
740 l, dep_pkg = e.split(":")
742 dep_pkg = dep_pkg.rsplit("_", 1)
743 if len(dep_pkg) == 2:
746 shlib_provider[l] = (dep_pkg, lib_ver)
749 for pkg in packages.split():
750 bb.debug(2, "calculating shlib requirements for %s" % pkg)
753 for n in needed[pkg]:
754 if n in shlib_provider.keys():
755 (dep_pkg, ver_needed) = shlib_provider[n]
761 dep = "%s (>= %s)" % (dep_pkg, ver_needed)
766 if not dep_pkg in dep_packages:
767 dep_packages.append(dep_pkg)
770 bb.note("Couldn't find shared library provider for %s" % n)
772 deps_file = os.path.join(pkgdest, pkg + ".shlibdeps")
773 if os.path.exists(deps_file):
776 fd = open(deps_file, 'w')
782 python package_do_pkgconfig () {
785 packages = bb.data.getVar('PACKAGES', d, True)
786 workdir = bb.data.getVar('WORKDIR', d, True)
787 pkgdest = bb.data.getVar('PKGDEST', d, True)
789 shlibs_dir = bb.data.getVar('SHLIBSDIR', d, True)
790 bb.mkdirhier(shlibs_dir)
792 pc_re = re.compile('(.*)\.pc$')
793 var_re = re.compile('(.*)=(.*)')
794 field_re = re.compile('(.*): (.*)')
796 pkgconfig_provided = {}
797 pkgconfig_needed = {}
798 for pkg in packages.split():
799 pkgconfig_provided[pkg] = []
800 pkgconfig_needed[pkg] = []
801 top = os.path.join(pkgdest, pkg)
802 for root, dirs, files in os.walk(top):
804 m = pc_re.match(file)
808 pkgconfig_provided[pkg].append(name)
809 path = os.path.join(root, file)
810 if not os.access(path, os.R_OK):
813 lines = f.readlines()
820 bb.data.setVar(name, bb.data.expand(val, pd), pd)
822 m = field_re.match(l)
825 exp = bb.data.expand(m.group(2), pd)
826 if hdr == 'Requires':
827 pkgconfig_needed[pkg] += exp.replace(',', ' ').split()
829 pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
830 if pstageactive == "1":
831 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
833 for pkg in packages.split():
834 pkgs_file = os.path.join(shlibs_dir, pkg + ".pclist")
835 if os.path.exists(pkgs_file):
837 if pkgconfig_provided[pkg] != []:
838 f = open(pkgs_file, 'w')
839 for p in pkgconfig_provided[pkg]:
842 package_stagefile(pkgs_file, d)
844 for dir in [shlibs_dir]:
845 if not os.path.exists(dir):
847 for file in os.listdir(dir):
848 m = re.match('^(.*)\.pclist$', file)
851 fd = open(os.path.join(dir, file))
852 lines = fd.readlines()
854 pkgconfig_provided[pkg] = []
856 pkgconfig_provided[pkg].append(l.rstrip())
858 for pkg in packages.split():
860 for n in pkgconfig_needed[pkg]:
862 for k in pkgconfig_provided.keys():
863 if n in pkgconfig_provided[k]:
864 if k != pkg and not (k in deps):
868 bb.note("couldn't find pkgconfig module '%s' in any package" % n)
869 deps_file = os.path.join(pkgdest, pkg + ".pcdeps")
870 if os.path.exists(deps_file):
873 fd = open(deps_file, 'w')
877 package_stagefile(deps_file, d)
879 if pstageactive == "1":
880 bb.utils.unlockfile(lf)
883 python read_shlibdeps () {
884 packages = bb.data.getVar('PACKAGES', d, True).split()
886 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
887 for extension in ".shlibdeps", ".pcdeps", ".clilibdeps":
888 depsfile = bb.data.expand("${PKGDEST}/" + pkg + extension, d)
889 if os.access(depsfile, os.R_OK):
891 lines = fd.readlines()
894 rdepends.append(l.rstrip())
895 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
898 python package_depchains() {
900 For a given set of prefix and postfix modifiers, make those packages
901 RRECOMMENDS on the corresponding packages for its RDEPENDS.
903 Example: If package A depends upon package B, and A's .bb emits an
904 A-dev package, this would make A-dev Recommends: B-dev.
906 If only one of a given suffix is specified, it will take the RRECOMMENDS
907 based on the RDEPENDS of *all* other packages. If more than one of a given
908 suffix is specified, its will only use the RDEPENDS of the single parent
912 packages = bb.data.getVar('PACKAGES', d, True)
913 postfixes = (bb.data.getVar('DEPCHAIN_POST', d, True) or '').split()
914 prefixes = (bb.data.getVar('DEPCHAIN_PRE', d, True) or '').split()
916 def pkg_adddeprrecs(pkg, base, suffix, getname, depends, d):
918 #bb.note('depends for %s is %s' % (base, depends))
919 rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, True) or bb.data.getVar('RRECOMMENDS', d, True) or "")
921 for depend in depends:
922 if depend.find('-native') != -1 or depend.find('-cross') != -1 or depend.startswith('virtual/'):
923 #bb.note("Skipping %s" % depend)
925 if depend.endswith('-dev'):
926 depend = depend.replace('-dev', '')
927 if depend.endswith('-dbg'):
928 depend = depend.replace('-dbg', '')
929 pkgname = getname(depend, suffix)
930 #bb.note("Adding %s for %s" % (pkgname, depend))
931 if not pkgname in rreclist:
932 rreclist.append(pkgname)
934 #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
935 bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
937 def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d):
939 #bb.note('rdepends for %s is %s' % (base, rdepends))
940 rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, True) or bb.data.getVar('RRECOMMENDS', d, True) or "")
942 for depend in rdepends:
943 if depend.endswith('-dev'):
944 depend = depend.replace('-dev', '')
945 if depend.endswith('-dbg'):
946 depend = depend.replace('-dbg', '')
947 pkgname = getname(depend, suffix)
948 if not pkgname in rreclist:
949 rreclist.append(pkgname)
951 #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
952 bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
954 def add_dep(list, dep):
955 dep = dep.split(' (')[0].strip()
960 for dep in explode_deps(bb.data.getVar('DEPENDS', d, True) or ""):
961 add_dep(depends, dep)
964 for dep in explode_deps(bb.data.getVar('RDEPENDS', d, True) or ""):
965 add_dep(rdepends, dep)
967 for pkg in packages.split():
968 for dep in explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, True) or ""):
969 add_dep(rdepends, dep)
971 #bb.note('rdepends is %s' % rdepends)
973 def post_getname(name, suffix):
974 return '%s%s' % (name, suffix)
975 def pre_getname(name, suffix):
976 return '%s%s' % (suffix, name)
979 for pkg in packages.split():
980 for postfix in postfixes:
981 if pkg.endswith(postfix):
982 if not postfix in pkgs:
984 pkgs[postfix][pkg] = (pkg[:-len(postfix)], post_getname)
986 for prefix in prefixes:
987 if pkg.startswith(prefix):
988 if not prefix in pkgs:
990 pkgs[prefix][pkg] = (pkg[:-len(prefix)], pre_getname)
993 for pkg in pkgs[suffix]:
994 (base, func) = pkgs[suffix][pkg]
995 if suffix == "-dev" and not pkg.startswith("kernel-module-"):
996 pkg_adddeprrecs(pkg, base, suffix, func, depends, d)
997 if len(pkgs[suffix]) == 1:
998 pkg_addrrecs(pkg, base, suffix, func, rdepends, d)
1001 for dep in explode_deps(bb.data.getVar('RDEPENDS_' + base, d, True) or bb.data.getVar('RDEPENDS', d, True) or ""):
1003 pkg_addrrecs(pkg, base, suffix, func, rdeps, d)
1006 PACKAGE_PREPROCESS_FUNCS ?= ""
1007 PACKAGEFUNCS ?= "perform_packagecopy \
1008 ${PACKAGE_PREPROCESS_FUNCS} \
1009 package_do_split_locales \
1012 package_do_pkgconfig \
1017 def package_run_hooks(f, d):
1019 staging = bb.data.getVar('PKGDATA_DIR', d, True)
1020 dn = os.path.join(staging, 'hooks', f)
1021 if os.access(dn, os.R_OK):
1022 for f in os.listdir(dn):
1023 fn = os.path.join(dn, f)
1026 for l in fp.readlines():
1028 bb.parse.parse_py.BBHandler.feeder(line, l, fn, os.path.basename(fn), d)
1031 anonqueue = bb.data.getVar("__anonqueue", d, True) or []
1032 body = [x['content'] for x in anonqueue]
1033 flag = { 'python' : 1, 'func' : 1 }
1034 bb.data.setVar("__anonfunc", "\n".join(body), d)
1035 bb.data.setVarFlags("__anonfunc", flag, d)
1037 t = bb.data.getVar('T', d)
1038 bb.data.setVar('T', '${TMPDIR}/', d)
1039 bb.build.exec_func("__anonfunc", d)
1040 bb.data.delVar('T', d)
1042 bb.data.setVar('T', t, d)
1043 except Exception, e:
1044 bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e)
1046 bb.data.delVar("__anonqueue", d)
1047 bb.data.delVar("__anonfunc", d)
1049 python package_do_package () {
1050 packages = (bb.data.getVar('PACKAGES', d, True) or "").split()
1051 if len(packages) < 1:
1052 bb.debug(1, "No packages to build, skipping do_package")
1055 workdir = bb.data.getVar('WORKDIR', d, True)
1056 outdir = bb.data.getVar('DEPLOY_DIR', d, True)
1057 dest = bb.data.getVar('D', d, True)
1058 dvar = bb.data.getVar('PKGD', d, True)
1059 pn = bb.data.getVar('PN', d, True)
1061 if not workdir or not outdir or not dest or not dvar or not pn or not packages:
1062 bb.error("WORKDIR, DEPLOY_DIR, D, PN and PKGD all must be defined, unable to package")
1065 for f in (bb.data.getVar('PACKAGEFUNCS', d, True) or '').split():
1066 bb.build.exec_func(f, d)
1067 package_run_hooks(f, d)
1069 do_package[dirs] = "${D}"
1070 addtask package before do_build after do_install
1072 # Dummy task to mark when all packaging is complete
1073 do_package_write () {
1076 addtask package_write before do_build after do_package
1078 EXPORT_FUNCTIONS do_package do_package_write
1081 # Helper functions for the package writing classes
1084 python package_mapping_rename_hook () {
1086 Rewrite variables to account for package renaming in things
1087 like debian.bbclass or manual PKG variable name changes
1089 runtime_mapping_rename("RDEPENDS", d)
1090 runtime_mapping_rename("RRECOMMENDS", d)
1091 runtime_mapping_rename("RSUGGESTS", d)
1092 runtime_mapping_rename("RPROVIDES", d)
1093 runtime_mapping_rename("RREPLACES", d)
1094 runtime_mapping_rename("RCONFLICTS", d)
1097 EXPORT_FUNCTIONS mapping_rename_hook