PKGDEST = "${WORKDIR}/install"
+def build_package_revision(d):
+ import bb
+ file_pr = bb.data.getVar('PR', d, True)
+ distro_pr = bb.data.getVar('DISTRO_PR', d, True) or ""
+ return "%s%s" % (file_pr, distro_pr)
+
+
def legitimize_package_name(s):
"""
Make sure package names are legitimate strings
# Remaining package name validity fixes
return s.lower().replace('_', '-').replace('@', '+').replace(',', '+').replace('/', '-')
-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):
+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):
"""
Used in .bb files to split up dynamically generated subpackages of a
given package, usually plugins or modules.
continue
f = os.path.join(dvar + root, o)
mode = os.lstat(f).st_mode
- if not (stat.S_ISREG(mode) or (allow_dirs and stat.S_ISDIR(mode))):
+ if not (stat.S_ISREG(mode) or (allow_links and stat.S_ISLNK(mode)) or (allow_dirs and stat.S_ISDIR(mode))):
continue
on = legitimize_package_name(m.group(1))
pkg = output_pattern % on
PACKAGE_DEPENDS += "file-native"
+def package_stash_hook(func, name, d):
+ import bb, os.path
+ body = bb.data.getVar(func, d, True)
+ pn = bb.data.getVar('PN', d, True)
+ staging = bb.data.getVar('PKGDATA_DIR', d, True)
+ dirname = os.path.join(staging, 'hooks', name)
+ bb.mkdirhier(dirname)
+ fn = os.path.join(dirname, pn)
+ f = open(fn, 'w')
+ f.write("python () {\n");
+ f.write(body);
+ f.write("}\n");
+ f.close()
+
python () {
import bb
if bb.data.getVar('PACKAGES', d, True) != '':
bb.debug(1, "runstrip: skip %s" % file)
return 0
+ # If the file is in a .debug directory it was already stripped,
+ # don't do it again...
+ if os.path.dirname(file).endswith(".debug"):
+ bb.note("Already ran strip")
+ return 0
+
strip = bb.data.getVar("STRIP", d, 1)
objcopy = bb.data.getVar("OBJCOPY", d, 1)
#bb.data.setVar('RDEPENDS_%s' % mainpkg, ' '.join(rdep), d)
}
-def copyfile(src,dest,newmtime=None,sstat=None):
- """
- Copies a file from src to dest, preserving all permissions and
- attributes; mtime will be preserved even when moving across
- filesystems. Returns true on success and false on failure.
- """
- import os, stat, shutil, commands
-
- #print "copyfile("+src+","+dest+","+str(newmtime)+","+str(sstat)+")"
- try:
- if not sstat:
- sstat=os.lstat(src)
- except Exception, e:
- print "copyfile: Stating source file failed...", e
- return False
-
- destexists=1
- try:
- dstat=os.lstat(dest)
- except:
- dstat=os.lstat(os.path.dirname(dest))
- destexists=0
-
- if destexists:
- if stat.S_ISLNK(dstat[stat.ST_MODE]):
- try:
- os.unlink(dest)
- destexists=0
- except Exception, e:
- pass
-
- if stat.S_ISLNK(sstat[stat.ST_MODE]):
- try:
- target=os.readlink(src)
- if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]):
- os.unlink(dest)
- os.symlink(target,dest)
- #os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
- return os.lstat(dest)
- except Exception, e:
- print "copyfile: failed to properly create symlink:", dest, "->", target, e
- return False
-
- if stat.S_ISREG(sstat[stat.ST_MODE]):
- try: # For safety copy then move it over.
- shutil.copyfile(src,dest+"#new")
- os.rename(dest+"#new",dest)
- except Exception, e:
- print 'copyfile: copy', src, '->', dest, 'failed.', e
- return False
- else:
- #we don't yet handle special, so we need to fall back to /bin/mv
- a=commands.getstatusoutput("/bin/cp -f "+"'"+src+"' '"+dest+"'")
- if a[0]!=0:
- print "copyfile: Failed to copy special file:" + src + "' to '" + dest + "'", a
- return False # failure
- try:
- os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
- os.chmod(dest, stat.S_IMODE(sstat[stat.ST_MODE])) # Sticky is reset on chown
- except Exception, e:
- print "copyfile: Failed to chown/chmod/unlink", dest, e
- return False
-
- if newmtime:
- os.utime(dest,(newmtime,newmtime))
- else:
- os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME]))
- newmtime=sstat[stat.ST_MTIME]
- return newmtime
-
python populate_packages () {
import glob, stat, errno, re
os.system('rm -rf %s' % pkgdest)
seen = []
+ main_is_empty = 1
+ main_pkg = bb.data.getVar('PN', d, 1)
for pkg in package_list:
localdata = bb.data.createCopy(d)
continue
if (not os.path.islink(file)) and (not os.path.exists(file)):
continue
+ if file[-4:] == '.pyo':
+ continue
if file in seen:
continue
seen.append(file)
fpath = os.path.join(root,file)
dpath = os.path.dirname(fpath)
bb.mkdirhier(dpath)
- ret = copyfile(file, fpath)
+ ret = bb.copyfile(file, fpath)
if ret is False or ret == 0:
raise bb.build.FuncFailed("File population failed")
+ if pkg == main_pkg and main_is_empty:
+ main_is_empty = 0
del localdata
os.chdir(workdir)
dangling_links[pkg].append(os.path.normpath(target))
for pkg in package_list:
- rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 1) or bb.data.getVar('RDEPENDS', d, 1) or "")
+ rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
+
+ remstr = "${PN} (= ${DEBPV})"
+ if main_is_empty and remstr in rdepends:
+ rdepends.remove(remstr)
for l in dangling_links[pkg]:
found = False
bb.debug(1, "%s contains dangling link %s" % (pkg, l))
if val:
f.write('%s_%s: %s\n' % (var, pkg, encode(val)))
- packages = bb.data.getVar('PACKAGES', d, 1)
+ packages = bb.data.getVar('PACKAGES', d, True)
+ pkgdatadir = bb.data.getVar('PKGDATA_DIR', d, True)
+
+ pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
+ if pstageactive == "1":
+ lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
- data_file = bb.data.expand("${PKGDATA_DIR}/${PN}", d)
+ data_file = pkgdatadir + bb.data.expand("/${PN}" , d)
f = open(data_file, 'w')
f.write("PACKAGES: %s\n" % packages)
f.close()
+ package_stagefile(data_file, d)
workdir = bb.data.getVar('WORKDIR', d, 1)
for pkg in packages.split():
- subdata_file = bb.data.expand("${PKGDATA_DIR}/runtime/%s" % pkg, d)
+ subdata_file = pkgdatadir + "/runtime/%s" % pkg
sf = open(subdata_file, 'w')
+ write_if_exists(sf, pkg, 'PN')
+ write_if_exists(sf, pkg, 'PR')
write_if_exists(sf, pkg, 'DESCRIPTION')
write_if_exists(sf, pkg, 'RDEPENDS')
write_if_exists(sf, pkg, 'RPROVIDES')
write_if_exists(sf, pkg, 'RRECOMMENDS')
write_if_exists(sf, pkg, 'RSUGGESTS')
- write_if_exists(sf, pkg, 'RPROVIDES')
write_if_exists(sf, pkg, 'RREPLACES')
write_if_exists(sf, pkg, 'RCONFLICTS')
write_if_exists(sf, pkg, 'PKG')
write_if_exists(sf, pkg, 'pkg_prerm')
sf.close()
+ package_stagefile(subdata_file, d)
+ #if pkgdatadir2:
+ # bb.copyfile(subdata_file, pkgdatadir2 + "/runtime/%s" % pkg)
+
allow_empty = bb.data.getVar('ALLOW_EMPTY_%s' % pkg, d, 1)
if not allow_empty:
allow_empty = bb.data.getVar('ALLOW_EMPTY', d, 1)
os.chdir(root)
g = glob('*')
if g or allow_empty == "1":
- file(bb.data.expand('${PKGDATA_DIR}/runtime/%s.packaged' % pkg, d), 'w').close()
+ packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg
+ file(packagedfile, 'w').close()
+ package_stagefile(packagedfile, d)
+ if pstageactive == "1":
+ bb.utils.unlockfile(lf)
}
emit_pkgdata[dirs] = "${PKGDATA_DIR}/runtime"
ldconfig_postinst_fragment() {
if [ x"$D" = "x" ]; then
- ldconfig
+ [ -x /sbin/ldconfig ] && /sbin/ldconfig
fi
}
+SHLIBSDIR = "${STAGING_DIR_HOST}/shlibs"
+
python package_do_shlibs() {
import os, re, os.path
bb.error("WORKDIR not defined")
return
- staging = bb.data.getVar('STAGING_DIR', d, 1)
- if not staging:
- bb.error("STAGING_DIR not defined")
- return
-
ver = bb.data.getVar('PV', d, 1)
if not ver:
bb.error("PV not defined")
return
- target_sys = bb.data.getVar('TARGET_SYS', d, 1)
- if not target_sys:
- bb.error("TARGET_SYS not defined")
- return
-
pkgdest = bb.data.getVar('PKGDEST', d, 1)
- shlibs_dir = os.path.join(staging, target_sys, "shlibs")
- old_shlibs_dir = os.path.join(staging, "shlibs")
+ shlibs_dir = bb.data.getVar('SHLIBSDIR', d, 1)
bb.mkdirhier(shlibs_dir)
+ pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
+ if pstageactive == "1":
+ lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
+
+ if bb.data.getVar('PACKAGE_SNAP_LIB_SYMLINKS', d, True) == "1":
+ snap_symlinks = True
+ else:
+ snap_symlinks = False
+
+ if (bb.data.getVar('USE_LDCONFIG', d, True) or "1") == "1":
+ use_ldconfig = True
+ else:
+ use_ldconfig = False
+
needed = {}
private_libs = bb.data.getVar('PRIVATE_LIBS', d, 1)
for pkg in packages.split():
needed[pkg] = []
sonames = list()
top = os.path.join(pkgdest, pkg)
+ renames = []
for root, dirs, files in os.walk(top):
for file in files:
soname = None
if m:
needed[pkg].append(m.group(1))
m = re.match("\s+SONAME\s+([^\s]*)", l)
- if m and not m.group(1) in sonames:
- # if library is private (only used by package) then do not build shlib for it
- if not private_libs or -1 == private_libs.find(m.group(1)):
- sonames.append(m.group(1))
- if m and libdir_re.match(root):
- needs_ldconfig = True
+ if m:
+ this_soname = m.group(1)
+ if not this_soname in sonames:
+ # if library is private (only used by package) then do not build shlib for it
+ if not private_libs or -1 == private_libs.find(this_soname):
+ sonames.append(this_soname)
+ if libdir_re.match(root):
+ needs_ldconfig = True
+ if snap_symlinks and (file != soname):
+ renames.append((path, os.path.join(root, this_soname)))
+ for (old, new) in renames:
+ os.rename(old, new)
shlibs_file = os.path.join(shlibs_dir, pkg + ".list")
if os.path.exists(shlibs_file):
os.remove(shlibs_file)
for s in sonames:
fd.write(s + '\n')
fd.close()
+ package_stagefile(shlibs_file, d)
fd = open(shver_file, 'w')
fd.write(ver + '\n')
fd.close()
- if needs_ldconfig:
+ package_stagefile(shver_file, d)
+ if needs_ldconfig and use_ldconfig:
bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg)
postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1)
if not postinst:
postinst += bb.data.getVar('ldconfig_postinst_fragment', d, 1)
bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
+ if pstageactive == "1":
+ bb.utils.unlockfile(lf)
+
shlib_provider = {}
list_re = re.compile('^(.*)\.list$')
- for dir in [old_shlibs_dir, shlibs_dir]:
+ for dir in [shlibs_dir]:
if not os.path.exists(dir):
continue
for file in os.listdir(dir):
dep_pkg = dep_pkg[0]
shlib_provider[l] = (dep_pkg, lib_ver)
+ dep_packages = []
for pkg in packages.split():
bb.debug(2, "calculating shlib requirements for %s" % pkg)
dep = dep_pkg
if not dep in deps:
deps.append(dep)
+ if not dep_pkg in dep_packages:
+ dep_packages.append(dep_pkg)
+
else:
bb.note("Couldn't find shared library provider for %s" % n)
bb.error("WORKDIR not defined")
return
- staging = bb.data.getVar('STAGING_DIR', d, 1)
- if not staging:
- bb.error("STAGING_DIR not defined")
- return
-
- target_sys = bb.data.getVar('TARGET_SYS', d, 1)
- if not target_sys:
- bb.error("TARGET_SYS not defined")
- return
-
pkgdest = bb.data.getVar('PKGDEST', d, 1)
- shlibs_dir = os.path.join(staging, target_sys, "shlibs")
- old_shlibs_dir = os.path.join(staging, "shlibs")
+ shlibs_dir = bb.data.getVar('SHLIBSDIR', d, 1)
bb.mkdirhier(shlibs_dir)
pc_re = re.compile('(.*)\.pc$')
if hdr == 'Requires':
pkgconfig_needed[pkg] += exp.replace(',', ' ').split()
+ pstageactive = bb.data.getVar('PSTAGING_ACTIVE', d, True)
+ if pstageactive == "1":
+ lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
+
for pkg in packages.split():
pkgs_file = os.path.join(shlibs_dir, pkg + ".pclist")
if os.path.exists(pkgs_file):
for p in pkgconfig_provided[pkg]:
f.write('%s\n' % p)
f.close()
+ package_stagefile(pkgs_file, d)
- for dir in [old_shlibs_dir, shlibs_dir]:
+ for dir in [shlibs_dir]:
if not os.path.exists(dir):
continue
for file in os.listdir(dir):
for dep in deps:
fd.write(dep + '\n')
fd.close()
+ package_stagefile(deps_file, d)
+
+ if pstageactive == "1":
+ bb.utils.unlockfile(lf)
}
python read_shlibdeps () {
postfixes = (bb.data.getVar('DEPCHAIN_POST', d, 1) or '').split()
prefixes = (bb.data.getVar('DEPCHAIN_PRE', d, 1) or '').split()
+ def pkg_adddeprrecs(pkg, base, suffix, getname, depends, d):
+
+ #bb.note('depends for %s is %s' % (base, depends))
+ rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, 1) or bb.data.getVar('RRECOMMENDS', d, 1) or "")
+
+ for depend in depends:
+ if depend.find('-native') != -1 or depend.find('-cross') != -1 or depend.startswith('virtual/'):
+ #bb.note("Skipping %s" % depend)
+ continue
+ if depend.endswith('-dev'):
+ depend = depend.replace('-dev', '')
+ if depend.endswith('-dbg'):
+ depend = depend.replace('-dbg', '')
+ pkgname = getname(depend, suffix)
+ #bb.note("Adding %s for %s" % (pkgname, depend))
+ if not pkgname in rreclist:
+ rreclist.append(pkgname)
+
+ #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
+ bb.data.setVar('RRECOMMENDS_%s' % pkg, ' '.join(rreclist), d)
+
def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d):
- #bb.note('rdepends for %s is %s' % (base, rdepends))
+ #bb.note('rdepends for %s is %s' % (base, rdepends))
rreclist = explode_deps(bb.data.getVar('RRECOMMENDS_' + pkg, d, 1) or bb.data.getVar('RRECOMMENDS', d, 1) or "")
for depend in rdepends:
+ if depend.endswith('-dev'):
+ depend = depend.replace('-dev', '')
+ if depend.endswith('-dbg'):
+ depend = depend.replace('-dbg', '')
pkgname = getname(depend, suffix)
- if not pkgname in rreclist and packaged(pkgname, d):
+ if not pkgname in rreclist:
rreclist.append(pkgname)
#bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
if dep not in list:
list.append(dep)
+ depends = []
+ for dep in explode_deps(bb.data.getVar('DEPENDS', d, 1) or ""):
+ add_dep(depends, dep)
+
rdepends = []
for dep in explode_deps(bb.data.getVar('RDEPENDS', d, 1) or ""):
add_dep(rdepends, dep)
for suffix in pkgs:
for pkg in pkgs[suffix]:
(base, func) = pkgs[suffix][pkg]
+ if suffix == "-dev" and not pkg.startswith("kernel-module-"):
+ pkg_adddeprrecs(pkg, base, suffix, func, depends, d)
if len(pkgs[suffix]) == 1:
pkg_addrrecs(pkg, base, suffix, func, rdepends, d)
else:
package_depchains \
emit_pkgdata"
+def package_run_hooks(f, d):
+ import bb, os
+ staging = bb.data.getVar('PKGDATA_DIR', d, True)
+ dn = os.path.join(staging, 'hooks', f)
+ if os.access(dn, os.R_OK):
+ for f in os.listdir(dn):
+ fn = os.path.join(dn, f)
+ fp = open(fn, 'r')
+ line = 0
+ for l in fp.readlines():
+ l = l.rstrip()
+ bb.parse.parse_py.BBHandler.feeder(line, l, fn, os.path.basename(fn), d)
+ line += 1
+ fp.close()
+ anonqueue = bb.data.getVar("__anonqueue", d, 1) or []
+ body = [x['content'] for x in anonqueue]
+ flag = { 'python' : 1, 'func' : 1 }
+ bb.data.setVar("__anonfunc", "\n".join(body), d)
+ bb.data.setVarFlags("__anonfunc", flag, d)
+ try:
+ t = bb.data.getVar('T', d)
+ bb.data.setVar('T', '${TMPDIR}/', d)
+ bb.build.exec_func("__anonfunc", d)
+ bb.data.delVar('T', d)
+ if t:
+ bb.data.setVar('T', t, d)
+ except Exception, e:
+ bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e)
+ raise
+ bb.data.delVar("__anonqueue", d)
+ bb.data.delVar("__anonfunc", d)
+
python package_do_package () {
packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
if len(packages) < 1:
for f in (bb.data.getVar('PACKAGEFUNCS', d, 1) or '').split():
bb.build.exec_func(f, d)
+ package_run_hooks(f, d)
}
do_package[dirs] = "${D}"
addtask package before do_build after do_install