diff options
| author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
|---|---|---|
| committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
| commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
| tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /meta/classes/package_deb.bbclass | |
| download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz | |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/classes/package_deb.bbclass')
| -rw-r--r-- | meta/classes/package_deb.bbclass | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/meta/classes/package_deb.bbclass b/meta/classes/package_deb.bbclass new file mode 100644 index 0000000000..5b5f7e2c9a --- /dev/null +++ b/meta/classes/package_deb.bbclass | |||
| @@ -0,0 +1,330 @@ | |||
| 1 | # | ||
| 2 | # Copyright 2006-2008 OpenedHand Ltd. | ||
| 3 | # | ||
| 4 | |||
| 5 | inherit package | ||
| 6 | |||
| 7 | IMAGE_PKGTYPE ?= "deb" | ||
| 8 | |||
| 9 | DPKG_ARCH ?= "${TARGET_ARCH}" | ||
| 10 | |||
| 11 | PKGWRITEDIRDEB = "${WORKDIR}/deploy-debs" | ||
| 12 | |||
| 13 | APTCONF_TARGET = "${WORKDIR}" | ||
| 14 | |||
| 15 | APT_ARGS = "${@['', '--no-install-recommends'][d.getVar("NO_RECOMMENDATIONS", True) == "1"]}" | ||
| 16 | |||
| 17 | # | ||
| 18 | # install a bunch of packages using apt | ||
| 19 | # the following shell variables needs to be set before calling this func: | ||
| 20 | # INSTALL_ROOTFS_DEB - install root dir | ||
| 21 | # INSTALL_BASEARCH_DEB - install base architecutre | ||
| 22 | # INSTALL_ARCHS_DEB - list of available archs | ||
| 23 | # INSTALL_PACKAGES_NORMAL_DEB - packages to be installed | ||
| 24 | # INSTALL_PACKAGES_ATTEMPTONLY_DEB - packages attemped to be installed only | ||
| 25 | # INSTALL_PACKAGES_LINGUAS_DEB - additional packages for uclibc | ||
| 26 | # INSTALL_TASK_DEB - task name | ||
| 27 | |||
| 28 | python do_package_deb () { | ||
| 29 | import re, copy | ||
| 30 | import textwrap | ||
| 31 | import subprocess | ||
| 32 | |||
| 33 | workdir = d.getVar('WORKDIR', True) | ||
| 34 | if not workdir: | ||
| 35 | bb.error("WORKDIR not defined, unable to package") | ||
| 36 | return | ||
| 37 | |||
| 38 | outdir = d.getVar('PKGWRITEDIRDEB', True) | ||
| 39 | if not outdir: | ||
| 40 | bb.error("PKGWRITEDIRDEB not defined, unable to package") | ||
| 41 | return | ||
| 42 | |||
| 43 | packages = d.getVar('PACKAGES', True) | ||
| 44 | if not packages: | ||
| 45 | bb.debug(1, "PACKAGES not defined, nothing to package") | ||
| 46 | return | ||
| 47 | |||
| 48 | tmpdir = d.getVar('TMPDIR', True) | ||
| 49 | |||
| 50 | if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK): | ||
| 51 | os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN")) | ||
| 52 | |||
| 53 | if packages == []: | ||
| 54 | bb.debug(1, "No packages; nothing to do") | ||
| 55 | return | ||
| 56 | |||
| 57 | pkgdest = d.getVar('PKGDEST', True) | ||
| 58 | |||
| 59 | def cleanupcontrol(root): | ||
| 60 | for p in ['CONTROL', 'DEBIAN']: | ||
| 61 | p = os.path.join(root, p) | ||
| 62 | if os.path.exists(p): | ||
| 63 | bb.utils.prunedir(p) | ||
| 64 | |||
| 65 | for pkg in packages.split(): | ||
| 66 | localdata = bb.data.createCopy(d) | ||
| 67 | root = "%s/%s" % (pkgdest, pkg) | ||
| 68 | |||
| 69 | lf = bb.utils.lockfile(root + ".lock") | ||
| 70 | |||
| 71 | localdata.setVar('ROOT', '') | ||
| 72 | localdata.setVar('ROOT_%s' % pkg, root) | ||
| 73 | pkgname = localdata.getVar('PKG_%s' % pkg, True) | ||
| 74 | if not pkgname: | ||
| 75 | pkgname = pkg | ||
| 76 | localdata.setVar('PKG', pkgname) | ||
| 77 | |||
| 78 | localdata.setVar('OVERRIDES', pkg) | ||
| 79 | |||
| 80 | bb.data.update_data(localdata) | ||
| 81 | basedir = os.path.join(os.path.dirname(root)) | ||
| 82 | |||
| 83 | pkgoutdir = os.path.join(outdir, localdata.getVar('PACKAGE_ARCH', True)) | ||
| 84 | bb.utils.mkdirhier(pkgoutdir) | ||
| 85 | |||
| 86 | os.chdir(root) | ||
| 87 | cleanupcontrol(root) | ||
| 88 | from glob import glob | ||
| 89 | g = glob('*') | ||
| 90 | if not g and localdata.getVar('ALLOW_EMPTY') != "1": | ||
| 91 | bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV', True), localdata.getVar('PKGR', True))) | ||
| 92 | bb.utils.unlockfile(lf) | ||
| 93 | continue | ||
| 94 | |||
| 95 | controldir = os.path.join(root, 'DEBIAN') | ||
| 96 | bb.utils.mkdirhier(controldir) | ||
| 97 | os.chmod(controldir, 0755) | ||
| 98 | try: | ||
| 99 | ctrlfile = open(os.path.join(controldir, 'control'), 'w') | ||
| 100 | # import codecs | ||
| 101 | # ctrlfile = codecs.open("someFile", "w", "utf-8") | ||
| 102 | except OSError: | ||
| 103 | bb.utils.unlockfile(lf) | ||
| 104 | raise bb.build.FuncFailed("unable to open control file for writing.") | ||
| 105 | |||
| 106 | fields = [] | ||
| 107 | pe = d.getVar('PKGE', True) | ||
| 108 | if pe and int(pe) > 0: | ||
| 109 | fields.append(["Version: %s:%s-%s\n", ['PKGE', 'PKGV', 'PKGR']]) | ||
| 110 | else: | ||
| 111 | fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']]) | ||
| 112 | fields.append(["Description: %s\n", ['DESCRIPTION']]) | ||
| 113 | fields.append(["Section: %s\n", ['SECTION']]) | ||
| 114 | fields.append(["Priority: %s\n", ['PRIORITY']]) | ||
| 115 | fields.append(["Maintainer: %s\n", ['MAINTAINER']]) | ||
| 116 | fields.append(["Architecture: %s\n", ['DPKG_ARCH']]) | ||
| 117 | fields.append(["OE: %s\n", ['PN']]) | ||
| 118 | fields.append(["PackageArch: %s\n", ['PACKAGE_ARCH']]) | ||
| 119 | if d.getVar('HOMEPAGE', True): | ||
| 120 | fields.append(["Homepage: %s\n", ['HOMEPAGE']]) | ||
| 121 | |||
| 122 | # Package, Version, Maintainer, Description - mandatory | ||
| 123 | # Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional | ||
| 124 | |||
| 125 | |||
| 126 | def pullData(l, d): | ||
| 127 | l2 = [] | ||
| 128 | for i in l: | ||
| 129 | data = d.getVar(i, True) | ||
| 130 | if data is None: | ||
| 131 | raise KeyError(f) | ||
| 132 | if i == 'DPKG_ARCH' and d.getVar('PACKAGE_ARCH', True) == 'all': | ||
| 133 | data = 'all' | ||
| 134 | elif i == 'PACKAGE_ARCH' or i == 'DPKG_ARCH': | ||
| 135 | # The params in deb package control don't allow character | ||
| 136 | # `_', so change the arch's `_' to `-'. Such as `x86_64' | ||
| 137 | # -->`x86-64' | ||
| 138 | data = data.replace('_', '-') | ||
| 139 | l2.append(data) | ||
| 140 | return l2 | ||
| 141 | |||
| 142 | ctrlfile.write("Package: %s\n" % pkgname) | ||
| 143 | # check for required fields | ||
| 144 | try: | ||
| 145 | for (c, fs) in fields: | ||
| 146 | for f in fs: | ||
| 147 | if localdata.getVar(f) is None: | ||
| 148 | raise KeyError(f) | ||
| 149 | # Special behavior for description... | ||
| 150 | if 'DESCRIPTION' in fs: | ||
| 151 | summary = localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or "." | ||
| 152 | ctrlfile.write('Description: %s\n' % unicode(summary)) | ||
| 153 | description = localdata.getVar('DESCRIPTION', True) or "." | ||
| 154 | description = textwrap.dedent(description).strip() | ||
| 155 | if '\\n' in description: | ||
| 156 | # Manually indent | ||
| 157 | for t in description.split('\\n'): | ||
| 158 | # We don't limit the width when manually indent, but we do | ||
| 159 | # need the textwrap.fill() to set the initial_indent and | ||
| 160 | # subsequent_indent, so set a large width | ||
| 161 | ctrlfile.write('%s\n' % unicode(textwrap.fill(t, width=100000, initial_indent=' ', subsequent_indent=' '))) | ||
| 162 | else: | ||
| 163 | # Auto indent | ||
| 164 | ctrlfile.write('%s\n' % unicode(textwrap.fill(description.strip(), width=74, initial_indent=' ', subsequent_indent=' '))) | ||
| 165 | |||
| 166 | else: | ||
| 167 | ctrlfile.write(unicode(c % tuple(pullData(fs, localdata)))) | ||
| 168 | except KeyError: | ||
| 169 | import sys | ||
| 170 | (type, value, traceback) = sys.exc_info() | ||
| 171 | bb.utils.unlockfile(lf) | ||
| 172 | ctrlfile.close() | ||
| 173 | raise bb.build.FuncFailed("Missing field for deb generation: %s" % value) | ||
| 174 | # more fields | ||
| 175 | |||
| 176 | custom_fields_chunk = get_package_additional_metadata("deb", localdata) | ||
| 177 | if custom_fields_chunk is not None: | ||
| 178 | ctrlfile.write(unicode(custom_fields_chunk)) | ||
| 179 | ctrlfile.write("\n") | ||
| 180 | |||
| 181 | mapping_rename_hook(localdata) | ||
| 182 | |||
| 183 | def debian_cmp_remap(var): | ||
| 184 | # dpkg does not allow for '(' or ')' in a dependency name | ||
| 185 | # replace these instances with '__' and '__' | ||
| 186 | # | ||
| 187 | # In debian '>' and '<' do not mean what it appears they mean | ||
| 188 | # '<' = less or equal | ||
| 189 | # '>' = greater or equal | ||
| 190 | # adjust these to the '<<' and '>>' equivalents | ||
| 191 | # | ||
| 192 | for dep in var: | ||
| 193 | if '(' in dep: | ||
| 194 | newdep = dep.replace('(', '__') | ||
| 195 | newdep = newdep.replace(')', '__') | ||
| 196 | if newdep != dep: | ||
| 197 | var[newdep] = var[dep] | ||
| 198 | del var[dep] | ||
| 199 | for dep in var: | ||
| 200 | for i, v in enumerate(var[dep]): | ||
| 201 | if (v or "").startswith("< "): | ||
| 202 | var[dep][i] = var[dep][i].replace("< ", "<< ") | ||
| 203 | elif (v or "").startswith("> "): | ||
| 204 | var[dep][i] = var[dep][i].replace("> ", ">> ") | ||
| 205 | |||
| 206 | rdepends = bb.utils.explode_dep_versions2(localdata.getVar("RDEPENDS", True) or "") | ||
| 207 | debian_cmp_remap(rdepends) | ||
| 208 | for dep in rdepends: | ||
| 209 | if '*' in dep: | ||
| 210 | del rdepends[dep] | ||
| 211 | rrecommends = bb.utils.explode_dep_versions2(localdata.getVar("RRECOMMENDS", True) or "") | ||
| 212 | debian_cmp_remap(rrecommends) | ||
| 213 | for dep in rrecommends: | ||
| 214 | if '*' in dep: | ||
| 215 | del rrecommends[dep] | ||
| 216 | rsuggests = bb.utils.explode_dep_versions2(localdata.getVar("RSUGGESTS", True) or "") | ||
| 217 | debian_cmp_remap(rsuggests) | ||
| 218 | rprovides = bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES", True) or "") | ||
| 219 | debian_cmp_remap(rprovides) | ||
| 220 | rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES", True) or "") | ||
| 221 | debian_cmp_remap(rreplaces) | ||
| 222 | rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS", True) or "") | ||
| 223 | debian_cmp_remap(rconflicts) | ||
| 224 | if rdepends: | ||
| 225 | ctrlfile.write("Depends: %s\n" % unicode(bb.utils.join_deps(rdepends))) | ||
| 226 | if rsuggests: | ||
| 227 | ctrlfile.write("Suggests: %s\n" % unicode(bb.utils.join_deps(rsuggests))) | ||
| 228 | if rrecommends: | ||
| 229 | ctrlfile.write("Recommends: %s\n" % unicode(bb.utils.join_deps(rrecommends))) | ||
| 230 | if rprovides: | ||
| 231 | ctrlfile.write("Provides: %s\n" % unicode(bb.utils.join_deps(rprovides))) | ||
| 232 | if rreplaces: | ||
| 233 | ctrlfile.write("Replaces: %s\n" % unicode(bb.utils.join_deps(rreplaces))) | ||
| 234 | if rconflicts: | ||
| 235 | ctrlfile.write("Conflicts: %s\n" % unicode(bb.utils.join_deps(rconflicts))) | ||
| 236 | ctrlfile.close() | ||
| 237 | |||
| 238 | for script in ["preinst", "postinst", "prerm", "postrm"]: | ||
| 239 | scriptvar = localdata.getVar('pkg_%s' % script, True) | ||
| 240 | if not scriptvar: | ||
| 241 | continue | ||
| 242 | scriptvar = scriptvar.strip() | ||
| 243 | try: | ||
| 244 | scriptfile = open(os.path.join(controldir, script), 'w') | ||
| 245 | except OSError: | ||
| 246 | bb.utils.unlockfile(lf) | ||
| 247 | raise bb.build.FuncFailed("unable to open %s script file for writing." % script) | ||
| 248 | |||
| 249 | if scriptvar.startswith("#!"): | ||
| 250 | pos = scriptvar.find("\n") + 1 | ||
| 251 | scriptfile.write(scriptvar[:pos]) | ||
| 252 | else: | ||
| 253 | pos = 0 | ||
| 254 | scriptfile.write("#!/bin/sh\n") | ||
| 255 | |||
| 256 | # Prevent the prerm/postrm scripts from being run during an upgrade | ||
| 257 | if script in ('prerm', 'postrm'): | ||
| 258 | scriptfile.write('[ "$1" != "upgrade" ] || exit 0\n') | ||
| 259 | |||
| 260 | scriptfile.write(scriptvar[pos:]) | ||
| 261 | scriptfile.write('\n') | ||
| 262 | scriptfile.close() | ||
| 263 | os.chmod(os.path.join(controldir, script), 0755) | ||
| 264 | |||
| 265 | conffiles_str = localdata.getVar("CONFFILES", True) | ||
| 266 | if conffiles_str: | ||
| 267 | try: | ||
| 268 | conffiles = open(os.path.join(controldir, 'conffiles'), 'w') | ||
| 269 | except OSError: | ||
| 270 | bb.utils.unlockfile(lf) | ||
| 271 | raise bb.build.FuncFailed("unable to open conffiles for writing.") | ||
| 272 | for f in conffiles_str.split(): | ||
| 273 | if os.path.exists(oe.path.join(root, f)): | ||
| 274 | conffiles.write('%s\n' % f) | ||
| 275 | conffiles.close() | ||
| 276 | |||
| 277 | os.chdir(basedir) | ||
| 278 | ret = subprocess.call("PATH=\"%s\" dpkg-deb -b %s %s" % (localdata.getVar("PATH", True), root, pkgoutdir), shell=True) | ||
| 279 | if ret != 0: | ||
| 280 | bb.utils.unlockfile(lf) | ||
| 281 | raise bb.build.FuncFailed("dpkg-deb execution failed") | ||
| 282 | |||
| 283 | cleanupcontrol(root) | ||
| 284 | bb.utils.unlockfile(lf) | ||
| 285 | } | ||
| 286 | |||
| 287 | SSTATETASKS += "do_package_write_deb" | ||
| 288 | do_package_write_deb[sstate-inputdirs] = "${PKGWRITEDIRDEB}" | ||
| 289 | do_package_write_deb[sstate-outputdirs] = "${DEPLOY_DIR_DEB}" | ||
| 290 | |||
| 291 | python do_package_write_deb_setscene () { | ||
| 292 | tmpdir = d.getVar('TMPDIR', True) | ||
| 293 | |||
| 294 | if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK): | ||
| 295 | os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN")) | ||
| 296 | |||
| 297 | sstate_setscene(d) | ||
| 298 | } | ||
| 299 | addtask do_package_write_deb_setscene | ||
| 300 | |||
| 301 | python () { | ||
| 302 | if d.getVar('PACKAGES', True) != '': | ||
| 303 | deps = ' dpkg-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot' | ||
| 304 | d.appendVarFlag('do_package_write_deb', 'depends', deps) | ||
| 305 | d.setVarFlag('do_package_write_deb', 'fakeroot', "1") | ||
| 306 | |||
| 307 | # Map TARGET_ARCH to Debian's ideas about architectures | ||
| 308 | darch = d.getVar('DPKG_ARCH', True) | ||
| 309 | if darch in ["x86", "i486", "i586", "i686", "pentium"]: | ||
| 310 | d.setVar('DPKG_ARCH', 'i386') | ||
| 311 | elif darch == "x86_64": | ||
| 312 | d.setVar('DPKG_ARCH', 'amd64') | ||
| 313 | elif darch == "arm": | ||
| 314 | d.setVar('DPKG_ARCH', 'armel') | ||
| 315 | } | ||
| 316 | |||
| 317 | python do_package_write_deb () { | ||
| 318 | bb.build.exec_func("read_subpackage_metadata", d) | ||
| 319 | bb.build.exec_func("do_package_deb", d) | ||
| 320 | } | ||
| 321 | do_package_write_deb[dirs] = "${PKGWRITEDIRDEB}" | ||
| 322 | do_package_write_deb[cleandirs] = "${PKGWRITEDIRDEB}" | ||
| 323 | do_package_write_deb[umask] = "022" | ||
| 324 | addtask package_write_deb after do_packagedata do_package | ||
| 325 | |||
| 326 | |||
| 327 | PACKAGEINDEXDEPS += "dpkg-native:do_populate_sysroot" | ||
| 328 | PACKAGEINDEXDEPS += "apt-native:do_populate_sysroot" | ||
| 329 | |||
| 330 | do_build[recrdeptask] += "do_package_write_deb" | ||
