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 copy # to back up env data
71 workdir = bb.data.getVar('WORKDIR', d, 1)
73 bb.error("WORKDIR not defined, unable to package")
76 import os # path manipulations
77 outdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
79 bb.error("DEPLOY_DIR_DEB not defined, unable to package")
82 dvar = bb.data.getVar('D', d, 1)
84 bb.error("D not defined, unable to package")
88 packages = bb.data.getVar('PACKAGES', d, 1)
90 bb.debug(1, "PACKAGES not defined, nothing to package")
93 tmpdir = bb.data.getVar('TMPDIR', d, 1)
94 # Invalidate the packages file
95 if os.access(os.path.join(tmpdir, "stamps", "do_packages"),os.R_OK):
96 os.unlink(os.path.join(tmpdir, "stamps", "do_packages"))
99 bb.debug(1, "No packages; nothing to do")
102 for pkg in packages.split():
103 localdata = bb.data.createCopy(d)
104 root = "%s/install/%s" % (workdir, pkg)
106 bb.data.setVar('ROOT', '', localdata)
107 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
108 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
111 bb.data.setVar('PKG', pkgname, localdata)
113 overrides = bb.data.getVar('OVERRIDES', localdata)
115 raise bb.build.FuncFailed('OVERRIDES not defined')
116 overrides = bb.data.expand(overrides, localdata)
117 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
119 bb.data.update_data(localdata)
120 basedir = os.path.join(os.path.dirname(root))
122 pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, 1))
123 bb.mkdirhier(pkgoutdir)
126 from glob import glob
129 del g[g.index('DEBIAN')]
130 del g[g.index('./DEBIAN')]
133 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
135 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
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 raise bb.build.FuncFailed("unable to open control file for writing.")
148 pe = bb.data.getVar('PE', d, 1)
149 if pe and int(pe) > 0:
150 fields.append(["Version: %s:%s-%s\n", ['PE', 'PV', 'PR']])
152 fields.append(["Version: %s-%s\n", ['PV', 'PR']])
153 fields.append(["Description: %s\n", ['DESCRIPTION']])
154 fields.append(["Section: %s\n", ['SECTION']])
155 fields.append(["Priority: %s\n", ['PRIORITY']])
156 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
157 fields.append(["Architecture: %s\n", ['TARGET_ARCH']])
158 fields.append(["OE: %s\n", ['PN']])
159 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
161 # Package, Version, Maintainer, Description - mandatory
162 # Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional
168 data = bb.data.getVar(i, d, 1)
171 if i == 'TARGET_ARCH' and bb.data.getVar('PACKAGE_ARCH', d, 1) == 'all':
176 ctrlfile.write("Package: %s\n" % pkgname)
177 # check for required fields
179 for (c, fs) in fields:
180 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
182 (type, value, traceback) = sys.exc_info()
184 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
187 bb.build.exec_func("mapping_rename_hook", localdata)
189 rdepends = explode_deps(unicode(bb.data.getVar("RDEPENDS", localdata, 1) or ""))
190 rdepends = [dep for dep in rdepends if not '*' in dep]
191 rrecommends = explode_deps(unicode(bb.data.getVar("RRECOMMENDS", localdata, 1) or ""))
192 rrecommends = [rec for rec in rrecommends if not '*' in rec]
193 rsuggests = (unicode(bb.data.getVar("RSUGGESTS", localdata, 1) or "")).split()
194 rprovides = (unicode(bb.data.getVar("RPROVIDES", localdata, 1) or "")).split()
195 rreplaces = (unicode(bb.data.getVar("RREPLACES", localdata, 1) or "")).split()
196 rconflicts = (unicode(bb.data.getVar("RCONFLICTS", localdata, 1) or "")).split()
198 ctrlfile.write(u"Depends: %s\n" % ", ".join(rdepends))
200 ctrlfile.write(u"Suggests: %s\n" % ", ".join(rsuggests))
202 ctrlfile.write(u"Recommends: %s\n" % ", ".join(rrecommends))
204 ctrlfile.write(u"Provides: %s\n" % ", ".join(rprovides))
206 ctrlfile.write(u"Replaces: %s\n" % ", ".join(rreplaces))
208 ctrlfile.write(u"Conflicts: %s\n" % ", ".join(rconflicts))
211 for script in ["preinst", "postinst", "prerm", "postrm"]:
212 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
216 scriptfile = file(os.path.join(controldir, script), 'w')
218 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
219 scriptfile.write("#!/bin/sh\n")
220 scriptfile.write(scriptvar)
222 os.chmod(os.path.join(controldir, script), 0755)
224 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
227 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
229 raise bb.build.FuncFailed("unable to open conffiles for writing.")
230 for f in conffiles_str.split():
231 conffiles.write('%s\n' % f)
235 ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir))
237 raise bb.build.FuncFailed("dpkg-deb execution failed")
239 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
240 scriptfile = os.path.join(controldir, script)
242 os.remove(scriptfile)