summaryrefslogtreecommitdiffstats
path: root/meta/classes/package_deb.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/package_deb.bbclass')
-rw-r--r--meta/classes/package_deb.bbclass317
1 files changed, 317 insertions, 0 deletions
diff --git a/meta/classes/package_deb.bbclass b/meta/classes/package_deb.bbclass
new file mode 100644
index 0000000..7bc29df
--- /dev/null
+++ b/meta/classes/package_deb.bbclass
@@ -0,0 +1,317 @@
1#
2# Copyright 2006-2008 OpenedHand Ltd.
3#
4
5inherit package
6
7IMAGE_PKGTYPE ?= "deb"
8
9DPKG_ARCH ?= "${TARGET_ARCH}"
10
11PKGWRITEDIRDEB = "${WORKDIR}/deploy-debs"
12
13APTCONF_TARGET = "${WORKDIR}"
14
15APT_ARGS = "${@['', '--no-install-recommends'][d.getVar("NO_RECOMMENDATIONS", True) == "1"]}"
16
17#
18# install a bunch of packages using apt
19# the following shell variables needs to be set before calling this func:
20# INSTALL_ROOTFS_DEB - install root dir
21# INSTALL_BASEARCH_DEB - install base architecutre
22# INSTALL_ARCHS_DEB - list of available archs
23# INSTALL_PACKAGES_NORMAL_DEB - packages to be installed
24# INSTALL_PACKAGES_ATTEMPTONLY_DEB - packages attemped to be installed only
25# INSTALL_PACKAGES_LINGUAS_DEB - additional packages for uclibc
26# INSTALL_TASK_DEB - task name
27
28python do_package_deb () {
29 import re, copy
30 import textwrap
31 import subprocess
32
33 workdir = d.getVar('WORKDIR', True)
34 if not workdir:
35 bb.error("WORKDIR not defined, unable to package")
36 return
37
38 outdir = d.getVar('PKGWRITEDIRDEB', True)
39 if not outdir:
40 bb.error("PKGWRITEDIRDEB not defined, unable to package")
41 return
42
43 packages = d.getVar('PACKAGES', True)
44 if not packages:
45 bb.debug(1, "PACKAGES not defined, nothing to package")
46 return
47
48 tmpdir = d.getVar('TMPDIR', True)
49
50 if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK):
51 os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"))
52
53 if packages == []:
54 bb.debug(1, "No packages; nothing to do")
55 return
56
57 pkgdest = d.getVar('PKGDEST', True)
58
59 def cleanupcontrol(root):
60 for p in ['CONTROL', 'DEBIAN']:
61 p = os.path.join(root, p)
62 if os.path.exists(p):
63 bb.utils.prunedir(p)
64
65 for pkg in packages.split():
66 localdata = bb.data.createCopy(d)
67 root = "%s/%s" % (pkgdest, pkg)
68
69 lf = bb.utils.lockfile(root + ".lock")
70
71 localdata.setVar('ROOT', '')
72 localdata.setVar('ROOT_%s' % pkg, root)
73 pkgname = localdata.getVar('PKG_%s' % pkg, True)
74 if not pkgname:
75 pkgname = pkg
76 localdata.setVar('PKG', pkgname)
77
78 localdata.setVar('OVERRIDES', pkg)
79
80 bb.data.update_data(localdata)
81 basedir = os.path.join(os.path.dirname(root))
82
83 pkgoutdir = os.path.join(outdir, localdata.getVar('PACKAGE_ARCH', True))
84 bb.utils.mkdirhier(pkgoutdir)
85
86 os.chdir(root)
87 cleanupcontrol(root)
88 from glob import glob
89 g = glob('*')
90 if not g and localdata.getVar('ALLOW_EMPTY') != "1":
91 bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV', True), localdata.getVar('PKGR', True)))
92 bb.utils.unlockfile(lf)
93 continue
94
95 controldir = os.path.join(root, 'DEBIAN')
96 bb.utils.mkdirhier(controldir)
97 os.chmod(controldir, 0755)
98 try:
99 ctrlfile = open(os.path.join(controldir, 'control'), 'w')
100 # import codecs
101 # ctrlfile = codecs.open("someFile", "w", "utf-8")
102 except OSError:
103 bb.utils.unlockfile(lf)
104 raise bb.build.FuncFailed("unable to open control file for writing.")
105
106 fields = []
107 pe = d.getVar('PKGE', True)
108 if pe and int(pe) > 0:
109 fields.append(["Version: %s:%s-%s\n", ['PKGE', 'PKGV', 'PKGR']])
110 else:
111 fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']])
112 fields.append(["Description: %s\n", ['DESCRIPTION']])
113 fields.append(["Section: %s\n", ['SECTION']])
114 fields.append(["Priority: %s\n", ['PRIORITY']])
115 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
116 fields.append(["Architecture: %s\n", ['DPKG_ARCH']])
117 fields.append(["OE: %s\n", ['PN']])
118 fields.append(["PackageArch: %s\n", ['PACKAGE_ARCH']])
119 if d.getVar('HOMEPAGE', True):
120 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
121
122 # Package, Version, Maintainer, Description - mandatory
123 # Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional
124
125
126 def pullData(l, d):
127 l2 = []
128 for i in l:
129 data = d.getVar(i, True)
130 if data is None:
131 raise KeyError(f)
132 if i == 'DPKG_ARCH' and d.getVar('PACKAGE_ARCH', True) == 'all':
133 data = 'all'
134 elif i == 'PACKAGE_ARCH' or i == 'DPKG_ARCH':
135 # The params in deb package control don't allow character
136 # `_', so change the arch's `_' to `-'. Such as `x86_64'
137 # -->`x86-64'
138 data = data.replace('_', '-')
139 l2.append(data)
140 return l2
141
142 ctrlfile.write("Package: %s\n" % pkgname)
143 # check for required fields
144 try:
145 for (c, fs) in fields:
146 for f in fs:
147 if localdata.getVar(f) is None:
148 raise KeyError(f)
149 # Special behavior for description...
150 if 'DESCRIPTION' in fs:
151 summary = localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or "."
152 ctrlfile.write('Description: %s\n' % unicode(summary))
153 description = localdata.getVar('DESCRIPTION', True) or "."
154 description = textwrap.dedent(description).strip()
155 if '\\n' in description:
156 # Manually indent
157 for t in description.split('\\n'):
158 # We don't limit the width when manually indent, but we do
159 # need the textwrap.fill() to set the initial_indent and
160 # subsequent_indent, so set a large width
161 ctrlfile.write('%s\n' % unicode(textwrap.fill(t, width=100000, initial_indent=' ', subsequent_indent=' ')))
162 else:
163 # Auto indent
164 ctrlfile.write('%s\n' % unicode(textwrap.fill(description.strip(), width=74, initial_indent=' ', subsequent_indent=' ')))
165
166 else:
167 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
168 except KeyError:
169 import sys
170 (type, value, traceback) = sys.exc_info()
171 bb.utils.unlockfile(lf)
172 ctrlfile.close()
173 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
174 # more fields
175
176 custom_fields_chunk = get_package_additional_metadata("deb", localdata)
177 if custom_fields_chunk is not None:
178 ctrlfile.write(unicode(custom_fields_chunk))
179 ctrlfile.write("\n")
180
181 mapping_rename_hook(localdata)
182
183 def debian_cmp_remap(var):
184 # dpkg does not allow for '(' or ')' in a dependency name
185 # replace these instances with '__' and '__'
186 #
187 # In debian '>' and '<' do not mean what it appears they mean
188 # '<' = less or equal
189 # '>' = greater or equal
190 # adjust these to the '<<' and '>>' equivalents
191 #
192 for dep in var:
193 if '(' in dep:
194 newdep = dep.replace('(', '__')
195 newdep = newdep.replace(')', '__')
196 if newdep != dep:
197 var[newdep] = var[dep]
198 del var[dep]
199 for dep in var:
200 for i, v in enumerate(var[dep]):
201 if (v or "").startswith("< "):
202 var[dep][i] = var[dep][i].replace("< ", "<< ")
203 elif (v or "").startswith("> "):
204 var[dep][i] = var[dep][i].replace("> ", ">> ")
205
206 rdepends = bb.utils.explode_dep_versions2(localdata.getVar("RDEPENDS", True) or "")
207 debian_cmp_remap(rdepends)
208 for dep in rdepends:
209 if '*' in dep:
210 del rdepends[dep]
211 rrecommends = bb.utils.explode_dep_versions2(localdata.getVar("RRECOMMENDS", True) or "")
212 debian_cmp_remap(rrecommends)
213 for dep in rrecommends:
214 if '*' in dep:
215 del rrecommends[dep]
216 rsuggests = bb.utils.explode_dep_versions2(localdata.getVar("RSUGGESTS", True) or "")
217 debian_cmp_remap(rsuggests)
218 rprovides = bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES", True) or "")
219 debian_cmp_remap(rprovides)
220 rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES", True) or "")
221 debian_cmp_remap(rreplaces)
222 rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS", True) or "")
223 debian_cmp_remap(rconflicts)
224 if rdepends:
225 ctrlfile.write("Depends: %s\n" % unicode(bb.utils.join_deps(rdepends)))
226 if rsuggests:
227 ctrlfile.write("Suggests: %s\n" % unicode(bb.utils.join_deps(rsuggests)))
228 if rrecommends:
229 ctrlfile.write("Recommends: %s\n" % unicode(bb.utils.join_deps(rrecommends)))
230 if rprovides:
231 ctrlfile.write("Provides: %s\n" % unicode(bb.utils.join_deps(rprovides)))
232 if rreplaces:
233 ctrlfile.write("Replaces: %s\n" % unicode(bb.utils.join_deps(rreplaces)))
234 if rconflicts:
235 ctrlfile.write("Conflicts: %s\n" % unicode(bb.utils.join_deps(rconflicts)))
236 ctrlfile.close()
237
238 for script in ["preinst", "postinst", "prerm", "postrm"]:
239 scriptvar = localdata.getVar('pkg_%s' % script, True)
240 if not scriptvar:
241 continue
242 try:
243 scriptfile = open(os.path.join(controldir, script), 'w')
244 except OSError:
245 bb.utils.unlockfile(lf)
246 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
247 scriptfile.write("#!/bin/sh\n")
248 scriptfile.write(scriptvar)
249 scriptfile.close()
250 os.chmod(os.path.join(controldir, script), 0755)
251
252 conffiles_str = localdata.getVar("CONFFILES", True)
253 if conffiles_str:
254 try:
255 conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
256 except OSError:
257 bb.utils.unlockfile(lf)
258 raise bb.build.FuncFailed("unable to open conffiles for writing.")
259 for f in conffiles_str.split():
260 if os.path.exists(oe.path.join(root, f)):
261 conffiles.write('%s\n' % f)
262 conffiles.close()
263
264 os.chdir(basedir)
265 ret = subprocess.call("PATH=\"%s\" dpkg-deb -b %s %s" % (localdata.getVar("PATH", True), root, pkgoutdir), shell=True)
266 if ret != 0:
267 bb.utils.unlockfile(lf)
268 raise bb.build.FuncFailed("dpkg-deb execution failed")
269
270 cleanupcontrol(root)
271 bb.utils.unlockfile(lf)
272}
273
274SSTATETASKS += "do_package_write_deb"
275do_package_write_deb[sstate-inputdirs] = "${PKGWRITEDIRDEB}"
276do_package_write_deb[sstate-outputdirs] = "${DEPLOY_DIR_DEB}"
277
278python do_package_write_deb_setscene () {
279 tmpdir = d.getVar('TMPDIR', True)
280
281 if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK):
282 os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"))
283
284 sstate_setscene(d)
285}
286addtask do_package_write_deb_setscene
287
288python () {
289 if d.getVar('PACKAGES', True) != '':
290 deps = ' dpkg-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot'
291 d.appendVarFlag('do_package_write_deb', 'depends', deps)
292 d.setVarFlag('do_package_write_deb', 'fakeroot', "1")
293
294 # Map TARGET_ARCH to Debian's ideas about architectures
295 darch = d.getVar('DPKG_ARCH', True)
296 if darch in ["x86", "i486", "i586", "i686", "pentium"]:
297 d.setVar('DPKG_ARCH', 'i386')
298 elif darch == "x86_64":
299 d.setVar('DPKG_ARCH', 'amd64')
300 elif darch == "arm":
301 d.setVar('DPKG_ARCH', 'armel')
302}
303
304python do_package_write_deb () {
305 bb.build.exec_func("read_subpackage_metadata", d)
306 bb.build.exec_func("do_package_deb", d)
307}
308do_package_write_deb[dirs] = "${PKGWRITEDIRDEB}"
309do_package_write_deb[cleandirs] = "${PKGWRITEDIRDEB}"
310do_package_write_deb[umask] = "022"
311addtask package_write_deb after do_packagedata do_package
312
313
314PACKAGEINDEXDEPS += "dpkg-native:do_populate_sysroot"
315PACKAGEINDEXDEPS += "apt-native:do_populate_sysroot"
316
317do_build[recrdeptask] += "do_package_write_deb"