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