diff options
Diffstat (limited to 'classes/package_deb.bbclass')
| -rw-r--r-- | classes/package_deb.bbclass | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/classes/package_deb.bbclass b/classes/package_deb.bbclass index b85ffe254f..2a9bf76a79 100644 --- a/classes/package_deb.bbclass +++ b/classes/package_deb.bbclass @@ -1,5 +1,5 @@ # -# Copyright 2006-2007 OpenedHand Ltd. +# Copyright 2006-2008 OpenedHand Ltd. # inherit package @@ -17,18 +17,16 @@ DPKG_ARCH_i686 ?= "i386" DPKG_ARCH_pentium ?= "i386" python package_deb_fn () { - from bb import data bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d) } addtask package_deb_install python do_package_deb_install () { - import os, sys pkg = bb.data.getVar('PKG', d, 1) pkgfn = bb.data.getVar('PKGFN', d, 1) rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1) debdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1) - stagingdir = bb.data.getVar('STAGING_DIR', d, 1) + apt_config = bb.data.expand('${STAGING_ETCDIR_NATIVE}/apt/apt.conf', d) stagingbindir = bb.data.getVar('STAGING_BINDIR_NATIVE', d, 1) tmpdir = bb.data.getVar('TMPDIR', d, 1) @@ -39,6 +37,7 @@ python do_package_deb_install () { os.makedirs(rootfs) os.chdir(rootfs) except OSError: + import sys raise bb.build.FuncFailed(str(sys.exc_value)) # update packages file @@ -54,8 +53,8 @@ python do_package_deb_install () { # env of the fork+execve'd processs # Set up environment - apt_config = os.getenv('APT_CONFIG') - os.putenv('APT_CONFIG', os.path.join(stagingdir, 'etc', 'apt', 'apt.conf')) + apt_config_backup = os.getenv('APT_CONFIG') + os.putenv('APT_CONFIG', apt_config) path = os.getenv('PATH') os.putenv('PATH', '%s:%s' % (stagingbindir, os.getenv('PATH'))) @@ -64,19 +63,18 @@ python do_package_deb_install () { commands.getstatusoutput('apt-get install -y %s' % pkgfn) # revert environment - os.putenv('APT_CONFIG', apt_config) + os.putenv('APT_CONFIG', apt_config_backup) os.putenv('PATH', path) } python do_package_deb () { - import sys, re, fcntl, copy + import re, copy workdir = bb.data.getVar('WORKDIR', d, 1) if not workdir: bb.error("WORKDIR not defined, unable to package") return - import os # path manipulations outdir = bb.data.getVar('DEPLOY_DIR_DEB', d, 1) if not outdir: bb.error("DEPLOY_DIR_DEB not defined, unable to package") @@ -102,20 +100,12 @@ python do_package_deb () { bb.debug(1, "No packages; nothing to do") return - def lockfile(name): - lf = open(name, "a+") - fcntl.flock(lf.fileno(), fcntl.LOCK_EX) - return lf - - def unlockfile(lf): - fcntl.flock(lf.fileno(), fcntl.LOCK_UN) - lf.close - for pkg in packages.split(): localdata = bb.data.createCopy(d) - root = "%s/install/%s" % (workdir, pkg) + pkgdest = bb.data.getVar('PKGDEST', d, 1) + root = "%s/%s" % (pkgdest, pkg) - lf = lockfile(root + ".lock") + lf = bb.utils.lockfile(root + ".lock") bb.data.setVar('ROOT', '', localdata) bb.data.setVar('ROOT_%s' % pkg, root, localdata) @@ -138,7 +128,7 @@ python do_package_deb () { os.chdir(root) from glob import glob - g = glob('*') + g = glob('*') + glob('.[!.]*') try: del g[g.index('DEBIAN')] del g[g.index('./DEBIAN')] @@ -146,8 +136,8 @@ python do_package_deb () { pass if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1": from bb import note - note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1))) - unlockfile(lf) + note("Not creating empty archive for %s-%s" % (pkg, bb.data.expand('${PV}-${PR}${DISTRO_PR}', localdata, True))) + bb.utils.unlockfile(lf) continue controldir = os.path.join(root, 'DEBIAN') @@ -158,14 +148,15 @@ python do_package_deb () { # import codecs # ctrlfile = codecs.open("someFile", "w", "utf-8") except OSError: + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open control file for writing.") fields = [] pe = bb.data.getVar('PE', d, 1) if pe and int(pe) > 0: - fields.append(["Version: %s:%s-%s\n", ['PE', 'PV', 'PR']]) + fields.append(["Version: %s:%s-%s%s\n", ['PE', 'PV', 'PR', 'DISTRO_PR']]) else: - fields.append(["Version: %s-%s\n", ['PV', 'PR']]) + fields.append(["Version: %s-%s%s\n", ['PV', 'PR', 'DISTRO_PR']]) fields.append(["Description: %s\n", ['DESCRIPTION']]) fields.append(["Section: %s\n", ['SECTION']]) fields.append(["Priority: %s\n", ['PRIORITY']]) @@ -195,7 +186,9 @@ python do_package_deb () { for (c, fs) in fields: ctrlfile.write(unicode(c % tuple(pullData(fs, localdata)))) except KeyError: + import sys (type, value, traceback) = sys.exc_info() + bb.utils.unlockfile(lf) ctrlfile.close() raise bb.build.FuncFailed("Missing field for deb generation: %s" % value) # more fields @@ -231,6 +224,7 @@ python do_package_deb () { try: scriptfile = file(os.path.join(controldir, script), 'w') except OSError: + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open %s script file for writing." % script) scriptfile.write("#!/bin/sh\n") scriptfile.write(scriptvar) @@ -242,34 +236,35 @@ python do_package_deb () { try: conffiles = file(os.path.join(controldir, 'conffiles'), 'w') except OSError: + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open conffiles for writing.") for f in conffiles_str.split(): conffiles.write('%s\n' % f) conffiles.close() + try: + write_package_md5sums(root, os.path.join(controldir, 'md5sums'), + ['DEBIAN']) + except: + bb.utils.unlockfile(lf) + raise + os.chdir(basedir) ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir)) if ret != 0: + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("dpkg-deb execution failed") - for script in ["preinst", "postinst", "prerm", "postrm", "control" ]: - scriptfile = os.path.join(controldir, script) - try: - os.remove(scriptfile) - except OSError: - pass - try: - os.rmdir(controldir) - except OSError: - pass - - unlockfile(lf) + bb.utils.prunedir(controldir) + bb.utils.unlockfile(lf) } python () { - import bb if bb.data.getVar('PACKAGES', d, True) != '': - bb.data.setVarFlag('do_package_write_deb', 'depends', 'dpkg-native:do_populate_staging fakeroot-native:do_populate_staging', d) + deps = (bb.data.getVarFlag('do_package_write_deb', 'depends', d) or "").split() + deps.append('dpkg-native:do_populate_staging') + deps.append('fakeroot-native:do_populate_staging') + bb.data.setVarFlag('do_package_write_deb', 'depends', " ".join(deps), d) } python do_package_write_deb () { |
