3 PACKAGE_EXTRA_DEPENDS += "dpkg-native fakeroot-native"
5 BOOTSTRAP_EXTRA_RDEPENDS += "dpkg"
6 DISTRO_EXTRA_RDEPENDS += "dpkg"
7 PACKAGE_WRITE_FUNCS += "do_package_deb"
10 python package_deb_fn () {
12 bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
15 addtask package_deb_install
16 python do_package_deb_install () {
18 pkg = bb.data.getVar('PKG', d, 1)
19 pkgfn = bb.data.getVar('PKGFN', d, 1)
20 rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
21 debdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
22 stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
23 stagingbindir = bb.data.getVar('STAGING_BINDIR_NATIVE', d, 1)
24 tmpdir = bb.data.getVar('TMPDIR', d, 1)
26 if None in (pkg,pkgfn,rootfs):
27 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGE_ROOTFS)")
29 if not os.exists(rootfs):
33 raise bb.build.FuncFailed(str(sys.exc_value))
35 # update packages file
36 (exitstatus, output) = commands.getstatusoutput('dpkg-scanpackages %s > %s/Packages' % (debdir, debdir))
37 if (exitstatus != 0 ):
38 raise bb.build.FuncFailed(output)
40 f = open(os.path.join(tmpdir, "stamps", "do_packages"), "w")
43 # NOTE: this env stuff is racy at best, we need something more capable
44 # than 'commands' for command execution, which includes manipulating the
45 # env of the fork+execve'd processs
48 apt_config = os.getenv('APT_CONFIG')
49 os.putenv('APT_CONFIG', os.path.join(stagingdir, 'etc', 'apt', 'apt.conf'))
50 path = os.getenv('PATH')
51 os.putenv('PATH', '%s:%s' % (stagingbindir, os.getenv('PATH')))
54 commands.getstatusoutput('apt-get update')
55 commands.getstatusoutput('apt-get install -y %s' % pkgfn)
58 os.putenv('APT_CONFIG', apt_config)
59 os.putenv('PATH', path)
62 python do_package_deb () {
63 import copy # to back up env data
67 workdir = bb.data.getVar('WORKDIR', d, 1)
69 bb.error("WORKDIR not defined, unable to package")
72 import os # path manipulations
73 outdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
75 bb.error("DEPLOY_DIR_DEB not defined, unable to package")
78 dvar = bb.data.getVar('D', d, 1)
80 bb.error("D not defined, unable to package")
84 packages = bb.data.getVar('PACKAGES', d, 1)
86 bb.debug(1, "PACKAGES not defined, nothing to package")
89 tmpdir = bb.data.getVar('TMPDIR', d, 1)
90 # Invalidate the packages file
91 if os.access(os.path.join(tmpdir, "stamps", "do_packages"),os.R_OK):
92 os.unlink(os.path.join(tmpdir, "stamps", "do_packages"))
95 bb.debug(1, "No packages; nothing to do")
98 for pkg in packages.split():
99 localdata = bb.data.createCopy(d)
100 root = "%s/install/%s" % (workdir, pkg)
102 bb.data.setVar('ROOT', '', localdata)
103 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
104 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
107 bb.data.setVar('PKG', pkgname, localdata)
109 overrides = bb.data.getVar('OVERRIDES', localdata)
111 raise bb.build.FuncFailed('OVERRIDES not defined')
112 overrides = bb.data.expand(overrides, localdata)
113 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
115 bb.data.update_data(localdata)
116 basedir = os.path.join(os.path.dirname(root))
118 pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, 1))
119 bb.mkdirhier(pkgoutdir)
122 from glob import glob
125 del g[g.index('DEBIAN')]
126 del g[g.index('./DEBIAN')]
129 if not g and not bb.data.getVar('ALLOW_EMPTY', localdata):
131 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
133 controldir = os.path.join(root, 'DEBIAN')
134 bb.mkdirhier(controldir)
136 ctrlfile = file(os.path.join(controldir, 'control'), 'wb')
138 # ctrlfile = codecs.open("someFile", "w", "utf-8")
140 raise bb.build.FuncFailed("unable to open control file for writing.")
143 pe = bb.data.getVar('PE', d, 1)
144 if pe and int(pe) > 0:
145 fields.append(["Version: %s:%s-%s\n", ['PE', 'PV', 'PR']])
147 fields.append(["Version: %s-%s\n", ['PV', 'PR']])
148 fields.append(["Description: %s\n", ['DESCRIPTION']])
149 fields.append(["Section: %s\n", ['SECTION']])
150 fields.append(["Priority: %s\n", ['PRIORITY']])
151 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
152 fields.append(["Architecture: %s\n", ['TARGET_ARCH']])
153 fields.append(["OE: %s\n", ['P']])
154 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
156 # Package, Version, Maintainer, Description - mandatory
157 # Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional
163 data = bb.data.getVar(i, d, 1)
166 if i == 'TARGET_ARCH' and bb.data.getVar('PACKAGE_ARCH', d, 1) == 'all':
171 ctrlfile.write("Package: %s\n" % pkgname)
172 # check for required fields
174 for (c, fs) in fields:
175 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
177 (type, value, traceback) = sys.exc_info()
179 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
182 bb.build.exec_func("mapping_rename_hook", localdata)
184 rdepends = explode_deps(unicode(bb.data.getVar("RDEPENDS", localdata, 1) or ""))
185 rdepends = [dep for dep in rdepends if not '*' in dep]
186 rrecommends = explode_deps(unicode(bb.data.getVar("RRECOMMENDS", localdata, 1) or ""))
187 rrecommends = [rec for rec in rrecommends if not '*' in rec]
188 rsuggests = (unicode(bb.data.getVar("RSUGGESTS", localdata, 1) or "")).split()
189 rprovides = (unicode(bb.data.getVar("RPROVIDES", localdata, 1) or "")).split()
190 rreplaces = (unicode(bb.data.getVar("RREPLACES", localdata, 1) or "")).split()
191 rconflicts = (unicode(bb.data.getVar("RCONFLICTS", localdata, 1) or "")).split()
193 ctrlfile.write(u"Depends: %s\n" % ", ".join(rdepends))
195 ctrlfile.write(u"Suggests: %s\n" % ", ".join(rsuggests))
197 ctrlfile.write(u"Recommends: %s\n" % ", ".join(rrecommends))
199 ctrlfile.write(u"Provides: %s\n" % ", ".join(rprovides))
201 ctrlfile.write(u"Replaces: %s\n" % ", ".join(rreplaces))
203 ctrlfile.write(u"Conflicts: %s\n" % ", ".join(rconflicts))
206 for script in ["preinst", "postinst", "prerm", "postrm"]:
207 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
211 scriptfile = file(os.path.join(controldir, script), 'w')
213 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
214 scriptfile.write("#!/bin/sh\n")
215 scriptfile.write(scriptvar)
217 os.chmod(os.path.join(controldir, script), 0755)
219 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
222 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
224 raise bb.build.FuncFailed("unable to open conffiles for writing.")
225 for f in conffiles_str.split():
226 conffiles.write('%s\n' % f)
230 ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir))
232 raise bb.build.FuncFailed("dpkg-deb execution failed")
234 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
235 scriptfile = os.path.join(controldir, script)
237 os.remove(scriptfile)