2 # Copyright 2006-2008 OpenedHand Ltd.
7 BOOTSTRAP_EXTRA_RDEPENDS += "apt"
8 DISTRO_EXTRA_RDEPENDS += "apt"
11 # Map TARGET_ARCH to Debian's ideas about architectures
12 DPKG_ARCH ?= "${TARGET_ARCH}"
13 DPKG_ARCH_x86 ?= "i386"
14 DPKG_ARCH_i486 ?= "i386"
15 DPKG_ARCH_i586 ?= "i386"
16 DPKG_ARCH_i686 ?= "i386"
17 DPKG_ARCH_pentium ?= "i386"
18 DPKG_ARCH_linux-gnueabi ?= "armel"
19 DPKG_ARCH_linux-uclibceabi ?= "armel"
21 python package_deb_fn () {
22 bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
25 addtask package_deb_install
26 python do_package_deb_install () {
27 pkg = bb.data.getVar('PKG', d, 1)
28 pkgfn = bb.data.getVar('PKGFN', d, 1)
29 rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
30 debdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
31 apt_config = bb.data.expand('${STAGING_ETCDIR_NATIVE}/apt/apt.conf', d)
32 stagingbindir = bb.data.getVar('STAGING_BINDIR_NATIVE', d, 1)
33 tmpdir = bb.data.getVar('TMPDIR', d, 1)
35 if None in (pkg,pkgfn,rootfs):
36 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGE_ROOTFS)")
38 if not os.exists(rootfs):
43 raise bb.build.FuncFailed(str(sys.exc_value))
45 # update packages file
46 (exitstatus, output) = commands.getstatusoutput('dpkg-scanpackages %s > %s/Packages' % (debdir, debdir))
47 if (exitstatus != 0 ):
48 raise bb.build.FuncFailed(output)
50 f = open(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"), "w")
53 # NOTE: this env stuff is racy at best, we need something more capable
54 # than 'commands' for command execution, which includes manipulating the
55 # env of the fork+execve'd processs
58 apt_config_backup = os.getenv('APT_CONFIG')
59 os.putenv('APT_CONFIG', apt_config)
60 path = os.getenv('PATH')
61 os.putenv('PATH', '%s:%s' % (stagingbindir, os.getenv('PATH')))
64 commands.getstatusoutput('apt-get update')
65 commands.getstatusoutput('apt-get install -y %s' % pkgfn)
68 os.putenv('APT_CONFIG', apt_config_backup)
69 os.putenv('PATH', path)
72 python do_package_deb () {
75 workdir = bb.data.getVar('WORKDIR', d, 1)
77 bb.error("WORKDIR not defined, unable to package")
80 outdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
82 bb.error("DEPLOY_DIR_DEB not defined, unable to package")
85 dvar = bb.data.getVar('D', d, 1)
87 bb.error("D not defined, unable to package")
91 tmpdir = bb.data.getVar('TMPDIR', d, 1)
93 if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK):
94 os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"))
96 packages = bb.data.getVar('PACKAGES', d, 1)
97 for pkg in packages.split():
98 localdata = bb.data.createCopy(d)
99 pkgdest = bb.data.getVar('PKGDEST', d, 1)
100 root = "%s/%s" % (pkgdest, pkg)
102 lf = bb.utils.lockfile(root + ".lock")
104 bb.data.setVar('ROOT', '', localdata)
105 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
106 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
109 bb.data.setVar('PKG', pkgname, localdata)
111 overrides = bb.data.getVar('OVERRIDES', localdata)
113 raise bb.build.FuncFailed('OVERRIDES not defined')
114 overrides = bb.data.expand(overrides, localdata)
115 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
117 bb.data.update_data(localdata)
118 basedir = os.path.join(os.path.dirname(root))
120 pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, 1))
121 bb.mkdirhier(pkgoutdir)
124 from glob import glob
125 g = glob('*') + glob('.[!.]*')
127 del g[g.index('DEBIAN')]
128 del g[g.index('./DEBIAN')]
131 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
133 note("Not creating empty archive for %s-%s" % (pkg, bb.data.expand('${PV}-${PR}${DISTRO_PR}', localdata, True)))
134 bb.utils.unlockfile(lf)
137 controldir = os.path.join(root, 'DEBIAN')
138 bb.mkdirhier(controldir)
139 os.chmod(controldir, 0755)
141 ctrlfile = file(os.path.join(controldir, 'control'), 'wb')
143 # ctrlfile = codecs.open("someFile", "w", "utf-8")
145 bb.utils.unlockfile(lf)
146 raise bb.build.FuncFailed("unable to open control file for writing.")
149 version = bb.data.getVar('PKGV', d, 1)
150 if re.match('[^0-9]+$', version):
151 version = '%s0' % version
152 pe = bb.data.getVar('PE', d, 1)
153 if pe and int(pe) > 0:
154 fields.append(["Version: %%s:%s-%%s\n" % version, ['PE', 'PKGR']])
156 fields.append(["Version: %s-%%s\n" % version, ['PKGR']])
157 fields.append(["Description: %s\n", ['DESCRIPTION']])
158 fields.append(["Section: %s\n", ['SECTION']])
159 fields.append(["Priority: %s\n", ['PRIORITY']])
160 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
161 fields.append(["Architecture: %s\n", ['DPKG_ARCH']])
162 fields.append(["OE: %s\n", ['PN']])
163 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
165 # Package, Version, Maintainer, Description - mandatory
166 # Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional
172 data = bb.data.getVar(i, d, 1)
175 if i == 'DPKG_ARCH' and bb.data.getVar('PACKAGE_ARCH', d, 1) == 'all':
180 ctrlfile.write("Package: %s\n" % pkgname)
181 # check for required fields
183 for (c, fs) in fields:
184 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
187 (type, value, traceback) = sys.exc_info()
188 bb.utils.unlockfile(lf)
190 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
193 bb.build.exec_func("mapping_rename_hook", localdata)
195 rdepends = explode_deps(unicode(bb.data.getVar("RDEPENDS", localdata, 1) or ""))
196 rdepends = [dep for dep in rdepends if not '*' in dep]
197 rrecommends = explode_deps(unicode(bb.data.getVar("RRECOMMENDS", localdata, 1) or ""))
198 rrecommends = [rec for rec in rrecommends if not '*' in rec]
199 rsuggests = (unicode(bb.data.getVar("RSUGGESTS", localdata, 1) or "")).split()
200 rprovides = (unicode(bb.data.getVar("RPROVIDES", localdata, 1) or "")).split()
201 rreplaces = (unicode(bb.data.getVar("RREPLACES", localdata, 1) or "")).split()
202 rconflicts = (unicode(bb.data.getVar("RCONFLICTS", localdata, 1) or "")).split()
204 ctrlfile.write(u"Depends: %s\n" % ", ".join(rdepends))
206 ctrlfile.write(u"Suggests: %s\n" % ", ".join(rsuggests))
208 ctrlfile.write(u"Recommends: %s\n" % ", ".join(rrecommends))
210 ctrlfile.write(u"Provides: %s\n" % ", ".join(rprovides))
212 ctrlfile.write(u"Replaces: %s\n" % ", ".join(rreplaces))
214 ctrlfile.write(u"Conflicts: %s\n" % ", ".join(rconflicts))
217 for script in ["preinst", "postinst", "prerm", "postrm"]:
218 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
222 scriptfile = file(os.path.join(controldir, script), 'w')
224 bb.utils.unlockfile(lf)
225 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
226 scriptfile.write("#!/bin/sh\n")
227 scriptfile.write(scriptvar)
229 os.chmod(os.path.join(controldir, script), 0755)
231 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
234 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
236 bb.utils.unlockfile(lf)
237 raise bb.build.FuncFailed("unable to open conffiles for writing.")
238 for f in conffiles_str.split():
239 conffiles.write('%s\n' % f)
243 write_package_md5sums(root, os.path.join(controldir, 'md5sums'),
246 bb.utils.unlockfile(lf)
250 ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir))
252 bb.utils.unlockfile(lf)
253 raise bb.build.FuncFailed("dpkg-deb execution failed")
255 bb.utils.prunedir(controldir)
256 bb.utils.unlockfile(lf)
260 if bb.data.getVar('PACKAGES', d, True) != '':
261 deps = (bb.data.getVarFlag('do_package_write_deb', 'depends', d) or "").split()
262 deps.append('dpkg-native:do_populate_sysroot')
263 deps.append('fakeroot-native:do_populate_sysroot')
264 bb.data.setVarFlag('do_package_write_deb', 'depends', " ".join(deps), d)
267 python do_package_write_deb () {
268 packages = bb.data.getVar('PACKAGES', d, True)
270 bb.debug(1, "No PACKAGES defined, nothing to package")
273 bb.build.exec_func("read_subpackage_metadata", d)
274 bb.build.exec_func("do_package_deb", d)
276 do_package_write_deb[dirs] = "${D}"
277 addtask package_write_deb before do_package_write after do_package
279 do_package_update_index_deb[lockfiles] = "${DEPLOY_DIR_DEB}.lock"
280 do_package_update_index_deb[nostamp] = "1"
281 do_package_update_index_deb[recrdeptask] += "do_package_write_deb"
282 do_package_update_index_deb[depends] += "dpkg-native:do_populate_sysroot"
284 do_package_update_index_deb () {
287 if [ ! -z "${DEPLOY_KEEP_PACKAGES}" ]; then
291 cd "${DEPLOY_DIR_DEB}"
292 for arch in ${PACKAGE_ARCHS}; do
293 if [ -e "$arch" ] ; then
294 dpkg-scanpackages "$arch" | gzip > "$arch/Packages.gz"
296 if [ -e "${BUILD_ARCH}-$arch-sdk" ] ; then
297 dpkg-scanpackages "${BUILD_ARCH}-$arch-sdk" | gzip > "${BUILD_ARCH}-$arch-sdk/Packages.gz"
299 if [ -e "${SDK_SYS}-sdk-$arch" ] ; then
300 dpkg-scanpackages "${SDK_SYS}-sdk-$arch" | gzip > "${SDK_SYS}-sdk-$arch/Packages.gz"
306 addtask package_update_index_deb before do_rootfs