2 # Copyright 2006-2007 OpenedHand Ltd.
7 PACKAGE_EXTRA_DEPENDS += "dpkg-native fakeroot-native"
9 BOOTSTRAP_EXTRA_RDEPENDS += "dpkg"
10 DISTRO_EXTRA_RDEPENDS += "dpkg"
11 PACKAGE_WRITE_FUNCS += "do_package_deb"
12 IMAGE_PKGTYPE ?= "deb"
14 python package_deb_fn () {
16 bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
19 addtask package_deb_install
20 python do_package_deb_install () {
22 pkg = bb.data.getVar('PKG', d, 1)
23 pkgfn = bb.data.getVar('PKGFN', d, 1)
24 rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
25 debdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
26 stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
27 stagingbindir = bb.data.getVar('STAGING_BINDIR_NATIVE', d, 1)
28 tmpdir = bb.data.getVar('TMPDIR', d, 1)
30 if None in (pkg,pkgfn,rootfs):
31 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGE_ROOTFS)")
33 if not os.exists(rootfs):
37 raise bb.build.FuncFailed(str(sys.exc_value))
39 # update packages file
40 (exitstatus, output) = commands.getstatusoutput('dpkg-scanpackages %s > %s/Packages' % (debdir, debdir))
41 if (exitstatus != 0 ):
42 raise bb.build.FuncFailed(output)
44 f = open(os.path.join(tmpdir, "stamps", "do_packages"), "w")
47 # NOTE: this env stuff is racy at best, we need something more capable
48 # than 'commands' for command execution, which includes manipulating the
49 # env of the fork+execve'd processs
52 apt_config = os.getenv('APT_CONFIG')
53 os.putenv('APT_CONFIG', os.path.join(stagingdir, 'etc', 'apt', 'apt.conf'))
54 path = os.getenv('PATH')
55 os.putenv('PATH', '%s:%s' % (stagingbindir, os.getenv('PATH')))
58 commands.getstatusoutput('apt-get update')
59 commands.getstatusoutput('apt-get install -y %s' % pkgfn)
62 os.putenv('APT_CONFIG', apt_config)
63 os.putenv('PATH', path)
66 python do_package_deb () {
67 import sys, re, fcntl, copy
69 workdir = bb.data.getVar('WORKDIR', d, 1)
71 bb.error("WORKDIR not defined, unable to package")
74 import os # path manipulations
75 outdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
77 bb.error("DEPLOY_DIR_DEB not defined, unable to package")
80 dvar = bb.data.getVar('D', d, 1)
82 bb.error("D not defined, unable to package")
86 packages = bb.data.getVar('PACKAGES', d, 1)
88 bb.debug(1, "PACKAGES not defined, nothing to package")
91 tmpdir = bb.data.getVar('TMPDIR', d, 1)
92 # Invalidate the packages file
93 if os.access(os.path.join(tmpdir, "stamps", "do_packages"),os.R_OK):
94 os.unlink(os.path.join(tmpdir, "stamps", "do_packages"))
97 bb.debug(1, "No packages; nothing to do")
101 lf = open(name, "a+")
102 fcntl.flock(lf.fileno(), fcntl.LOCK_EX)
106 fcntl.flock(lf.fileno(), fcntl.LOCK_UN)
109 for pkg in packages.split():
110 localdata = bb.data.createCopy(d)
111 root = "%s/install/%s" % (workdir, pkg)
113 lf = lockfile(root + ".lock")
115 bb.data.setVar('ROOT', '', localdata)
116 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
117 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
120 bb.data.setVar('PKG', pkgname, localdata)
122 overrides = bb.data.getVar('OVERRIDES', localdata)
124 raise bb.build.FuncFailed('OVERRIDES not defined')
125 overrides = bb.data.expand(overrides, localdata)
126 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
128 bb.data.update_data(localdata)
129 basedir = os.path.join(os.path.dirname(root))
131 pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, 1))
132 bb.mkdirhier(pkgoutdir)
135 from glob import glob
138 del g[g.index('DEBIAN')]
139 del g[g.index('./DEBIAN')]
142 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
144 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
147 controldir = os.path.join(root, 'DEBIAN')
148 bb.mkdirhier(controldir)
149 os.chmod(controldir, 0755)
151 ctrlfile = file(os.path.join(controldir, 'control'), 'wb')
153 # ctrlfile = codecs.open("someFile", "w", "utf-8")
155 raise bb.build.FuncFailed("unable to open control file for writing.")
158 pe = bb.data.getVar('PE', d, 1)
159 if pe and int(pe) > 0:
160 fields.append(["Version: %s:%s-%s\n", ['PE', 'PV', 'PR']])
162 fields.append(["Version: %s-%s\n", ['PV', 'PR']])
163 fields.append(["Description: %s\n", ['DESCRIPTION']])
164 fields.append(["Section: %s\n", ['SECTION']])
165 fields.append(["Priority: %s\n", ['PRIORITY']])
166 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
167 fields.append(["Architecture: %s\n", ['TARGET_ARCH']])
168 fields.append(["OE: %s\n", ['PN']])
169 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
171 # Package, Version, Maintainer, Description - mandatory
172 # Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional
178 data = bb.data.getVar(i, d, 1)
181 if i == 'TARGET_ARCH' and bb.data.getVar('PACKAGE_ARCH', d, 1) == 'all':
186 ctrlfile.write("Package: %s\n" % pkgname)
187 # check for required fields
189 for (c, fs) in fields:
190 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
192 (type, value, traceback) = sys.exc_info()
194 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
197 bb.build.exec_func("mapping_rename_hook", localdata)
199 rdepends = explode_deps(unicode(bb.data.getVar("RDEPENDS", localdata, 1) or ""))
200 rdepends = [dep for dep in rdepends if not '*' in dep]
201 rrecommends = explode_deps(unicode(bb.data.getVar("RRECOMMENDS", localdata, 1) or ""))
202 rrecommends = [rec for rec in rrecommends if not '*' in rec]
203 rsuggests = (unicode(bb.data.getVar("RSUGGESTS", localdata, 1) or "")).split()
204 rprovides = (unicode(bb.data.getVar("RPROVIDES", localdata, 1) or "")).split()
205 rreplaces = (unicode(bb.data.getVar("RREPLACES", localdata, 1) or "")).split()
206 rconflicts = (unicode(bb.data.getVar("RCONFLICTS", localdata, 1) or "")).split()
208 ctrlfile.write(u"Depends: %s\n" % ", ".join(rdepends))
210 ctrlfile.write(u"Suggests: %s\n" % ", ".join(rsuggests))
212 ctrlfile.write(u"Recommends: %s\n" % ", ".join(rrecommends))
214 ctrlfile.write(u"Provides: %s\n" % ", ".join(rprovides))
216 ctrlfile.write(u"Replaces: %s\n" % ", ".join(rreplaces))
218 ctrlfile.write(u"Conflicts: %s\n" % ", ".join(rconflicts))
221 for script in ["preinst", "postinst", "prerm", "postrm"]:
222 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
226 scriptfile = file(os.path.join(controldir, script), 'w')
228 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
229 scriptfile.write("#!/bin/sh\n")
230 scriptfile.write(scriptvar)
232 os.chmod(os.path.join(controldir, script), 0755)
234 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
237 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
239 raise bb.build.FuncFailed("unable to open conffiles for writing.")
240 for f in conffiles_str.split():
241 conffiles.write('%s\n' % f)
245 ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir))
247 raise bb.build.FuncFailed("dpkg-deb execution failed")
249 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
250 scriptfile = os.path.join(controldir, script)
252 os.remove(scriptfile)
265 if bb.data.getVar('PACKAGES', d, True) != '':
266 bb.data.setVarFlag('do_package_write_deb', 'depends', 'dpkg-native:do_populate_staging fakeroot-native:do_populate_staging', d)
269 python do_package_write_deb () {
270 bb.build.exec_func("read_subpackage_metadata", d)
271 bb.build.exec_func("do_package_deb", d)
273 do_package_write_deb[dirs] = "${D}"
274 #addtask package_write_deb before do_package_write after do_package