blob: 5eb910ca3184178ffc83d8ad21efa854afdf8aed [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
Brad Bishop316dfdd2018-06-25 12:45:53 -040011OPKGBUILDCMD ??= "opkg-build -Z xz"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050013OPKG_ARGS += "--force_postinstall --prefer-arch-to-version"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014OPKG_ARGS += "${@['', '--no-install-recommends'][d.getVar("NO_RECOMMENDATIONS") == "1"]}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015OPKG_ARGS += "${@['', '--add-exclude ' + ' --add-exclude '.join((d.getVar('PACKAGE_EXCLUDE') or "").split())][(d.getVar("PACKAGE_EXCLUDE") or "").strip() != ""]}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
17OPKGLIBDIR = "${localstatedir}/lib"
18
19python do_package_ipk () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050020 workdir = d.getVar('WORKDIR')
21 outdir = d.getVar('PKGWRITEDIRIPK')
22 tmpdir = d.getVar('TMPDIR')
23 pkgdest = d.getVar('PKGDEST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024 if not workdir or not outdir or not tmpdir:
25 bb.error("Variables incorrectly set, unable to package")
26 return
27
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028 packages = d.getVar('PACKAGES')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 if not packages or packages == '':
30 bb.debug(1, "No packages; nothing to do")
31 return
32
33 # We're about to add new packages so the index needs to be checked
34 # so remove the appropriate stamp file.
35 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
36 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
37
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080038 oe.utils.multiprocess_launch(ipk_write_pkg, packages.split(), d, extraargs=(d,))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039}
40do_package_ipk[vardeps] += "ipk_write_pkg"
41do_package_ipk[vardepsexclude] = "BB_NUMBER_THREADS"
42
43def ipk_write_pkg(pkg, d):
44 import re, copy
45 import subprocess
46 import textwrap
47 import collections
48
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049 def cleanupcontrol(root):
50 for p in ['CONTROL', 'DEBIAN']:
51 p = os.path.join(root, p)
52 if os.path.exists(p):
53 bb.utils.prunedir(p)
54
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055 outdir = d.getVar('PKGWRITEDIRIPK')
56 pkgdest = d.getVar('PKGDEST')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057 recipesource = os.path.basename(d.getVar('FILE'))
Brad Bishop37a0e4d2017-12-04 01:01:44 -050058
Brad Bishopd7bf8c12018-02-25 22:55:05 -050059 localdata = bb.data.createCopy(d)
60 root = "%s/%s" % (pkgdest, pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061
Brad Bishopd7bf8c12018-02-25 22:55:05 -050062 lf = bb.utils.lockfile(root + ".lock")
63 try:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 localdata.setVar('ROOT', '')
65 localdata.setVar('ROOT_%s' % pkg, root)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050066 pkgname = localdata.getVar('PKG_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 if not pkgname:
68 pkgname = pkg
69 localdata.setVar('PKG', pkgname)
70
71 localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg)
72
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 basedir = os.path.join(os.path.dirname(root))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050074 arch = localdata.getVar('PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075
76 if localdata.getVar('IPK_HIERARCHICAL_FEED', False) == "1":
77 # Spread packages across subdirectories so each isn't too crowded
78 if pkgname.startswith('lib'):
79 pkg_prefix = 'lib' + pkgname[3]
80 else:
81 pkg_prefix = pkgname[0]
82
83 # Keep -dbg, -dev, -doc, -staticdev, -locale and -locale-* packages
84 # together. These package suffixes are taken from the definitions of
85 # PACKAGES and PACKAGES_DYNAMIC in meta/conf/bitbake.conf
86 if pkgname[-4:] in ('-dbg', '-dev', '-doc'):
87 pkg_subdir = pkgname[:-4]
88 elif pkgname.endswith('-staticdev'):
89 pkg_subdir = pkgname[:-10]
90 elif pkgname.endswith('-locale'):
91 pkg_subdir = pkgname[:-7]
92 elif '-locale-' in pkgname:
93 pkg_subdir = pkgname[:pkgname.find('-locale-')]
94 else:
95 pkg_subdir = pkgname
96
97 pkgoutdir = "%s/%s/%s/%s" % (outdir, arch, pkg_prefix, pkg_subdir)
98 else:
99 pkgoutdir = "%s/%s" % (outdir, arch)
100
101 bb.utils.mkdirhier(pkgoutdir)
102 os.chdir(root)
103 cleanupcontrol(root)
104 from glob import glob
105 g = glob('*')
106 if not g and localdata.getVar('ALLOW_EMPTY', False) != "1":
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500107 bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV'), localdata.getVar('PKGR')))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500108 return
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109
110 controldir = os.path.join(root, 'CONTROL')
111 bb.utils.mkdirhier(controldir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 ctrlfile = open(os.path.join(controldir, 'control'), 'w')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113
114 fields = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500115 pe = d.getVar('PKGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 if pe and int(pe) > 0:
117 fields.append(["Version: %s:%s-%s\n", ['PKGE', 'PKGV', 'PKGR']])
118 else:
119 fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']])
120 fields.append(["Description: %s\n", ['DESCRIPTION']])
121 fields.append(["Section: %s\n", ['SECTION']])
122 fields.append(["Priority: %s\n", ['PRIORITY']])
123 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
124 fields.append(["License: %s\n", ['LICENSE']])
125 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
126 fields.append(["OE: %s\n", ['PN']])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 if d.getVar('HOMEPAGE'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
129
130 def pullData(l, d):
131 l2 = []
132 for i in l:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500133 l2.append(d.getVar(i))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134 return l2
135
136 ctrlfile.write("Package: %s\n" % pkgname)
137 # check for required fields
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138 for (c, fs) in fields:
139 for f in fs:
140 if localdata.getVar(f, False) is None:
141 raise KeyError(f)
142 # Special behavior for description...
143 if 'DESCRIPTION' in fs:
144 summary = localdata.getVar('SUMMARY') or localdata.getVar('DESCRIPTION') or "."
145 ctrlfile.write('Description: %s\n' % summary)
146 description = localdata.getVar('DESCRIPTION') or "."
147 description = textwrap.dedent(description).strip()
148 if '\\n' in description:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500149 # Manually indent: multiline description includes a leading space
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500150 for t in description.split('\\n'):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500151 ctrlfile.write(' %s\n' % (t.strip() or ' .'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500153 # 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)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 # more fields
158
159 custom_fields_chunk = get_package_additional_metadata("ipk", localdata)
160 if custom_fields_chunk is not None:
161 ctrlfile.write(custom_fields_chunk)
162 ctrlfile.write("\n")
163
164 mapping_rename_hook(localdata)
165
166 def debian_cmp_remap(var):
167 # In debian '>' and '<' do not mean what it appears they mean
168 # '<' = less or equal
169 # '>' = greater or equal
170 # adjust these to the '<<' and '>>' equivalents
171 #
172 for dep in var:
173 for i, v in enumerate(var[dep]):
174 if (v or "").startswith("< "):
175 var[dep][i] = var[dep][i].replace("< ", "<< ")
176 elif (v or "").startswith("> "):
177 var[dep][i] = var[dep][i].replace("> ", ">> ")
178
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500179 rdepends = bb.utils.explode_dep_versions2(localdata.getVar("RDEPENDS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500180 debian_cmp_remap(rdepends)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181 rrecommends = bb.utils.explode_dep_versions2(localdata.getVar("RRECOMMENDS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182 debian_cmp_remap(rrecommends)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500183 rsuggests = bb.utils.explode_dep_versions2(localdata.getVar("RSUGGESTS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500184 debian_cmp_remap(rsuggests)
185 # Deliberately drop version information here, not wanted/supported by ipk
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500186 rprovides = dict.fromkeys(bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES") or ""), [])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600187 rprovides = collections.OrderedDict(sorted(rprovides.items(), key=lambda x: x[0]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500188 debian_cmp_remap(rprovides)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500189 rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190 debian_cmp_remap(rreplaces)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500191 rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500192 debian_cmp_remap(rconflicts)
193
194 if rdepends:
195 ctrlfile.write("Depends: %s\n" % bb.utils.join_deps(rdepends))
196 if rsuggests:
197 ctrlfile.write("Suggests: %s\n" % bb.utils.join_deps(rsuggests))
198 if rrecommends:
199 ctrlfile.write("Recommends: %s\n" % bb.utils.join_deps(rrecommends))
200 if rprovides:
201 ctrlfile.write("Provides: %s\n" % bb.utils.join_deps(rprovides))
202 if rreplaces:
203 ctrlfile.write("Replaces: %s\n" % bb.utils.join_deps(rreplaces))
204 if rconflicts:
205 ctrlfile.write("Conflicts: %s\n" % bb.utils.join_deps(rconflicts))
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500206 ctrlfile.write("Source: %s\n" % recipesource)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207 ctrlfile.close()
208
209 for script in ["preinst", "postinst", "prerm", "postrm"]:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500210 scriptvar = localdata.getVar('pkg_%s' % script)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500211 if not scriptvar:
212 continue
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500213 scriptfile = open(os.path.join(controldir, script), 'w')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500214 scriptfile.write(scriptvar)
215 scriptfile.close()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600216 os.chmod(os.path.join(controldir, script), 0o755)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217
218 conffiles_str = ' '.join(get_conffiles(pkg, d))
219 if conffiles_str:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500220 conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221 for f in conffiles_str.split():
222 if os.path.exists(oe.path.join(root, f)):
223 conffiles.write('%s\n' % f)
224 conffiles.close()
225
226 os.chdir(basedir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500227 subprocess.check_output("PATH=\"%s\" %s %s %s" % (localdata.getVar("PATH"),
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500228 d.getVar("OPKGBUILDCMD"), pkg, pkgoutdir),
229 stderr=subprocess.STDOUT,
230 shell=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500232 if d.getVar('IPK_SIGN_PACKAGES') == '1':
233 ipkver = "%s-%s" % (d.getVar('PKGV'), d.getVar('PKGR'))
234 ipk_to_sign = "%s/%s_%s_%s.ipk" % (pkgoutdir, pkgname, ipkver, d.getVar('PACKAGE_ARCH'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500235 sign_ipk(d, ipk_to_sign)
236
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500237 finally:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 cleanupcontrol(root)
239 bb.utils.unlockfile(lf)
240
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241# Otherwise allarch packages may change depending on override configuration
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500242ipk_write_pkg[vardepsexclude] = "OVERRIDES"
243
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244
245SSTATETASKS += "do_package_write_ipk"
246do_package_write_ipk[sstate-inputdirs] = "${PKGWRITEDIRIPK}"
247do_package_write_ipk[sstate-outputdirs] = "${DEPLOY_DIR_IPK}"
248
249python do_package_write_ipk_setscene () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500250 tmpdir = d.getVar('TMPDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251
252 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
253 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
254
255 sstate_setscene(d)
256}
257addtask do_package_write_ipk_setscene
258
259python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500260 if d.getVar('PACKAGES') != '':
Brad Bishop316dfdd2018-06-25 12:45:53 -0400261 deps = ' opkg-utils-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot xz-native:do_populate_sysroot'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262 d.appendVarFlag('do_package_write_ipk', 'depends', deps)
263 d.setVarFlag('do_package_write_ipk', 'fakeroot', "1")
264}
265
266python do_package_write_ipk () {
267 bb.build.exec_func("read_subpackage_metadata", d)
268 bb.build.exec_func("do_package_ipk", d)
269}
270do_package_write_ipk[dirs] = "${PKGWRITEDIRIPK}"
271do_package_write_ipk[cleandirs] = "${PKGWRITEDIRIPK}"
272do_package_write_ipk[umask] = "022"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500273do_package_write_ipk[depends] += "${@oe.utils.build_depends_string(d.getVar('PACKAGE_WRITE_DEPS'), 'do_populate_sysroot')}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500274addtask package_write_ipk after do_packagedata do_package
275
276PACKAGEINDEXDEPS += "opkg-utils-native:do_populate_sysroot"
277PACKAGEINDEXDEPS += "opkg-native:do_populate_sysroot"
278
279do_build[recrdeptask] += "do_package_write_ipk"