2 DEPENDS_prepend="${@["dpkg-native ", ""][(bb.data.getVar('PACKAGES', d, 1) == '')]}"
3 BOOTSTRAP_EXTRA_RDEPENDS += "dpkg"
4 DISTRO_EXTRA_RDEPENDS += "dpkg"
5 PACKAGE_WRITE_FUNCS += "do_package_deb"
8 python package_deb_fn () {
10 bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
13 addtask package_deb_install
14 python do_package_deb_install () {
16 pkg = bb.data.getVar('PKG', d, 1)
17 pkgfn = bb.data.getVar('PKGFN', d, 1)
18 rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
19 debdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
20 stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
21 stagingbindir = bb.data.getVar('STAGING_BINDIR_NATIVE', d, 1)
22 tmpdir = bb.data.getVar('TMPDIR', d, 1)
24 if None in (pkg,pkgfn,rootfs):
25 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGE_ROOTFS)")
27 if not os.exists(rootfs):
31 raise bb.build.FuncFailed(str(sys.exc_value))
33 # update packages file
34 (exitstatus, output) = commands.getstatusoutput('dpkg-scanpackages %s > %s/Packages' % (debdir, debdir))
35 if (exitstatus != 0 ):
36 raise bb.build.FuncFailed(output)
38 f = open(os.path.join(tmpdir, "stamps", "do_packages"), "w")
41 # NOTE: this env stuff is racy at best, we need something more capable
42 # than 'commands' for command execution, which includes manipulating the
43 # env of the fork+execve'd processs
46 apt_config = os.getenv('APT_CONFIG')
47 os.putenv('APT_CONFIG', os.path.join(stagingdir, 'etc', 'apt', 'apt.conf'))
48 path = os.getenv('PATH')
49 os.putenv('PATH', '%s:%s' % (stagingbindir, os.getenv('PATH')))
52 commands.getstatusoutput('apt-get update')
53 commands.getstatusoutput('apt-get install -y %s' % pkgfn)
56 os.putenv('APT_CONFIG', apt_config)
57 os.putenv('PATH', path)
60 python do_package_deb () {
61 import copy # to back up env data
65 workdir = bb.data.getVar('WORKDIR', d, 1)
67 bb.error("WORKDIR not defined, unable to package")
70 import os # path manipulations
71 outdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
73 bb.error("DEPLOY_DIR_DEB not defined, unable to package")
76 dvar = bb.data.getVar('D', d, 1)
78 bb.error("D not defined, unable to package")
82 packages = bb.data.getVar('PACKAGES', d, 1)
84 bb.debug(1, "PACKAGES not defined, nothing to package")
87 tmpdir = bb.data.getVar('TMPDIR', d, 1)
88 # Invalidate the packages file
89 if os.access(os.path.join(tmpdir, "stamps", "do_packages"),os.R_OK):
90 os.unlink(os.path.join(tmpdir, "stamps", "do_packages"))
93 bb.debug(1, "No packages; nothing to do")
96 for pkg in packages.split():
97 localdata = bb.data.createCopy(d)
98 root = "%s/install/%s" % (workdir, pkg)
100 bb.data.setVar('ROOT', '', localdata)
101 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
102 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
105 bb.data.setVar('PKG', pkgname, localdata)
107 overrides = bb.data.getVar('OVERRIDES', localdata)
109 raise bb.build.FuncFailed('OVERRIDES not defined')
110 overrides = bb.data.expand(overrides, localdata)
111 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
113 bb.data.update_data(localdata)
114 basedir = os.path.join(os.path.dirname(root))
116 pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, 1))
117 bb.mkdirhier(pkgoutdir)
120 from glob import glob
123 del g[g.index('DEBIAN')]
124 del g[g.index('./DEBIAN')]
127 if not g and not bb.data.getVar('ALLOW_EMPTY', localdata):
129 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
131 controldir = os.path.join(root, 'DEBIAN')
132 bb.mkdirhier(controldir)
134 ctrlfile = file(os.path.join(controldir, 'control'), 'wb')
136 # ctrlfile = codecs.open("someFile", "w", "utf-8")
138 raise bb.build.FuncFailed("unable to open control file for writing.")
141 pe = bb.data.getVar('PE', d, 1)
142 if pe and int(pe) > 0:
143 fields.append(["Version: %s:%s-%s\n", ['PE', 'PV', 'PR']])
145 fields.append(["Version: %s-%s\n", ['PV', 'PR']])
146 fields.append(["Description: %s\n", ['DESCRIPTION']])
147 fields.append(["Section: %s\n", ['SECTION']])
148 fields.append(["Priority: %s\n", ['PRIORITY']])
149 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
150 fields.append(["Architecture: %s\n", ['TARGET_ARCH']])
151 fields.append(["OE: %s\n", ['P']])
152 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
154 # Package, Version, Maintainer, Description - mandatory
155 # Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional
161 data = bb.data.getVar(i, d, 1)
164 if i == 'TARGET_ARCH' and bb.data.getVar('PACKAGE_ARCH', d, 1) == 'all':
169 ctrlfile.write("Package: %s\n" % pkgname)
170 # check for required fields
172 for (c, fs) in fields:
173 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
175 (type, value, traceback) = sys.exc_info()
177 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
180 bb.build.exec_func("mapping_rename_hook", localdata)
182 rdepends = explode_deps(unicode(bb.data.getVar("RDEPENDS", localdata, 1) or ""))
183 rdepends = [dep for dep in rdepends if not '*' in dep]
184 rrecommends = explode_deps(unicode(bb.data.getVar("RRECOMMENDS", localdata, 1) or ""))
185 rrecommends = [rec for rec in rrecommends if not '*' in rec]
186 rsuggests = (unicode(bb.data.getVar("RSUGGESTS", localdata, 1) or "")).split()
187 rprovides = (unicode(bb.data.getVar("RPROVIDES", localdata, 1) or "")).split()
188 rreplaces = (unicode(bb.data.getVar("RREPLACES", localdata, 1) or "")).split()
189 rconflicts = (unicode(bb.data.getVar("RCONFLICTS", localdata, 1) or "")).split()
191 ctrlfile.write(u"Depends: %s\n" % ", ".join(rdepends))
193 ctrlfile.write(u"Suggests: %s\n" % ", ".join(rsuggests))
195 ctrlfile.write(u"Recommends: %s\n" % ", ".join(rrecommends))
197 ctrlfile.write(u"Provides: %s\n" % ", ".join(rprovides))
199 ctrlfile.write(u"Replaces: %s\n" % ", ".join(rreplaces))
201 ctrlfile.write(u"Conflicts: %s\n" % ", ".join(rconflicts))
204 for script in ["preinst", "postinst", "prerm", "postrm"]:
205 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
209 scriptfile = file(os.path.join(controldir, script), 'w')
211 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
212 scriptfile.write("#!/bin/sh\n")
213 scriptfile.write(scriptvar)
215 os.chmod(os.path.join(controldir, script), 0755)
217 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
220 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
222 raise bb.build.FuncFailed("unable to open conffiles for writing.")
223 for f in conffiles_str.split():
224 conffiles.write('%s\n' % f)
228 ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir))
230 raise bb.build.FuncFailed("dpkg-deb execution failed")
232 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
233 scriptfile = os.path.join(controldir, script)
235 os.remove(scriptfile)