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" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | OPKG_ARGS += "${@['', '--no-install-recommends'][d.getVar("NO_RECOMMENDATIONS") == "1"]}" |
| 15 | OPKG_ARGS += "${@['', '--add-exclude ' + ' --add-exclude '.join((d.getVar('PACKAGE_EXCLUDE') or "").split())][(d.getVar("PACKAGE_EXCLUDE") or "") != ""]}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | workdir = d.getVar('WORKDIR') |
| 28 | outdir = d.getVar('PKGWRITEDIRIPK') |
| 29 | tmpdir = d.getVar('TMPDIR') |
| 30 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | if not workdir or not outdir or not tmpdir: |
| 32 | bb.error("Variables incorrectly set, unable to package") |
| 33 | return |
| 34 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 35 | packages = d.getVar('PACKAGES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | recipesource = os.path.basename(d.getVar('FILE')) |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 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) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 61 | pkgname = localdata.getVar('PKG_%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | if not pkgname: |
| 63 | pkgname = pkg |
| 64 | localdata.setVar('PKG', pkgname) |
| 65 | |
| 66 | localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg) |
| 67 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 | basedir = os.path.join(os.path.dirname(root)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 69 | arch = localdata.getVar('PACKAGE_ARCH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | |
| 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 102 | bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV'), localdata.getVar('PKGR'))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | bb.utils.unlockfile(lf) |
| 104 | continue |
| 105 | |
| 106 | controldir = os.path.join(root, 'CONTROL') |
| 107 | bb.utils.mkdirhier(controldir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 108 | ctrlfile = open(os.path.join(controldir, 'control'), 'w') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | |
| 110 | fields = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 111 | pe = d.getVar('PKGE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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']]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 123 | if d.getVar('HOMEPAGE'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | fields.append(["Homepage: %s\n", ['HOMEPAGE']]) |
| 125 | |
| 126 | def pullData(l, d): |
| 127 | l2 = [] |
| 128 | for i in l: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 129 | l2.append(d.getVar(i)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | return l2 |
| 131 | |
| 132 | ctrlfile.write("Package: %s\n" % pkgname) |
| 133 | # check for required fields |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 134 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 156 | # 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 160 | # 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 182 | rdepends = bb.utils.explode_dep_versions2(localdata.getVar("RDEPENDS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | debian_cmp_remap(rdepends) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 184 | rrecommends = bb.utils.explode_dep_versions2(localdata.getVar("RRECOMMENDS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 185 | debian_cmp_remap(rrecommends) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 186 | rsuggests = bb.utils.explode_dep_versions2(localdata.getVar("RSUGGESTS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | debian_cmp_remap(rsuggests) |
| 188 | # Deliberately drop version information here, not wanted/supported by ipk |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 189 | rprovides = dict.fromkeys(bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES") or ""), []) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 190 | rprovides = collections.OrderedDict(sorted(rprovides.items(), key=lambda x: x[0])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | debian_cmp_remap(rprovides) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 192 | rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 193 | debian_cmp_remap(rreplaces) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 194 | rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 195 | 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 Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 209 | ctrlfile.write("Source: %s\n" % recipesource) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 210 | ctrlfile.close() |
| 211 | |
| 212 | for script in ["preinst", "postinst", "prerm", "postrm"]: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 213 | scriptvar = localdata.getVar('pkg_%s' % script) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | if not scriptvar: |
| 215 | continue |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 216 | scriptfile = open(os.path.join(controldir, script), 'w') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 217 | scriptfile.write(scriptvar) |
| 218 | scriptfile.close() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 219 | os.chmod(os.path.join(controldir, script), 0o755) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | |
| 221 | conffiles_str = ' '.join(get_conffiles(pkg, d)) |
| 222 | if conffiles_str: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 223 | conffiles = open(os.path.join(controldir, 'conffiles'), 'w') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 230 | subprocess.check_output("PATH=\"%s\" %s %s %s" % (localdata.getVar("PATH"), |
| 231 | d.getVar("OPKGBUILDCMD"), pkg, pkgoutdir), shell=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 232 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 233 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 236 | sign_ipk(d, ipk_to_sign) |
| 237 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | cleanupcontrol(root) |
| 239 | bb.utils.unlockfile(lf) |
| 240 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 241 | os.chdir(oldcwd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 242 | } |
| 243 | # Otherwise allarch packages may change depending on override configuration |
| 244 | do_package_ipk[vardepsexclude] = "OVERRIDES" |
| 245 | |
| 246 | SSTATETASKS += "do_package_write_ipk" |
| 247 | do_package_write_ipk[sstate-inputdirs] = "${PKGWRITEDIRIPK}" |
| 248 | do_package_write_ipk[sstate-outputdirs] = "${DEPLOY_DIR_IPK}" |
| 249 | |
| 250 | python do_package_write_ipk_setscene () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 251 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | |
| 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 | } |
| 258 | addtask do_package_write_ipk_setscene |
| 259 | |
| 260 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 261 | if d.getVar('PACKAGES') != '': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | 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 | |
| 267 | python do_package_write_ipk () { |
| 268 | bb.build.exec_func("read_subpackage_metadata", d) |
| 269 | bb.build.exec_func("do_package_ipk", d) |
| 270 | } |
| 271 | do_package_write_ipk[dirs] = "${PKGWRITEDIRIPK}" |
| 272 | do_package_write_ipk[cleandirs] = "${PKGWRITEDIRIPK}" |
| 273 | do_package_write_ipk[umask] = "022" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 274 | do_package_write_ipk[depends] += "${@oe.utils.build_depends_string(d.getVar('PACKAGE_WRITE_DEPS'), 'do_populate_sysroot')}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | addtask package_write_ipk after do_packagedata do_package |
| 276 | |
| 277 | PACKAGEINDEXDEPS += "opkg-utils-native:do_populate_sysroot" |
| 278 | PACKAGEINDEXDEPS += "opkg-native:do_populate_sysroot" |
| 279 | |
| 280 | do_build[recrdeptask] += "do_package_write_ipk" |