2007-08-07 14:34:33 +00:00
|
|
|
#
|
2008-05-20 14:58:34 +00:00
|
|
|
# Copyright 2006-2008 OpenedHand Ltd.
|
2007-08-07 14:34:33 +00:00
|
|
|
#
|
|
|
|
|
2006-09-19 09:04:09 +00:00
|
|
|
inherit package
|
2007-04-03 11:31:02 +00:00
|
|
|
|
2006-09-19 09:04:09 +00:00
|
|
|
IMAGE_PKGTYPE ?= "deb"
|
|
|
|
|
2007-09-27 20:26:26 +00:00
|
|
|
# Map TARGET_ARCH to Debian's ideas about architectures
|
|
|
|
DPKG_ARCH ?= "${TARGET_ARCH}"
|
|
|
|
DPKG_ARCH_x86 ?= "i386"
|
|
|
|
DPKG_ARCH_i486 ?= "i386"
|
|
|
|
DPKG_ARCH_i586 ?= "i386"
|
|
|
|
DPKG_ARCH_i686 ?= "i386"
|
|
|
|
DPKG_ARCH_pentium ?= "i386"
|
|
|
|
|
2006-09-19 09:04:09 +00:00
|
|
|
python package_deb_fn () {
|
|
|
|
bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
|
|
|
|
}
|
|
|
|
|
|
|
|
addtask package_deb_install
|
|
|
|
python do_package_deb_install () {
|
2010-07-01 23:05:38 +00:00
|
|
|
pkg = bb.data.getVar('PKG', d, True)
|
|
|
|
pkgfn = bb.data.getVar('PKGFN', d, True)
|
|
|
|
rootfs = bb.data.getVar('IMAGE_ROOTFS', d, True)
|
|
|
|
debdir = bb.data.getVar('DEPLOY_DIR_DEB', d, True)
|
2007-11-12 11:11:48 +00:00
|
|
|
apt_config = bb.data.expand('${STAGING_ETCDIR_NATIVE}/apt/apt.conf', d)
|
2010-07-01 23:05:38 +00:00
|
|
|
stagingbindir = bb.data.getVar('STAGING_BINDIR_NATIVE', d, True)
|
|
|
|
tmpdir = bb.data.getVar('TMPDIR', d, True)
|
2006-09-19 09:04:09 +00:00
|
|
|
|
|
|
|
if None in (pkg,pkgfn,rootfs):
|
|
|
|
raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGE_ROOTFS)")
|
|
|
|
try:
|
|
|
|
if not os.exists(rootfs):
|
|
|
|
os.makedirs(rootfs)
|
|
|
|
os.chdir(rootfs)
|
|
|
|
except OSError:
|
2009-11-08 22:32:43 +00:00
|
|
|
import sys
|
2006-09-19 09:04:09 +00:00
|
|
|
raise bb.build.FuncFailed(str(sys.exc_value))
|
|
|
|
|
|
|
|
# update packages file
|
|
|
|
(exitstatus, output) = commands.getstatusoutput('dpkg-scanpackages %s > %s/Packages' % (debdir, debdir))
|
|
|
|
if (exitstatus != 0 ):
|
|
|
|
raise bb.build.FuncFailed(output)
|
|
|
|
|
2007-09-27 11:48:36 +00:00
|
|
|
f = open(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"), "w")
|
2006-09-19 09:04:09 +00:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
# NOTE: this env stuff is racy at best, we need something more capable
|
|
|
|
# than 'commands' for command execution, which includes manipulating the
|
|
|
|
# env of the fork+execve'd processs
|
|
|
|
|
|
|
|
# Set up environment
|
2007-11-12 11:11:48 +00:00
|
|
|
apt_config_backup = os.getenv('APT_CONFIG')
|
|
|
|
os.putenv('APT_CONFIG', apt_config)
|
2006-09-19 09:04:09 +00:00
|
|
|
path = os.getenv('PATH')
|
|
|
|
os.putenv('PATH', '%s:%s' % (stagingbindir, os.getenv('PATH')))
|
|
|
|
|
|
|
|
# install package
|
|
|
|
commands.getstatusoutput('apt-get update')
|
|
|
|
commands.getstatusoutput('apt-get install -y %s' % pkgfn)
|
|
|
|
|
|
|
|
# revert environment
|
2007-11-12 11:11:48 +00:00
|
|
|
os.putenv('APT_CONFIG', apt_config_backup)
|
2006-09-19 09:04:09 +00:00
|
|
|
os.putenv('PATH', path)
|
|
|
|
}
|
|
|
|
|
|
|
|
python do_package_deb () {
|
2009-11-08 22:32:43 +00:00
|
|
|
import re, copy
|
2006-09-19 09:04:09 +00:00
|
|
|
|
2010-07-01 23:05:38 +00:00
|
|
|
workdir = bb.data.getVar('WORKDIR', d, True)
|
2006-09-19 09:04:09 +00:00
|
|
|
if not workdir:
|
|
|
|
bb.error("WORKDIR not defined, unable to package")
|
|
|
|
return
|
|
|
|
|
2010-07-01 23:05:38 +00:00
|
|
|
outdir = bb.data.getVar('DEPLOY_DIR_DEB', d, True)
|
2006-09-19 09:04:09 +00:00
|
|
|
if not outdir:
|
|
|
|
bb.error("DEPLOY_DIR_DEB not defined, unable to package")
|
|
|
|
return
|
|
|
|
|
2010-07-01 23:05:38 +00:00
|
|
|
dvar = bb.data.getVar('D', d, True)
|
2006-09-19 09:04:09 +00:00
|
|
|
if not dvar:
|
|
|
|
bb.error("D not defined, unable to package")
|
|
|
|
return
|
|
|
|
bb.mkdirhier(dvar)
|
|
|
|
|
2010-07-01 23:05:38 +00:00
|
|
|
packages = bb.data.getVar('PACKAGES', d, True)
|
2006-09-19 09:04:09 +00:00
|
|
|
if not packages:
|
|
|
|
bb.debug(1, "PACKAGES not defined, nothing to package")
|
|
|
|
return
|
|
|
|
|
2010-07-01 23:05:38 +00:00
|
|
|
tmpdir = bb.data.getVar('TMPDIR', d, True)
|
2007-09-27 11:48:36 +00:00
|
|
|
|
|
|
|
if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK):
|
|
|
|
os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"))
|
2006-09-19 09:04:09 +00:00
|
|
|
|
|
|
|
if packages == []:
|
|
|
|
bb.debug(1, "No packages; nothing to do")
|
|
|
|
return
|
|
|
|
|
|
|
|
for pkg in packages.split():
|
|
|
|
localdata = bb.data.createCopy(d)
|
2010-07-01 23:05:38 +00:00
|
|
|
pkgdest = bb.data.getVar('PKGDEST', d, True)
|
2007-11-24 23:05:05 +00:00
|
|
|
root = "%s/%s" % (pkgdest, pkg)
|
2006-09-19 09:04:09 +00:00
|
|
|
|
2007-11-24 14:55:57 +00:00
|
|
|
lf = bb.utils.lockfile(root + ".lock")
|
2007-08-24 16:50:56 +00:00
|
|
|
|
2006-09-19 09:04:09 +00:00
|
|
|
bb.data.setVar('ROOT', '', localdata)
|
|
|
|
bb.data.setVar('ROOT_%s' % pkg, root, localdata)
|
2010-07-01 23:05:38 +00:00
|
|
|
pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, True)
|
2006-09-19 09:04:09 +00:00
|
|
|
if not pkgname:
|
|
|
|
pkgname = pkg
|
|
|
|
bb.data.setVar('PKG', pkgname, localdata)
|
|
|
|
|
2010-07-07 11:53:46 +00:00
|
|
|
bb.data.setVar('OVERRIDES', pkg, localdata)
|
2006-09-19 09:04:09 +00:00
|
|
|
|
|
|
|
bb.data.update_data(localdata)
|
|
|
|
basedir = os.path.join(os.path.dirname(root))
|
|
|
|
|
2010-07-01 23:05:38 +00:00
|
|
|
pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, True))
|
2006-09-19 09:04:09 +00:00
|
|
|
bb.mkdirhier(pkgoutdir)
|
|
|
|
|
|
|
|
os.chdir(root)
|
|
|
|
from glob import glob
|
|
|
|
g = glob('*')
|
|
|
|
try:
|
|
|
|
del g[g.index('DEBIAN')]
|
|
|
|
del g[g.index('./DEBIAN')]
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2007-09-01 23:49:12 +00:00
|
|
|
if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
|
2010-07-01 23:05:38 +00:00
|
|
|
bb.note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, True), bb.data.getVar('PR', localdata, True)))
|
2007-11-24 14:55:57 +00:00
|
|
|
bb.utils.unlockfile(lf)
|
2006-09-19 09:04:09 +00:00
|
|
|
continue
|
2007-09-27 11:48:36 +00:00
|
|
|
|
2006-09-19 09:04:09 +00:00
|
|
|
controldir = os.path.join(root, 'DEBIAN')
|
|
|
|
bb.mkdirhier(controldir)
|
2007-03-31 14:04:49 +00:00
|
|
|
os.chmod(controldir, 0755)
|
2006-09-19 09:04:09 +00:00
|
|
|
try:
|
|
|
|
ctrlfile = file(os.path.join(controldir, 'control'), 'wb')
|
|
|
|
# import codecs
|
|
|
|
# ctrlfile = codecs.open("someFile", "w", "utf-8")
|
|
|
|
except OSError:
|
2007-11-24 14:55:57 +00:00
|
|
|
bb.utils.unlockfile(lf)
|
2006-09-19 09:04:09 +00:00
|
|
|
raise bb.build.FuncFailed("unable to open control file for writing.")
|
|
|
|
|
|
|
|
fields = []
|
2010-07-01 23:05:38 +00:00
|
|
|
pe = bb.data.getVar('PE', d, True)
|
2007-05-31 22:51:19 +00:00
|
|
|
if pe and int(pe) > 0:
|
|
|
|
fields.append(["Version: %s:%s-%s\n", ['PE', 'PV', 'PR']])
|
|
|
|
else:
|
|
|
|
fields.append(["Version: %s-%s\n", ['PV', 'PR']])
|
2006-09-19 09:04:09 +00:00
|
|
|
fields.append(["Description: %s\n", ['DESCRIPTION']])
|
|
|
|
fields.append(["Section: %s\n", ['SECTION']])
|
|
|
|
fields.append(["Priority: %s\n", ['PRIORITY']])
|
|
|
|
fields.append(["Maintainer: %s\n", ['MAINTAINER']])
|
2007-09-27 20:26:26 +00:00
|
|
|
fields.append(["Architecture: %s\n", ['DPKG_ARCH']])
|
2007-05-31 22:51:19 +00:00
|
|
|
fields.append(["OE: %s\n", ['PN']])
|
2006-09-19 09:04:09 +00:00
|
|
|
fields.append(["Homepage: %s\n", ['HOMEPAGE']])
|
|
|
|
|
|
|
|
# Package, Version, Maintainer, Description - mandatory
|
|
|
|
# Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional
|
|
|
|
|
|
|
|
|
|
|
|
def pullData(l, d):
|
|
|
|
l2 = []
|
|
|
|
for i in l:
|
2010-07-01 23:05:38 +00:00
|
|
|
data = bb.data.getVar(i, d, True)
|
2006-11-24 17:23:05 +00:00
|
|
|
if data is None:
|
|
|
|
raise KeyError(f)
|
2010-07-01 23:05:38 +00:00
|
|
|
if i == 'DPKG_ARCH' and bb.data.getVar('PACKAGE_ARCH', d, True) == 'all':
|
2006-11-24 17:23:05 +00:00
|
|
|
data = 'all'
|
|
|
|
l2.append(data)
|
2006-09-19 09:04:09 +00:00
|
|
|
return l2
|
|
|
|
|
|
|
|
ctrlfile.write("Package: %s\n" % pkgname)
|
|
|
|
# check for required fields
|
|
|
|
try:
|
|
|
|
for (c, fs) in fields:
|
|
|
|
ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
|
|
|
|
except KeyError:
|
2009-11-08 22:32:43 +00:00
|
|
|
import sys
|
2006-09-19 09:04:09 +00:00
|
|
|
(type, value, traceback) = sys.exc_info()
|
2007-11-24 14:55:57 +00:00
|
|
|
bb.utils.unlockfile(lf)
|
2006-09-19 09:04:09 +00:00
|
|
|
ctrlfile.close()
|
|
|
|
raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
|
|
|
|
# more fields
|
|
|
|
|
|
|
|
bb.build.exec_func("mapping_rename_hook", localdata)
|
|
|
|
|
2010-07-01 23:05:38 +00:00
|
|
|
rdepends = bb.utils.explode_dep_versions(bb.data.getVar("RDEPENDS", localdata, True) or "")
|
|
|
|
for dep in rdepends:
|
|
|
|
if '*' in dep:
|
|
|
|
del rdepends[dep]
|
|
|
|
rrecommends = bb.utils.explode_dep_versions(bb.data.getVar("RRECOMMENDS", localdata, True) or "")
|
|
|
|
for dep in rrecommends:
|
|
|
|
if '*' in dep:
|
|
|
|
del rrecommends[dep]
|
|
|
|
rsuggests = bb.utils.explode_dep_versions(bb.data.getVar("RSUGGESTS", localdata, True) or "")
|
|
|
|
rprovides = bb.utils.explode_dep_versions(bb.data.getVar("RPROVIDES", localdata, True) or "")
|
|
|
|
rreplaces = bb.utils.explode_dep_versions(bb.data.getVar("RREPLACES", localdata, True) or "")
|
|
|
|
rconflicts = bb.utils.explode_dep_versions(bb.data.getVar("RCONFLICTS", localdata, True) or "")
|
2006-09-19 09:04:09 +00:00
|
|
|
if rdepends:
|
2010-07-01 23:05:38 +00:00
|
|
|
ctrlfile.write("Depends: %s\n" % unicode(bb.utils.join_deps(rdepends)))
|
2006-09-19 09:04:09 +00:00
|
|
|
if rsuggests:
|
2010-07-01 23:05:38 +00:00
|
|
|
ctrlfile.write("Suggests: %s\n" % unicode(bb.utils.join_deps(rsuggests)))
|
2006-09-19 09:04:09 +00:00
|
|
|
if rrecommends:
|
2010-07-01 23:05:38 +00:00
|
|
|
ctrlfile.write("Recommends: %s\n" % unicode(bb.utils.join_deps(rrecommends)))
|
2006-09-19 09:04:09 +00:00
|
|
|
if rprovides:
|
2010-07-01 23:05:38 +00:00
|
|
|
ctrlfile.write("Provides: %s\n" % unicode(bb.utils.join_deps(rprovides)))
|
2006-09-19 09:04:09 +00:00
|
|
|
if rreplaces:
|
2010-07-01 23:05:38 +00:00
|
|
|
ctrlfile.write("Replaces: %s\n" % unicode(bb.utils.join_deps(rreplaces)))
|
2006-09-19 09:04:09 +00:00
|
|
|
if rconflicts:
|
2010-07-01 23:05:38 +00:00
|
|
|
ctrlfile.write("Conflicts: %s\n" % unicode(bb.utils.join_deps(rconflicts)))
|
2006-09-19 09:04:09 +00:00
|
|
|
ctrlfile.close()
|
|
|
|
|
|
|
|
for script in ["preinst", "postinst", "prerm", "postrm"]:
|
2010-07-01 23:05:38 +00:00
|
|
|
scriptvar = bb.data.getVar('pkg_%s' % script, localdata, True)
|
2006-09-19 09:04:09 +00:00
|
|
|
if not scriptvar:
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
scriptfile = file(os.path.join(controldir, script), 'w')
|
|
|
|
except OSError:
|
2007-11-24 14:55:57 +00:00
|
|
|
bb.utils.unlockfile(lf)
|
2006-09-19 09:04:09 +00:00
|
|
|
raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
|
2007-08-07 14:34:33 +00:00
|
|
|
scriptfile.write("#!/bin/sh\n")
|
2006-09-19 09:04:09 +00:00
|
|
|
scriptfile.write(scriptvar)
|
|
|
|
scriptfile.close()
|
|
|
|
os.chmod(os.path.join(controldir, script), 0755)
|
|
|
|
|
2010-07-01 23:05:38 +00:00
|
|
|
conffiles_str = bb.data.getVar("CONFFILES", localdata, True)
|
2006-09-19 09:04:09 +00:00
|
|
|
if conffiles_str:
|
|
|
|
try:
|
|
|
|
conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
|
|
|
|
except OSError:
|
2007-11-24 14:55:57 +00:00
|
|
|
bb.utils.unlockfile(lf)
|
2006-09-19 09:04:09 +00:00
|
|
|
raise bb.build.FuncFailed("unable to open conffiles for writing.")
|
|
|
|
for f in conffiles_str.split():
|
|
|
|
conffiles.write('%s\n' % f)
|
|
|
|
conffiles.close()
|
|
|
|
|
|
|
|
os.chdir(basedir)
|
2010-06-23 14:19:06 +00:00
|
|
|
ret = os.system("PATH=\"%s\" %s dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, True), bb.data.getVar("FAKEROOT", localdata, True) or "fakeroot", root, pkgoutdir))
|
2006-09-19 09:04:09 +00:00
|
|
|
if ret != 0:
|
2010-07-22 17:26:07 +00:00
|
|
|
bb.utils.prunedir(controldir)
|
2007-11-24 14:55:57 +00:00
|
|
|
bb.utils.unlockfile(lf)
|
2006-09-19 09:04:09 +00:00
|
|
|
raise bb.build.FuncFailed("dpkg-deb execution failed")
|
|
|
|
|
2008-08-18 07:58:39 +00:00
|
|
|
bb.utils.prunedir(controldir)
|
2007-11-24 14:55:57 +00:00
|
|
|
bb.utils.unlockfile(lf)
|
2006-09-19 09:04:09 +00:00
|
|
|
}
|
2007-08-21 09:37:30 +00:00
|
|
|
|
|
|
|
python () {
|
|
|
|
if bb.data.getVar('PACKAGES', d, True) != '':
|
2007-11-28 20:01:41 +00:00
|
|
|
deps = (bb.data.getVarFlag('do_package_write_deb', 'depends', d) or "").split()
|
2009-11-10 14:55:23 +00:00
|
|
|
deps.append('dpkg-native:do_populate_sysroot')
|
2010-06-23 14:19:06 +00:00
|
|
|
deps.append('virtual/fakeroot-native:do_populate_sysroot')
|
2007-11-28 20:01:41 +00:00
|
|
|
bb.data.setVarFlag('do_package_write_deb', 'depends', " ".join(deps), d)
|
2007-08-21 09:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
python do_package_write_deb () {
|
|
|
|
bb.build.exec_func("read_subpackage_metadata", d)
|
|
|
|
bb.build.exec_func("do_package_deb", d)
|
|
|
|
}
|
|
|
|
do_package_write_deb[dirs] = "${D}"
|
2007-08-21 22:39:57 +00:00
|
|
|
addtask package_write_deb before do_package_write after do_package
|
2007-08-21 09:37:30 +00:00
|
|
|
|