diff options
Diffstat (limited to 'meta/classes/package_ipk.bbclass')
| -rw-r--r-- | meta/classes/package_ipk.bbclass | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass new file mode 100644 index 0000000000..2949d1d2e0 --- /dev/null +++ b/meta/classes/package_ipk.bbclass | |||
| @@ -0,0 +1,261 @@ | |||
| 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 | |||
| 13 | OPKG_ARGS = "--force_postinstall --prefer-arch-to-version" | ||
| 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 | ||
| 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', 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 | pkgoutdir = "%s/%s" % (outdir, arch) | ||
| 67 | bb.utils.mkdirhier(pkgoutdir) | ||
| 68 | os.chdir(root) | ||
| 69 | cleanupcontrol(root) | ||
| 70 | from glob import glob | ||
| 71 | g = glob('*') | ||
| 72 | if not g and localdata.getVar('ALLOW_EMPTY') != "1": | ||
| 73 | bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV', True), localdata.getVar('PKGR', True))) | ||
| 74 | bb.utils.unlockfile(lf) | ||
| 75 | continue | ||
| 76 | |||
| 77 | controldir = os.path.join(root, 'CONTROL') | ||
| 78 | bb.utils.mkdirhier(controldir) | ||
| 79 | try: | ||
| 80 | ctrlfile = open(os.path.join(controldir, 'control'), 'w') | ||
| 81 | except OSError: | ||
| 82 | bb.utils.unlockfile(lf) | ||
| 83 | raise bb.build.FuncFailed("unable to open control file for writing.") | ||
| 84 | |||
| 85 | fields = [] | ||
| 86 | pe = d.getVar('PKGE', True) | ||
| 87 | if pe and int(pe) > 0: | ||
| 88 | fields.append(["Version: %s:%s-%s\n", ['PKGE', 'PKGV', 'PKGR']]) | ||
| 89 | else: | ||
| 90 | fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']]) | ||
| 91 | fields.append(["Description: %s\n", ['DESCRIPTION']]) | ||
| 92 | fields.append(["Section: %s\n", ['SECTION']]) | ||
| 93 | fields.append(["Priority: %s\n", ['PRIORITY']]) | ||
| 94 | fields.append(["Maintainer: %s\n", ['MAINTAINER']]) | ||
| 95 | fields.append(["License: %s\n", ['LICENSE']]) | ||
| 96 | fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']]) | ||
| 97 | fields.append(["OE: %s\n", ['PN']]) | ||
| 98 | if d.getVar('HOMEPAGE', True): | ||
| 99 | fields.append(["Homepage: %s\n", ['HOMEPAGE']]) | ||
| 100 | |||
| 101 | def pullData(l, d): | ||
| 102 | l2 = [] | ||
| 103 | for i in l: | ||
| 104 | l2.append(d.getVar(i, True)) | ||
| 105 | return l2 | ||
| 106 | |||
| 107 | ctrlfile.write("Package: %s\n" % pkgname) | ||
| 108 | # check for required fields | ||
| 109 | try: | ||
| 110 | for (c, fs) in fields: | ||
| 111 | for f in fs: | ||
| 112 | if localdata.getVar(f) is None: | ||
| 113 | raise KeyError(f) | ||
| 114 | # Special behavior for description... | ||
| 115 | if 'DESCRIPTION' in fs: | ||
| 116 | summary = localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or "." | ||
| 117 | ctrlfile.write('Description: %s\n' % summary) | ||
| 118 | description = localdata.getVar('DESCRIPTION', True) or "." | ||
| 119 | description = textwrap.dedent(description).strip() | ||
| 120 | if '\\n' in description: | ||
| 121 | # Manually indent | ||
| 122 | for t in description.split('\\n'): | ||
| 123 | # We don't limit the width when manually indent, but we do | ||
| 124 | # need the textwrap.fill() to set the initial_indent and | ||
| 125 | # subsequent_indent, so set a large width | ||
| 126 | ctrlfile.write('%s\n' % textwrap.fill(t.strip(), width=100000, initial_indent=' ', subsequent_indent=' ')) | ||
| 127 | else: | ||
| 128 | # Auto indent | ||
| 129 | ctrlfile.write('%s\n' % textwrap.fill(description, width=74, initial_indent=' ', subsequent_indent=' ')) | ||
| 130 | else: | ||
| 131 | ctrlfile.write(c % tuple(pullData(fs, localdata))) | ||
| 132 | except KeyError: | ||
| 133 | import sys | ||
| 134 | (type, value, traceback) = sys.exc_info() | ||
| 135 | ctrlfile.close() | ||
| 136 | bb.utils.unlockfile(lf) | ||
| 137 | raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value) | ||
| 138 | # more fields | ||
| 139 | |||
| 140 | custom_fields_chunk = get_package_additional_metadata("ipk", localdata) | ||
| 141 | if custom_fields_chunk is not None: | ||
| 142 | ctrlfile.write(custom_fields_chunk) | ||
| 143 | ctrlfile.write("\n") | ||
| 144 | |||
| 145 | mapping_rename_hook(localdata) | ||
| 146 | |||
| 147 | def debian_cmp_remap(var): | ||
| 148 | # In debian '>' and '<' do not mean what it appears they mean | ||
| 149 | # '<' = less or equal | ||
| 150 | # '>' = greater or equal | ||
| 151 | # adjust these to the '<<' and '>>' equivalents | ||
| 152 | # | ||
| 153 | for dep in var: | ||
| 154 | for i, v in enumerate(var[dep]): | ||
| 155 | if (v or "").startswith("< "): | ||
| 156 | var[dep][i] = var[dep][i].replace("< ", "<< ") | ||
| 157 | elif (v or "").startswith("> "): | ||
| 158 | var[dep][i] = var[dep][i].replace("> ", ">> ") | ||
| 159 | |||
| 160 | rdepends = bb.utils.explode_dep_versions2(localdata.getVar("RDEPENDS", True) or "") | ||
| 161 | debian_cmp_remap(rdepends) | ||
| 162 | rrecommends = bb.utils.explode_dep_versions2(localdata.getVar("RRECOMMENDS", True) or "") | ||
| 163 | debian_cmp_remap(rrecommends) | ||
| 164 | rsuggests = bb.utils.explode_dep_versions2(localdata.getVar("RSUGGESTS", True) or "") | ||
| 165 | debian_cmp_remap(rsuggests) | ||
| 166 | rprovides = bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES", True) or "") | ||
| 167 | debian_cmp_remap(rprovides) | ||
| 168 | rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES", True) or "") | ||
| 169 | debian_cmp_remap(rreplaces) | ||
| 170 | rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS", True) or "") | ||
| 171 | debian_cmp_remap(rconflicts) | ||
| 172 | |||
| 173 | if rdepends: | ||
| 174 | ctrlfile.write("Depends: %s\n" % bb.utils.join_deps(rdepends)) | ||
| 175 | if rsuggests: | ||
| 176 | ctrlfile.write("Suggests: %s\n" % bb.utils.join_deps(rsuggests)) | ||
| 177 | if rrecommends: | ||
| 178 | ctrlfile.write("Recommends: %s\n" % bb.utils.join_deps(rrecommends)) | ||
| 179 | if rprovides: | ||
| 180 | ctrlfile.write("Provides: %s\n" % bb.utils.join_deps(rprovides)) | ||
| 181 | if rreplaces: | ||
| 182 | ctrlfile.write("Replaces: %s\n" % bb.utils.join_deps(rreplaces)) | ||
| 183 | if rconflicts: | ||
| 184 | ctrlfile.write("Conflicts: %s\n" % bb.utils.join_deps(rconflicts)) | ||
| 185 | src_uri = localdata.getVar("SRC_URI", True) or "None" | ||
| 186 | if src_uri: | ||
| 187 | src_uri = re.sub("\s+", " ", src_uri) | ||
| 188 | ctrlfile.write("Source: %s\n" % " ".join(src_uri.split())) | ||
| 189 | ctrlfile.close() | ||
| 190 | |||
| 191 | for script in ["preinst", "postinst", "prerm", "postrm"]: | ||
| 192 | scriptvar = localdata.getVar('pkg_%s' % script, True) | ||
| 193 | if not scriptvar: | ||
| 194 | continue | ||
| 195 | try: | ||
| 196 | scriptfile = open(os.path.join(controldir, script), 'w') | ||
| 197 | except OSError: | ||
| 198 | bb.utils.unlockfile(lf) | ||
| 199 | raise bb.build.FuncFailed("unable to open %s script file for writing." % script) | ||
| 200 | scriptfile.write(scriptvar) | ||
| 201 | scriptfile.close() | ||
| 202 | os.chmod(os.path.join(controldir, script), 0755) | ||
| 203 | |||
| 204 | conffiles_str = localdata.getVar("CONFFILES", True) | ||
| 205 | if conffiles_str: | ||
| 206 | try: | ||
| 207 | conffiles = open(os.path.join(controldir, 'conffiles'), 'w') | ||
| 208 | except OSError: | ||
| 209 | bb.utils.unlockfile(lf) | ||
| 210 | raise bb.build.FuncFailed("unable to open conffiles for writing.") | ||
| 211 | for f in conffiles_str.split(): | ||
| 212 | if os.path.exists(oe.path.join(root, f)): | ||
| 213 | conffiles.write('%s\n' % f) | ||
| 214 | conffiles.close() | ||
| 215 | |||
| 216 | os.chdir(basedir) | ||
| 217 | ret = subprocess.call("PATH=\"%s\" %s %s %s" % (localdata.getVar("PATH", True), | ||
| 218 | d.getVar("OPKGBUILDCMD",1), pkg, pkgoutdir), shell=True) | ||
| 219 | if ret != 0: | ||
| 220 | bb.utils.unlockfile(lf) | ||
| 221 | raise bb.build.FuncFailed("opkg-build execution failed") | ||
| 222 | |||
| 223 | cleanupcontrol(root) | ||
| 224 | bb.utils.unlockfile(lf) | ||
| 225 | |||
| 226 | } | ||
| 227 | |||
| 228 | SSTATETASKS += "do_package_write_ipk" | ||
| 229 | do_package_write_ipk[sstate-inputdirs] = "${PKGWRITEDIRIPK}" | ||
| 230 | do_package_write_ipk[sstate-outputdirs] = "${DEPLOY_DIR_IPK}" | ||
| 231 | |||
| 232 | python do_package_write_ipk_setscene () { | ||
| 233 | tmpdir = d.getVar('TMPDIR', True) | ||
| 234 | |||
| 235 | if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK): | ||
| 236 | os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN")) | ||
| 237 | |||
| 238 | sstate_setscene(d) | ||
| 239 | } | ||
| 240 | addtask do_package_write_ipk_setscene | ||
| 241 | |||
| 242 | python () { | ||
| 243 | if d.getVar('PACKAGES', True) != '': | ||
| 244 | deps = ' opkg-utils-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot' | ||
| 245 | d.appendVarFlag('do_package_write_ipk', 'depends', deps) | ||
| 246 | d.setVarFlag('do_package_write_ipk', 'fakeroot', "1") | ||
| 247 | } | ||
| 248 | |||
| 249 | python do_package_write_ipk () { | ||
| 250 | bb.build.exec_func("read_subpackage_metadata", d) | ||
| 251 | bb.build.exec_func("do_package_ipk", d) | ||
| 252 | } | ||
| 253 | do_package_write_ipk[dirs] = "${PKGWRITEDIRIPK}" | ||
| 254 | do_package_write_ipk[cleandirs] = "${PKGWRITEDIRIPK}" | ||
| 255 | do_package_write_ipk[umask] = "022" | ||
| 256 | addtask package_write_ipk after do_packagedata do_package | ||
| 257 | |||
| 258 | PACKAGEINDEXDEPS += "opkg-utils-native:do_populate_sysroot" | ||
| 259 | PACKAGEINDEXDEPS += "opkg-native:do_populate_sysroot" | ||
| 260 | |||
| 261 | do_build[recrdeptask] += "do_package_write_ipk" | ||
