blob: f1ad1d5c17ab2781c10e6d4b588e174313e1ffd0 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit 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
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050013OPKG_ARGS += "--force_postinstall --prefer-arch-to-version"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014OPKG_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', d.getVar("OVERRIDES", False) + ":" + 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', False) == "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', False) != "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, False) 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 # Deliberately drop version information here, not wanted/supported by ipk
192 rprovides = dict.fromkeys(bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES", True) or ""), [])
193 debian_cmp_remap(rprovides)
194 rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES", True) or "")
195 debian_cmp_remap(rreplaces)
196 rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS", True) or "")
197 debian_cmp_remap(rconflicts)
198
199 if rdepends:
200 ctrlfile.write("Depends: %s\n" % bb.utils.join_deps(rdepends))
201 if rsuggests:
202 ctrlfile.write("Suggests: %s\n" % bb.utils.join_deps(rsuggests))
203 if rrecommends:
204 ctrlfile.write("Recommends: %s\n" % bb.utils.join_deps(rrecommends))
205 if rprovides:
206 ctrlfile.write("Provides: %s\n" % bb.utils.join_deps(rprovides))
207 if rreplaces:
208 ctrlfile.write("Replaces: %s\n" % bb.utils.join_deps(rreplaces))
209 if rconflicts:
210 ctrlfile.write("Conflicts: %s\n" % bb.utils.join_deps(rconflicts))
211 src_uri = localdata.getVar("SRC_URI", True).strip() or "None"
212 if src_uri:
213 src_uri = re.sub("\s+", " ", src_uri)
214 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
215 ctrlfile.close()
216
217 for script in ["preinst", "postinst", "prerm", "postrm"]:
218 scriptvar = localdata.getVar('pkg_%s' % script, True)
219 if not scriptvar:
220 continue
221 try:
222 scriptfile = open(os.path.join(controldir, script), 'w')
223 except OSError:
224 bb.utils.unlockfile(lf)
225 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
226 scriptfile.write(scriptvar)
227 scriptfile.close()
228 os.chmod(os.path.join(controldir, script), 0755)
229
230 conffiles_str = ' '.join(get_conffiles(pkg, d))
231 if conffiles_str:
232 try:
233 conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
234 except OSError:
235 bb.utils.unlockfile(lf)
236 raise bb.build.FuncFailed("unable to open conffiles for writing.")
237 for f in conffiles_str.split():
238 if os.path.exists(oe.path.join(root, f)):
239 conffiles.write('%s\n' % f)
240 conffiles.close()
241
242 os.chdir(basedir)
243 ret = subprocess.call("PATH=\"%s\" %s %s %s" % (localdata.getVar("PATH", True),
244 d.getVar("OPKGBUILDCMD",1), pkg, pkgoutdir), shell=True)
245 if ret != 0:
246 bb.utils.unlockfile(lf)
247 raise bb.build.FuncFailed("opkg-build execution failed")
248
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500249 if d.getVar('IPK_SIGN_PACKAGES', True) == '1':
250 ipkver = "%s-%s" % (d.getVar('PKGV', True), d.getVar('PKGR', True))
251 ipk_to_sign = "%s/%s_%s_%s.ipk" % (pkgoutdir, pkgname, ipkver, d.getVar('PACKAGE_ARCH', True))
252 sign_ipk(d, ipk_to_sign)
253
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254 cleanupcontrol(root)
255 bb.utils.unlockfile(lf)
256
257}
258# Otherwise allarch packages may change depending on override configuration
259do_package_ipk[vardepsexclude] = "OVERRIDES"
260
261SSTATETASKS += "do_package_write_ipk"
262do_package_write_ipk[sstate-inputdirs] = "${PKGWRITEDIRIPK}"
263do_package_write_ipk[sstate-outputdirs] = "${DEPLOY_DIR_IPK}"
264
265python do_package_write_ipk_setscene () {
266 tmpdir = d.getVar('TMPDIR', True)
267
268 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
269 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
270
271 sstate_setscene(d)
272}
273addtask do_package_write_ipk_setscene
274
275python () {
276 if d.getVar('PACKAGES', True) != '':
277 deps = ' opkg-utils-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot'
278 d.appendVarFlag('do_package_write_ipk', 'depends', deps)
279 d.setVarFlag('do_package_write_ipk', 'fakeroot', "1")
280}
281
282python do_package_write_ipk () {
283 bb.build.exec_func("read_subpackage_metadata", d)
284 bb.build.exec_func("do_package_ipk", d)
285}
286do_package_write_ipk[dirs] = "${PKGWRITEDIRIPK}"
287do_package_write_ipk[cleandirs] = "${PKGWRITEDIRIPK}"
288do_package_write_ipk[umask] = "022"
289addtask package_write_ipk after do_packagedata do_package
290
291PACKAGEINDEXDEPS += "opkg-utils-native:do_populate_sysroot"
292PACKAGEINDEXDEPS += "opkg-native:do_populate_sysroot"
293
294do_build[recrdeptask] += "do_package_write_ipk"