blob: a1e51ee690829fa9d16e9ecab9a4b88e80e409f7 [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"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014OPKG_ARGS += "${@['', '--no-install-recommends'][d.getVar("NO_RECOMMENDATIONS") == "1"]}"
15OPKG_ARGS += "${@['', '--add-exclude ' + ' --add-exclude '.join((d.getVar('PACKAGE_EXCLUDE') or "").split())][(d.getVar("PACKAGE_EXCLUDE") or "") != ""]}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
17OPKGLIBDIR = "${localstatedir}/lib"
18
19python do_package_ipk () {
20 import re, copy
21 import textwrap
22 import subprocess
Patrick Williamsc0f7c042017-02-23 20:41:17 -060023 import collections
24
25 oldcwd = os.getcwd()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027 workdir = d.getVar('WORKDIR')
28 outdir = d.getVar('PKGWRITEDIRIPK')
29 tmpdir = d.getVar('TMPDIR')
30 pkgdest = d.getVar('PKGDEST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 if not workdir or not outdir or not tmpdir:
32 bb.error("Variables incorrectly set, unable to package")
33 return
34
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035 packages = d.getVar('PACKAGES')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036 if not packages or packages == '':
37 bb.debug(1, "No packages; nothing to do")
38 return
39
40 # We're about to add new packages so the index needs to be checked
41 # so remove the appropriate stamp file.
42 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
43 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
44
45 def cleanupcontrol(root):
46 for p in ['CONTROL', 'DEBIAN']:
47 p = os.path.join(root, p)
48 if os.path.exists(p):
49 bb.utils.prunedir(p)
50
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 recipesource = os.path.basename(d.getVar('FILE'))
Brad Bishop37a0e4d2017-12-04 01:01:44 -050052
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053 for pkg in packages.split():
54 localdata = bb.data.createCopy(d)
55 root = "%s/%s" % (pkgdest, pkg)
56
57 lf = bb.utils.lockfile(root + ".lock")
58
59 localdata.setVar('ROOT', '')
60 localdata.setVar('ROOT_%s' % pkg, root)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050061 pkgname = localdata.getVar('PKG_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062 if not pkgname:
63 pkgname = pkg
64 localdata.setVar('PKG', pkgname)
65
66 localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg)
67
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068 basedir = os.path.join(os.path.dirname(root))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050069 arch = localdata.getVar('PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
71 if localdata.getVar('IPK_HIERARCHICAL_FEED', False) == "1":
72 # Spread packages across subdirectories so each isn't too crowded
73 if pkgname.startswith('lib'):
74 pkg_prefix = 'lib' + pkgname[3]
75 else:
76 pkg_prefix = pkgname[0]
77
78 # Keep -dbg, -dev, -doc, -staticdev, -locale and -locale-* packages
79 # together. These package suffixes are taken from the definitions of
80 # PACKAGES and PACKAGES_DYNAMIC in meta/conf/bitbake.conf
81 if pkgname[-4:] in ('-dbg', '-dev', '-doc'):
82 pkg_subdir = pkgname[:-4]
83 elif pkgname.endswith('-staticdev'):
84 pkg_subdir = pkgname[:-10]
85 elif pkgname.endswith('-locale'):
86 pkg_subdir = pkgname[:-7]
87 elif '-locale-' in pkgname:
88 pkg_subdir = pkgname[:pkgname.find('-locale-')]
89 else:
90 pkg_subdir = pkgname
91
92 pkgoutdir = "%s/%s/%s/%s" % (outdir, arch, pkg_prefix, pkg_subdir)
93 else:
94 pkgoutdir = "%s/%s" % (outdir, arch)
95
96 bb.utils.mkdirhier(pkgoutdir)
97 os.chdir(root)
98 cleanupcontrol(root)
99 from glob import glob
100 g = glob('*')
101 if not g and localdata.getVar('ALLOW_EMPTY', False) != "1":
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500102 bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV'), localdata.getVar('PKGR')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103 bb.utils.unlockfile(lf)
104 continue
105
106 controldir = os.path.join(root, 'CONTROL')
107 bb.utils.mkdirhier(controldir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500108 ctrlfile = open(os.path.join(controldir, 'control'), 'w')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109
110 fields = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500111 pe = d.getVar('PKGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 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']])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500123 if d.getVar('HOMEPAGE'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500124 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
125
126 def pullData(l, d):
127 l2 = []
128 for i in l:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500129 l2.append(d.getVar(i))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 return l2
131
132 ctrlfile.write("Package: %s\n" % pkgname)
133 # check for required fields
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500134 for (c, fs) in fields:
135 for f in fs:
136 if localdata.getVar(f, False) is None:
137 raise KeyError(f)
138 # Special behavior for description...
139 if 'DESCRIPTION' in fs:
140 summary = localdata.getVar('SUMMARY') or localdata.getVar('DESCRIPTION') or "."
141 ctrlfile.write('Description: %s\n' % summary)
142 description = localdata.getVar('DESCRIPTION') or "."
143 description = textwrap.dedent(description).strip()
144 if '\\n' in description:
145 # Manually indent
146 for t in description.split('\\n'):
147 # We don't limit the width when manually indent, but we do
148 # need the textwrap.fill() to set the initial_indent and
149 # subsequent_indent, so set a large width
150 line = textwrap.fill(t.strip(),
151 width=100000,
152 initial_indent=' ',
153 subsequent_indent=' ') or '.'
154 ctrlfile.write('%s\n' % line)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500156 # Auto indent
157 ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' '))
158 else:
159 ctrlfile.write(c % tuple(pullData(fs, localdata)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160 # more fields
161
162 custom_fields_chunk = get_package_additional_metadata("ipk", localdata)
163 if custom_fields_chunk is not None:
164 ctrlfile.write(custom_fields_chunk)
165 ctrlfile.write("\n")
166
167 mapping_rename_hook(localdata)
168
169 def debian_cmp_remap(var):
170 # In debian '>' and '<' do not mean what it appears they mean
171 # '<' = less or equal
172 # '>' = greater or equal
173 # adjust these to the '<<' and '>>' equivalents
174 #
175 for dep in var:
176 for i, v in enumerate(var[dep]):
177 if (v or "").startswith("< "):
178 var[dep][i] = var[dep][i].replace("< ", "<< ")
179 elif (v or "").startswith("> "):
180 var[dep][i] = var[dep][i].replace("> ", ">> ")
181
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500182 rdepends = bb.utils.explode_dep_versions2(localdata.getVar("RDEPENDS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183 debian_cmp_remap(rdepends)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500184 rrecommends = bb.utils.explode_dep_versions2(localdata.getVar("RRECOMMENDS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500185 debian_cmp_remap(rrecommends)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500186 rsuggests = bb.utils.explode_dep_versions2(localdata.getVar("RSUGGESTS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187 debian_cmp_remap(rsuggests)
188 # Deliberately drop version information here, not wanted/supported by ipk
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500189 rprovides = dict.fromkeys(bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES") or ""), [])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600190 rprovides = collections.OrderedDict(sorted(rprovides.items(), key=lambda x: x[0]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 debian_cmp_remap(rprovides)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500192 rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193 debian_cmp_remap(rreplaces)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500194 rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500195 debian_cmp_remap(rconflicts)
196
197 if rdepends:
198 ctrlfile.write("Depends: %s\n" % bb.utils.join_deps(rdepends))
199 if rsuggests:
200 ctrlfile.write("Suggests: %s\n" % bb.utils.join_deps(rsuggests))
201 if rrecommends:
202 ctrlfile.write("Recommends: %s\n" % bb.utils.join_deps(rrecommends))
203 if rprovides:
204 ctrlfile.write("Provides: %s\n" % bb.utils.join_deps(rprovides))
205 if rreplaces:
206 ctrlfile.write("Replaces: %s\n" % bb.utils.join_deps(rreplaces))
207 if rconflicts:
208 ctrlfile.write("Conflicts: %s\n" % bb.utils.join_deps(rconflicts))
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500209 ctrlfile.write("Source: %s\n" % recipesource)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210 ctrlfile.close()
211
212 for script in ["preinst", "postinst", "prerm", "postrm"]:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500213 scriptvar = localdata.getVar('pkg_%s' % script)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500214 if not scriptvar:
215 continue
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 scriptfile = open(os.path.join(controldir, script), 'w')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217 scriptfile.write(scriptvar)
218 scriptfile.close()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600219 os.chmod(os.path.join(controldir, script), 0o755)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220
221 conffiles_str = ' '.join(get_conffiles(pkg, d))
222 if conffiles_str:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500223 conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224 for f in conffiles_str.split():
225 if os.path.exists(oe.path.join(root, f)):
226 conffiles.write('%s\n' % f)
227 conffiles.close()
228
229 os.chdir(basedir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500230 subprocess.check_output("PATH=\"%s\" %s %s %s" % (localdata.getVar("PATH"),
231 d.getVar("OPKGBUILDCMD"), pkg, pkgoutdir), shell=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500233 if d.getVar('IPK_SIGN_PACKAGES') == '1':
234 ipkver = "%s-%s" % (d.getVar('PKGV'), d.getVar('PKGR'))
235 ipk_to_sign = "%s/%s_%s_%s.ipk" % (pkgoutdir, pkgname, ipkver, d.getVar('PACKAGE_ARCH'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500236 sign_ipk(d, ipk_to_sign)
237
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 cleanupcontrol(root)
239 bb.utils.unlockfile(lf)
240
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600241 os.chdir(oldcwd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500242}
243# Otherwise allarch packages may change depending on override configuration
244do_package_ipk[vardepsexclude] = "OVERRIDES"
245
246SSTATETASKS += "do_package_write_ipk"
247do_package_write_ipk[sstate-inputdirs] = "${PKGWRITEDIRIPK}"
248do_package_write_ipk[sstate-outputdirs] = "${DEPLOY_DIR_IPK}"
249
250python do_package_write_ipk_setscene () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500251 tmpdir = d.getVar('TMPDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500252
253 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
254 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
255
256 sstate_setscene(d)
257}
258addtask do_package_write_ipk_setscene
259
260python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500261 if d.getVar('PACKAGES') != '':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262 deps = ' opkg-utils-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot'
263 d.appendVarFlag('do_package_write_ipk', 'depends', deps)
264 d.setVarFlag('do_package_write_ipk', 'fakeroot', "1")
265}
266
267python do_package_write_ipk () {
268 bb.build.exec_func("read_subpackage_metadata", d)
269 bb.build.exec_func("do_package_ipk", d)
270}
271do_package_write_ipk[dirs] = "${PKGWRITEDIRIPK}"
272do_package_write_ipk[cleandirs] = "${PKGWRITEDIRIPK}"
273do_package_write_ipk[umask] = "022"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500274do_package_write_ipk[depends] += "${@oe.utils.build_depends_string(d.getVar('PACKAGE_WRITE_DEPS'), 'do_populate_sysroot')}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500275addtask package_write_ipk after do_packagedata do_package
276
277PACKAGEINDEXDEPS += "opkg-utils-native:do_populate_sysroot"
278PACKAGEINDEXDEPS += "opkg-native:do_populate_sysroot"
279
280do_build[recrdeptask] += "do_package_write_ipk"