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.bbclass236
1 files changed, 236 insertions, 0 deletions
diff --git a/meta/classes/package_deb.bbclass b/meta/classes/package_deb.bbclass
new file mode 100644
index 0000000000..4526ac156c
--- /dev/null
+++ b/meta/classes/package_deb.bbclass
@@ -0,0 +1,236 @@
1inherit package
2DEPENDS_prepend="${@["dpkg-native ", ""][(bb.data.getVar('PACKAGES', d, 1) == '')]}"
3BOOTSTRAP_EXTRA_RDEPENDS += "dpkg"
4DISTRO_EXTRA_RDEPENDS += "dpkg"
5PACKAGEFUNCS += "do_package_deb"
6IMAGE_PKGTYPE ?= "deb"
7
8python package_deb_fn () {
9 from bb import data
10 bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
11}
12
13addtask package_deb_install
14python do_package_deb_install () {
15 import os, sys
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', d, 1)
22 tmpdir = bb.data.getVar('TMPDIR', d, 1)
23
24 if None in (pkg,pkgfn,rootfs):
25 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGE_ROOTFS)")
26 try:
27 if not os.exists(rootfs):
28 os.makedirs(rootfs)
29 os.chdir(rootfs)
30 except OSError:
31 raise bb.build.FuncFailed(str(sys.exc_value))
32
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)
37
38 f = open(os.path.join(os.path.join(tmpdir, "stamps"), "do_packages"), "w")
39 f.close()
40
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
44
45 # Set up environment
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')))
50
51 # install package
52 commands.getstatusoutput('apt-get update')
53 commands.getstatusoutput('apt-get install -y %s' % pkgfn)
54
55 # revert environment
56 os.putenv('APT_CONFIG', apt_config)
57 os.putenv('PATH', path)
58}
59
60python do_package_deb () {
61 import copy # to back up env data
62 import sys
63 import re
64
65 workdir = bb.data.getVar('WORKDIR', d, 1)
66 if not workdir:
67 bb.error("WORKDIR not defined, unable to package")
68 return
69
70 import os # path manipulations
71 outdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1)
72 if not outdir:
73 bb.error("DEPLOY_DIR_DEB not defined, unable to package")
74 return
75
76 dvar = bb.data.getVar('D', d, 1)
77 if not dvar:
78 bb.error("D not defined, unable to package")
79 return
80 bb.mkdirhier(dvar)
81
82 packages = bb.data.getVar('PACKAGES', d, 1)
83 if not packages:
84 bb.debug(1, "PACKAGES not defined, nothing to package")
85 return
86
87 tmpdir = bb.data.getVar('TMPDIR', d, 1)
88 # Invalidate the packages file
89 if os.access(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),os.R_OK):
90 os.unlink(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"))
91
92 if packages == []:
93 bb.debug(1, "No packages; nothing to do")
94 return
95
96 for pkg in packages.split():
97 localdata = bb.data.createCopy(d)
98 root = "%s/install/%s" % (workdir, pkg)
99
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)
103 if not pkgname:
104 pkgname = pkg
105 bb.data.setVar('PKG', pkgname, localdata)
106
107 overrides = bb.data.getVar('OVERRIDES', localdata)
108 if not overrides:
109 raise bb.build.FuncFailed('OVERRIDES not defined')
110 overrides = bb.data.expand(overrides, localdata)
111 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
112
113 bb.data.update_data(localdata)
114 basedir = os.path.join(os.path.dirname(root))
115
116 pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, 1))
117 bb.mkdirhier(pkgoutdir)
118
119 os.chdir(root)
120 from glob import glob
121 g = glob('*')
122 try:
123 del g[g.index('DEBIAN')]
124 del g[g.index('./DEBIAN')]
125 except ValueError:
126 pass
127 if not g and not bb.data.getVar('ALLOW_EMPTY', localdata):
128 from bb import note
129 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
130 continue
131 controldir = os.path.join(root, 'DEBIAN')
132 bb.mkdirhier(controldir)
133 try:
134 ctrlfile = file(os.path.join(controldir, 'control'), 'wb')
135 # import codecs
136 # ctrlfile = codecs.open("someFile", "w", "utf-8")
137 except OSError:
138 raise bb.build.FuncFailed("unable to open control file for writing.")
139
140 fields = []
141 fields.append(["Version: %s-%s\n", ['PV', 'PR']])
142 fields.append(["Description: %s\n", ['DESCRIPTION']])
143 fields.append(["Section: %s\n", ['SECTION']])
144 fields.append(["Priority: %s\n", ['PRIORITY']])
145 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
146 fields.append(["Architecture: %s\n", ['TARGET_ARCH']])
147 fields.append(["OE: %s\n", ['P']])
148 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
149
150# Package, Version, Maintainer, Description - mandatory
151# Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional
152
153
154 def pullData(l, d):
155 l2 = []
156 for i in l:
157 l2.append(bb.data.getVar(i, d, 1))
158 return l2
159
160 ctrlfile.write("Package: %s\n" % pkgname)
161 # check for required fields
162 try:
163 for (c, fs) in fields:
164 for f in fs:
165 if bb.data.getVar(f, localdata) is None:
166 raise KeyError(f)
167 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
168 except KeyError:
169 (type, value, traceback) = sys.exc_info()
170 ctrlfile.close()
171 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
172 # more fields
173
174 bb.build.exec_func("mapping_rename_hook", localdata)
175
176 rdepends = explode_deps(unicode(bb.data.getVar("RDEPENDS", localdata, 1) or ""))
177 rdepends = [dep for dep in rdepends if not '*' in dep]
178 rrecommends = explode_deps(unicode(bb.data.getVar("RRECOMMENDS", localdata, 1) or ""))
179 rrecommends = [rec for rec in rrecommends if not '*' in rec]
180 rsuggests = (unicode(bb.data.getVar("RSUGGESTS", localdata, 1) or "")).split()
181 rprovides = (unicode(bb.data.getVar("RPROVIDES", localdata, 1) or "")).split()
182 rreplaces = (unicode(bb.data.getVar("RREPLACES", localdata, 1) or "")).split()
183 rconflicts = (unicode(bb.data.getVar("RCONFLICTS", localdata, 1) or "")).split()
184 if rdepends:
185 ctrlfile.write(u"Depends: %s\n" % ", ".join(rdepends))
186 if rsuggests:
187 ctrlfile.write(u"Suggests: %s\n" % ", ".join(rsuggests))
188 if rrecommends:
189 ctrlfile.write(u"Recommends: %s\n" % ", ".join(rrecommends))
190 if rprovides:
191 ctrlfile.write(u"Provides: %s\n" % ", ".join(rprovides))
192 if rreplaces:
193 ctrlfile.write(u"Replaces: %s\n" % ", ".join(rreplaces))
194 if rconflicts:
195 ctrlfile.write(u"Conflicts: %s\n" % ", ".join(rconflicts))
196 ctrlfile.close()
197
198 for script in ["preinst", "postinst", "prerm", "postrm"]:
199 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
200 if not scriptvar:
201 continue
202 try:
203 scriptfile = file(os.path.join(controldir, script), 'w')
204 except OSError:
205 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
206 scriptfile.write(scriptvar)
207 scriptfile.close()
208 os.chmod(os.path.join(controldir, script), 0755)
209
210 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
211 if conffiles_str:
212 try:
213 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
214 except OSError:
215 raise bb.build.FuncFailed("unable to open conffiles for writing.")
216 for f in conffiles_str.split():
217 conffiles.write('%s\n' % f)
218 conffiles.close()
219
220 os.chdir(basedir)
221 ret = os.system("PATH=\"%s\" dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir))
222 if ret != 0:
223 raise bb.build.FuncFailed("dpkg-deb execution failed")
224
225 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
226 scriptfile = os.path.join(controldir, script)
227 try:
228 os.remove(scriptfile)
229 except OSError:
230 pass
231 try:
232 os.rmdir(controldir)
233 except OSError:
234 pass
235 del localdata
236}