merge of '0b604857bbf871639fdb43ee8380222e8ef64bb7'
[vuplus_openembedded] / classes / package_ipk.bbclass
index 16d6050..f05b744 100644 (file)
@@ -1,17 +1,21 @@
 inherit package
 
-BOOTSTRAP_EXTRA_RDEPENDS += "ipkg-collateral ipkg"
+BOOTSTRAP_EXTRA_RDEPENDS += "opkg-collateral opkg"
 IMAGE_PKGTYPE ?= "ipk"
 
-IPKGCONF_TARGET = "${STAGING_ETCDIR_NATIVE}/ipkg.conf"
-IPKGCONF_SDK =  "${STAGING_ETCDIR_NATIVE}/ipkg-sdk.conf"
+IPKGCONF_TARGET = "${STAGING_ETCDIR_NATIVE}/opkg.conf"
+IPKGCONF_SDK =  "${STAGING_ETCDIR_NATIVE}/opkg-sdk.conf"
 
 python package_ipk_fn () {
        from bb import data
        bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
 }
 
-python package_ipk_install () {
+python package_ipk_install () { 
+       #
+       # Warning - this function is not multimachine safe (see stagingdir reference)!
+       #
+
        import os, sys
        pkg = bb.data.getVar('PKG', d, 1)
        pkgfn = bb.data.getVar('PKGFN', d, 1)
@@ -31,7 +35,7 @@ python package_ipk_install () {
                raise bb.build.FuncFailed
 
        # Generate ipk.conf if it or the stamp doesnt exist
-       conffile = os.path.join(stagingdir,"ipkg.conf")
+       conffile = os.path.join(stagingdir,"opkg.conf")
        if not os.access(conffile, os.R_OK):
                ipkg_archs = bb.data.getVar('PACKAGE_ARCHS',d)
                if ipkg_archs is None:
@@ -56,8 +60,8 @@ python package_ipk_install () {
                f = open(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"),"w")
                f.close()
 
-       ret = os.system('ipkg-cl  -o %s -f %s update' % (rootfs, conffile))
-       ret = os.system('ipkg-cl  -o %s -f %s install %s' % (rootfs, conffile, pkgfn))
+       ret = os.system('opkg-cl  -o %s -f %s update' % (rootfs, conffile))
+       ret = os.system('opkg-cl  -o %s -f %s install %s' % (rootfs, conffile, pkgfn))
        if (ret != 0 ):
                raise bb.build.FuncFailed
 }
@@ -114,7 +118,7 @@ package_generate_ipkg_conf () {
 }
 
 python do_package_ipk () {
-       import sys, re, copy, fcntl
+       import sys, re, copy
 
        workdir = bb.data.getVar('WORKDIR', d, 1)
        if not workdir:
@@ -133,36 +137,18 @@ python do_package_ipk () {
                return
        bb.mkdirhier(dvar)
 
-       packages = bb.data.getVar('PACKAGES', d, 1)
-       if not packages:
-               bb.debug(1, "PACKAGES not defined, nothing to package")
-               return
-
        tmpdir = bb.data.getVar('TMPDIR', d, 1)
 
        if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
                os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
 
-       if packages == []:
-               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
-
-
+       packages = bb.data.getVar('PACKAGES', d, True)
        for pkg in packages.split():
                localdata = bb.data.createCopy(d)
                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)
@@ -193,7 +179,7 @@ python do_package_ipk () {
                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)
+                       bb.utils.unlockfile(lf)
                        continue
 
                controldir = os.path.join(root, 'CONTROL')
@@ -201,7 +187,7 @@ python do_package_ipk () {
                try:
                        ctrlfile = file(os.path.join(controldir, 'control'), 'w')
                except OSError:
-                       unlockfile(lf)
+                       bb.utils.unlockfile(lf)
                        raise bb.build.FuncFailed("unable to open control file for writing.")
 
                fields = []
@@ -235,7 +221,7 @@ python do_package_ipk () {
                except KeyError:
                        (type, value, traceback) = sys.exc_info()
                        ctrlfile.close()
-                       unlockfile(lf)
+                       bb.utils.unlockfile(lf)
                        raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
                # more fields
 
@@ -272,7 +258,7 @@ python do_package_ipk () {
                        try:
                                scriptfile = file(os.path.join(controldir, script), 'w')
                        except OSError:
-                               unlockfile(lf)
+                               bb.utils.unlockfile(lf)
                                raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
                        scriptfile.write(scriptvar)
                        scriptfile.close()
@@ -283,7 +269,7 @@ python do_package_ipk () {
                        try:
                                conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
                        except OSError:
-                               unlockfile(lf)
+                               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)
@@ -293,7 +279,7 @@ python do_package_ipk () {
                ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1), 
                                                           bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
                if ret != 0:
-                       unlockfile(lf)
+                       bb.utils.unlockfile(lf)
                        raise bb.build.FuncFailed("ipkg-build execution failed")
 
                for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
@@ -306,7 +292,7 @@ python do_package_ipk () {
                        os.rmdir(controldir)
                except OSError:
                        pass
-               unlockfile(lf)
+               bb.utils.unlockfile(lf)
 }
 
 python () {
@@ -319,6 +305,11 @@ python () {
 }
 
 python do_package_write_ipk () {
+       packages = bb.data.getVar('PACKAGES', d, True)
+       if not packages:
+               bb.debug(1, "No PACKAGES defined, nothing to package")
+               return
+
        bb.build.exec_func("read_subpackage_metadata", d)
        bb.build.exec_func("do_package_ipk", d)
 }