summaryrefslogtreecommitdiffstats
path: root/meta/classes/package_ipk.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/package_ipk.bbclass')
-rw-r--r--meta/classes/package_ipk.bbclass286
1 files changed, 286 insertions, 0 deletions
diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
new file mode 100644
index 0000000000..44fd3eb29c
--- /dev/null
+++ b/meta/classes/package_ipk.bbclass
@@ -0,0 +1,286 @@
1inherit package
2
3IMAGE_PKGTYPE ?= "ipk"
4
5IPKGCONF_TARGET = "${WORKDIR}/opkg.conf"
6IPKGCONF_SDK = "${WORKDIR}/opkg-sdk.conf"
7
8PKGWRITEDIRIPK = "${WORKDIR}/deploy-ipks"
9
10# Program to be used to build opkg packages
11OPKGBUILDCMD ??= "opkg-build"
12
13OPKG_ARGS = "--force_postinstall --prefer-arch-to-version"
14OPKG_ARGS += "${@['', '--no-install-recommends'][d.getVar("NO_RECOMMENDATIONS", True) == "1"]}"
15OPKG_ARGS += "${@['', '--add-exclude ' + ' --add-exclude '.join((d.getVar('PACKAGE_EXCLUDE', True) or "").split())][(d.getVar("PACKAGE_EXCLUDE", True) or "") != ""]}"
16
17OPKGLIBDIR = "${localstatedir}/lib"
18
19python do_package_ipk () {
20 import re, copy
21 import textwrap
22 import subprocess
23
24 workdir = d.getVar('WORKDIR', True)
25 outdir = d.getVar('PKGWRITEDIRIPK', True)
26 tmpdir = d.getVar('TMPDIR', True)
27 pkgdest = d.getVar('PKGDEST', True)
28 if not workdir or not outdir or not tmpdir:
29 bb.error("Variables incorrectly set, unable to package")
30 return
31
32 packages = d.getVar('PACKAGES', True)
33 if not packages or packages == '':
34 bb.debug(1, "No packages; nothing to do")
35 return
36
37 # We're about to add new packages so the index needs to be checked
38 # so remove the appropriate stamp file.
39 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
40 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
41
42 def cleanupcontrol(root):
43 for p in ['CONTROL', 'DEBIAN']:
44 p = os.path.join(root, p)
45 if os.path.exists(p):
46 bb.utils.prunedir(p)
47
48 for pkg in packages.split():
49 localdata = bb.data.createCopy(d)
50 root = "%s/%s" % (pkgdest, pkg)
51
52 lf = bb.utils.lockfile(root + ".lock")
53
54 localdata.setVar('ROOT', '')
55 localdata.setVar('ROOT_%s' % pkg, root)
56 pkgname = localdata.getVar('PKG_%s' % pkg, True)
57 if not pkgname:
58 pkgname = pkg
59 localdata.setVar('PKG', pkgname)
60
61 localdata.setVar('OVERRIDES', pkg)
62
63 bb.data.update_data(localdata)
64 basedir = os.path.join(os.path.dirname(root))
65 arch = localdata.getVar('PACKAGE_ARCH', True)
66
67 if localdata.getVar('IPK_HIERARCHICAL_FEED') == "1":
68 # Spread packages across subdirectories so each isn't too crowded
69 if pkgname.startswith('lib'):
70 pkg_prefix = 'lib' + pkgname[3]
71 else:
72 pkg_prefix = pkgname[0]
73
74 # Keep -dbg, -dev, -doc, -staticdev, -locale and -locale-* packages
75 # together. These package suffixes are taken from the definitions of
76 # PACKAGES and PACKAGES_DYNAMIC in meta/conf/bitbake.conf
77 if pkgname[-4:] in ('-dbg', '-dev', '-doc'):
78 pkg_subdir = pkgname[:-4]
79 elif pkgname.endswith('-staticdev'):
80 pkg_subdir = pkgname[:-10]
81 elif pkgname.endswith('-locale'):
82 pkg_subdir = pkgname[:-7]
83 elif '-locale-' in pkgname:
84 pkg_subdir = pkgname[:pkgname.find('-locale-')]
85 else:
86 pkg_subdir = pkgname
87
88 pkgoutdir = "%s/%s/%s/%s" % (outdir, arch, pkg_prefix, pkg_subdir)
89 else:
90 pkgoutdir = "%s/%s" % (outdir, arch)
91
92 bb.utils.mkdirhier(pkgoutdir)
93 os.chdir(root)
94 cleanupcontrol(root)
95 from glob import glob
96 g = glob('*')
97 if not g and localdata.getVar('ALLOW_EMPTY') != "1":
98 bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV', True), localdata.getVar('PKGR', True)))
99 bb.utils.unlockfile(lf)
100 continue
101
102 controldir = os.path.join(root, 'CONTROL')
103 bb.utils.mkdirhier(controldir)
104 try:
105 ctrlfile = open(os.path.join(controldir, 'control'), 'w')
106 except OSError:
107 bb.utils.unlockfile(lf)
108 raise bb.build.FuncFailed("unable to open control file for writing.")
109
110 fields = []
111 pe = d.getVar('PKGE', True)
112 if pe and int(pe) > 0:
113 fields.append(["Version: %s:%s-%s\n", ['PKGE', 'PKGV', 'PKGR']])
114 else:
115 fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']])
116 fields.append(["Description: %s\n", ['DESCRIPTION']])
117 fields.append(["Section: %s\n", ['SECTION']])
118 fields.append(["Priority: %s\n", ['PRIORITY']])
119 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
120 fields.append(["License: %s\n", ['LICENSE']])
121 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
122 fields.append(["OE: %s\n", ['PN']])
123 if d.getVar('HOMEPAGE', True):
124 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
125
126 def pullData(l, d):
127 l2 = []
128 for i in l:
129 l2.append(d.getVar(i, True))
130 return l2
131
132 ctrlfile.write("Package: %s\n" % pkgname)
133 # check for required fields
134 try:
135 for (c, fs) in fields:
136 for f in fs:
137 if localdata.getVar(f) is None:
138 raise KeyError(f)
139 # Special behavior for description...
140 if 'DESCRIPTION' in fs:
141 summary = localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or "."
142 ctrlfile.write('Description: %s\n' % summary)
143 description = localdata.getVar('DESCRIPTION', True) or "."
144 description = textwrap.dedent(description).strip()
145 if '\\n' in description:
146 # Manually indent
147 for t in description.split('\\n'):
148 # We don't limit the width when manually indent, but we do
149 # need the textwrap.fill() to set the initial_indent and
150 # subsequent_indent, so set a large width
151 ctrlfile.write('%s\n' % textwrap.fill(t.strip(), width=100000, initial_indent=' ', subsequent_indent=' '))
152 else:
153 # Auto indent
154 ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' '))
155 else:
156 ctrlfile.write(c % tuple(pullData(fs, localdata)))
157 except KeyError:
158 import sys
159 (type, value, traceback) = sys.exc_info()
160 ctrlfile.close()
161 bb.utils.unlockfile(lf)
162 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
163 # more fields
164
165 custom_fields_chunk = get_package_additional_metadata("ipk", localdata)
166 if custom_fields_chunk is not None:
167 ctrlfile.write(custom_fields_chunk)
168 ctrlfile.write("\n")
169
170 mapping_rename_hook(localdata)
171
172 def debian_cmp_remap(var):
173 # In debian '>' and '<' do not mean what it appears they mean
174 # '<' = less or equal
175 # '>' = greater or equal
176 # adjust these to the '<<' and '>>' equivalents
177 #
178 for dep in var:
179 for i, v in enumerate(var[dep]):
180 if (v or "").startswith("< "):
181 var[dep][i] = var[dep][i].replace("< ", "<< ")
182 elif (v or "").startswith("> "):
183 var[dep][i] = var[dep][i].replace("> ", ">> ")
184
185 rdepends = bb.utils.explode_dep_versions2(localdata.getVar("RDEPENDS", True) or "")
186 debian_cmp_remap(rdepends)
187 rrecommends = bb.utils.explode_dep_versions2(localdata.getVar("RRECOMMENDS", True) or "")
188 debian_cmp_remap(rrecommends)
189 rsuggests = bb.utils.explode_dep_versions2(localdata.getVar("RSUGGESTS", True) or "")
190 debian_cmp_remap(rsuggests)
191 rprovides = bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES", True) or "")
192 debian_cmp_remap(rprovides)
193 rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES", True) or "")
194 debian_cmp_remap(rreplaces)
195 rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS", True) or "")
196 debian_cmp_remap(rconflicts)
197
198 if rdepends:
199 ctrlfile.write("Depends: %s\n" % bb.utils.join_deps(rdepends))
200 if rsuggests:
201 ctrlfile.write("Suggests: %s\n" % bb.utils.join_deps(rsuggests))
202 if rrecommends:
203 ctrlfile.write("Recommends: %s\n" % bb.utils.join_deps(rrecommends))
204 if rprovides:
205 ctrlfile.write("Provides: %s\n" % bb.utils.join_deps(rprovides))
206 if rreplaces:
207 ctrlfile.write("Replaces: %s\n" % bb.utils.join_deps(rreplaces))
208 if rconflicts:
209 ctrlfile.write("Conflicts: %s\n" % bb.utils.join_deps(rconflicts))
210 src_uri = localdata.getVar("SRC_URI", True).strip() or "None"
211 if src_uri:
212 src_uri = re.sub("\s+", " ", src_uri)
213 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
214 ctrlfile.close()
215
216 for script in ["preinst", "postinst", "prerm", "postrm"]:
217 scriptvar = localdata.getVar('pkg_%s' % script, True)
218 if not scriptvar:
219 continue
220 try:
221 scriptfile = open(os.path.join(controldir, script), 'w')
222 except OSError:
223 bb.utils.unlockfile(lf)
224 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
225 scriptfile.write(scriptvar)
226 scriptfile.close()
227 os.chmod(os.path.join(controldir, script), 0755)
228
229 conffiles_str = localdata.getVar("CONFFILES", True)
230 if conffiles_str:
231 try:
232 conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
233 except OSError:
234 bb.utils.unlockfile(lf)
235 raise bb.build.FuncFailed("unable to open conffiles for writing.")
236 for f in conffiles_str.split():
237 if os.path.exists(oe.path.join(root, f)):
238 conffiles.write('%s\n' % f)
239 conffiles.close()
240
241 os.chdir(basedir)
242 ret = subprocess.call("PATH=\"%s\" %s %s %s" % (localdata.getVar("PATH", True),
243 d.getVar("OPKGBUILDCMD",1), pkg, pkgoutdir), shell=True)
244 if ret != 0:
245 bb.utils.unlockfile(lf)
246 raise bb.build.FuncFailed("opkg-build execution failed")
247
248 cleanupcontrol(root)
249 bb.utils.unlockfile(lf)
250
251}
252
253SSTATETASKS += "do_package_write_ipk"
254do_package_write_ipk[sstate-inputdirs] = "${PKGWRITEDIRIPK}"
255do_package_write_ipk[sstate-outputdirs] = "${DEPLOY_DIR_IPK}"
256
257python do_package_write_ipk_setscene () {
258 tmpdir = d.getVar('TMPDIR', True)
259
260 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
261 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
262
263 sstate_setscene(d)
264}
265addtask do_package_write_ipk_setscene
266
267python () {
268 if d.getVar('PACKAGES', True) != '':
269 deps = ' opkg-utils-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot'
270 d.appendVarFlag('do_package_write_ipk', 'depends', deps)
271 d.setVarFlag('do_package_write_ipk', 'fakeroot', "1")
272}
273
274python do_package_write_ipk () {
275 bb.build.exec_func("read_subpackage_metadata", d)
276 bb.build.exec_func("do_package_ipk", d)
277}
278do_package_write_ipk[dirs] = "${PKGWRITEDIRIPK}"
279do_package_write_ipk[cleandirs] = "${PKGWRITEDIRIPK}"
280do_package_write_ipk[umask] = "022"
281addtask package_write_ipk after do_packagedata do_package
282
283PACKAGEINDEXDEPS += "opkg-utils-native:do_populate_sysroot"
284PACKAGEINDEXDEPS += "opkg-native:do_populate_sysroot"
285
286do_build[recrdeptask] += "do_package_write_ipk"