diff options
| author | Richard Purdie <richard@openedhand.com> | 2005-08-31 10:45:47 +0000 |
|---|---|---|
| committer | Richard Purdie <richard@openedhand.com> | 2005-08-31 10:45:47 +0000 |
| commit | 4b46c1f6e891b1ddd5968536440b888661fade3e (patch) | |
| tree | e0ba2c1f56f61b868bf746da5c4feabb25b800b2 /openembedded/classes/package_ipk.bbclass | |
| download | poky-4b46c1f6e891b1ddd5968536440b888661fade3e.tar.gz | |
Initial population
git-svn-id: https://svn.o-hand.com/repos/poky@1 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'openembedded/classes/package_ipk.bbclass')
| -rw-r--r-- | openembedded/classes/package_ipk.bbclass | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/openembedded/classes/package_ipk.bbclass b/openembedded/classes/package_ipk.bbclass new file mode 100644 index 0000000000..3c6125d9e3 --- /dev/null +++ b/openembedded/classes/package_ipk.bbclass | |||
| @@ -0,0 +1,231 @@ | |||
| 1 | inherit package | ||
| 2 | DEPENDS_prepend="${@["ipkg-utils-native ", ""][(bb.data.getVar('PACKAGES', d, 1) == '')]}" | ||
| 3 | BOOTSTRAP_EXTRA_RDEPENDS += "ipkg-collateral ipkg ipkg-link" | ||
| 4 | BOOTSTRAP_EXTRA_DEPENDS += "ipkg-collateral ipkg ipkg-link" | ||
| 5 | PACKAGEFUNCS += "do_package_ipk" | ||
| 6 | |||
| 7 | python package_ipk_fn () { | ||
| 8 | from bb import data | ||
| 9 | bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d) | ||
| 10 | } | ||
| 11 | |||
| 12 | python package_ipk_install () { | ||
| 13 | import os, sys | ||
| 14 | pkg = bb.data.getVar('PKG', d, 1) | ||
| 15 | pkgfn = bb.data.getVar('PKGFN', d, 1) | ||
| 16 | rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1) | ||
| 17 | ipkdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1) | ||
| 18 | stagingdir = bb.data.getVar('STAGING_DIR', d, 1) | ||
| 19 | tmpdir = bb.data.getVar('TMPDIR', d, 1) | ||
| 20 | |||
| 21 | if None in (pkg,pkgfn,rootfs): | ||
| 22 | raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)") | ||
| 23 | try: | ||
| 24 | bb.mkdirhier(rootfs) | ||
| 25 | os.chdir(rootfs) | ||
| 26 | except OSError: | ||
| 27 | (type, value, traceback) = sys.exc_info() | ||
| 28 | print value | ||
| 29 | raise bb.build.FuncFailed | ||
| 30 | |||
| 31 | # Generate ipk.conf if it or the stamp doesnt exist | ||
| 32 | conffile = os.path.join(stagingdir,"ipkg.conf") | ||
| 33 | if not os.access(conffile, os.R_OK): | ||
| 34 | ipkg_archs = bb.data.getVar('IPKG_ARCHS',d) | ||
| 35 | if ipkg_archs is None: | ||
| 36 | bb.error("IPKG_ARCHS missing") | ||
| 37 | raise FuncFailed | ||
| 38 | ipkg_archs = ipkg_archs.split() | ||
| 39 | arch_priority = 1 | ||
| 40 | |||
| 41 | f = open(conffile,"w") | ||
| 42 | for arch in ipkg_archs: | ||
| 43 | f.write("arch %s %s\n" % ( arch, arch_priority )) | ||
| 44 | arch_priority += 1 | ||
| 45 | f.write("src local file:%s" % ipkdir) | ||
| 46 | f.close() | ||
| 47 | |||
| 48 | |||
| 49 | if (not os.access(os.path.join(ipkdir,"Packages"), os.R_OK) or | ||
| 50 | not os.access(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),os.R_OK)): | ||
| 51 | ret = os.system('ipkg-make-index -p %s %s ' % (os.path.join(ipkdir, "Packages"), ipkdir)) | ||
| 52 | if (ret != 0 ): | ||
| 53 | raise bb.build.FuncFailed | ||
| 54 | f=open(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),"w") | ||
| 55 | f.close() | ||
| 56 | |||
| 57 | ret = os.system('ipkg-cl -o %s -f %s update' % (rootfs, conffile)) | ||
| 58 | ret = os.system('ipkg-cl -o %s -f %s install %s' % (rootfs, conffile, pkgfn)) | ||
| 59 | if (ret != 0 ): | ||
| 60 | raise bb.build.FuncFailed | ||
| 61 | } | ||
| 62 | |||
| 63 | python do_package_ipk () { | ||
| 64 | import copy # to back up env data | ||
| 65 | import sys | ||
| 66 | import re | ||
| 67 | |||
| 68 | workdir = bb.data.getVar('WORKDIR', d, 1) | ||
| 69 | if not workdir: | ||
| 70 | bb.error("WORKDIR not defined, unable to package") | ||
| 71 | return | ||
| 72 | |||
| 73 | import os # path manipulations | ||
| 74 | outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1) | ||
| 75 | if not outdir: | ||
| 76 | bb.error("DEPLOY_DIR_IPK not defined, unable to package") | ||
| 77 | return | ||
| 78 | bb.mkdirhier(outdir) | ||
| 79 | |||
| 80 | dvar = bb.data.getVar('D', d, 1) | ||
| 81 | if not dvar: | ||
| 82 | bb.error("D not defined, unable to package") | ||
| 83 | return | ||
| 84 | bb.mkdirhier(dvar) | ||
| 85 | |||
| 86 | packages = bb.data.getVar('PACKAGES', d, 1) | ||
| 87 | if not packages: | ||
| 88 | bb.debug(1, "PACKAGES not defined, nothing to package") | ||
| 89 | return | ||
| 90 | |||
| 91 | tmpdir = bb.data.getVar('TMPDIR', d, 1) | ||
| 92 | # Invalidate the packages file | ||
| 93 | if os.access(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),os.R_OK): | ||
| 94 | os.unlink(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages")) | ||
| 95 | |||
| 96 | if packages == []: | ||
| 97 | bb.debug(1, "No packages; nothing to do") | ||
| 98 | return | ||
| 99 | |||
| 100 | for pkg in packages.split(): | ||
| 101 | localdata = bb.data.createCopy(d) | ||
| 102 | root = "%s/install/%s" % (workdir, pkg) | ||
| 103 | |||
| 104 | bb.data.setVar('ROOT', '', localdata) | ||
| 105 | bb.data.setVar('ROOT_%s' % pkg, root, localdata) | ||
| 106 | pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1) | ||
| 107 | if not pkgname: | ||
| 108 | pkgname = pkg | ||
| 109 | bb.data.setVar('PKG', pkgname, localdata) | ||
| 110 | |||
| 111 | overrides = bb.data.getVar('OVERRIDES', localdata) | ||
| 112 | if not overrides: | ||
| 113 | raise bb.build.FuncFailed('OVERRIDES not defined') | ||
| 114 | overrides = bb.data.expand(overrides, localdata) | ||
| 115 | bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata) | ||
| 116 | |||
| 117 | bb.data.update_data(localdata) | ||
| 118 | basedir = os.path.join(os.path.dirname(root)) | ||
| 119 | pkgoutdir = outdir | ||
| 120 | bb.mkdirhier(pkgoutdir) | ||
| 121 | os.chdir(root) | ||
| 122 | from glob import glob | ||
| 123 | g = glob('*') | ||
| 124 | try: | ||
| 125 | del g[g.index('CONTROL')] | ||
| 126 | del g[g.index('./CONTROL')] | ||
| 127 | except ValueError: | ||
| 128 | pass | ||
| 129 | if not g and not bb.data.getVar('ALLOW_EMPTY', localdata): | ||
| 130 | from bb import note | ||
| 131 | note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1))) | ||
| 132 | continue | ||
| 133 | controldir = os.path.join(root, 'CONTROL') | ||
| 134 | bb.mkdirhier(controldir) | ||
| 135 | try: | ||
| 136 | ctrlfile = file(os.path.join(controldir, 'control'), 'w') | ||
| 137 | except OSError: | ||
| 138 | raise bb.build.FuncFailed("unable to open control file for writing.") | ||
| 139 | |||
| 140 | fields = [] | ||
| 141 | fields.append(["Version: %s-%s\n", ['PV', 'PR']]) | ||
| 142 | fields.append(["Description: %s\n", ['DESCRIPTION']]) | ||
| 143 | fields.append(["Section: %s\n", ['SECTION']]) | ||
| 144 | fields.append(["Priority: %s\n", ['PRIORITY']]) | ||
| 145 | fields.append(["Maintainer: %s\n", ['MAINTAINER']]) | ||
| 146 | fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']]) | ||
| 147 | fields.append(["OE: %s\n", ['P']]) | ||
| 148 | |||
| 149 | def pullData(l, d): | ||
| 150 | l2 = [] | ||
| 151 | for i in l: | ||
| 152 | l2.append(bb.data.getVar(i, d, 1)) | ||
| 153 | return l2 | ||
| 154 | |||
| 155 | ctrlfile.write("Package: %s\n" % pkgname) | ||
| 156 | # check for required fields | ||
| 157 | try: | ||
| 158 | for (c, fs) in fields: | ||
| 159 | for f in fs: | ||
| 160 | if bb.data.getVar(f, localdata) is None: | ||
| 161 | raise KeyError(f) | ||
| 162 | ctrlfile.write(c % tuple(pullData(fs, localdata))) | ||
| 163 | except KeyError: | ||
| 164 | (type, value, traceback) = sys.exc_info() | ||
| 165 | ctrlfile.close() | ||
| 166 | raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value) | ||
| 167 | # more fields | ||
| 168 | rdepends = explode_deps(bb.data.getVar("RDEPENDS", localdata, 1) or "") | ||
| 169 | rrecommends = explode_deps(bb.data.getVar("RRECOMMENDS", localdata, 1) or "") | ||
| 170 | rsuggests = (bb.data.getVar("RSUGGESTS", localdata, 1) or "").split() | ||
| 171 | rprovides = (bb.data.getVar("RPROVIDES", localdata, 1) or "").split() | ||
| 172 | rreplaces = (bb.data.getVar("RREPLACES", localdata, 1) or "").split() | ||
| 173 | rconflicts = (bb.data.getVar("RCONFLICTS", localdata, 1) or "").split() | ||
| 174 | if rdepends: | ||
| 175 | ctrlfile.write("Depends: %s\n" % ", ".join(rdepends)) | ||
| 176 | if rsuggests: | ||
| 177 | ctrlfile.write("Suggests: %s\n" % ", ".join(rsuggests)) | ||
| 178 | if rrecommends: | ||
| 179 | ctrlfile.write("Recommends: %s\n" % ", ".join(rrecommends)) | ||
| 180 | if rprovides: | ||
| 181 | ctrlfile.write("Provides: %s\n" % ", ".join(rprovides)) | ||
| 182 | if rreplaces: | ||
| 183 | ctrlfile.write("Replaces: %s\n" % ", ".join(rreplaces)) | ||
| 184 | if rconflicts: | ||
| 185 | ctrlfile.write("Conflicts: %s\n" % ", ".join(rconflicts)) | ||
| 186 | src_uri = bb.data.getVar("SRC_URI", localdata, 1) | ||
| 187 | if src_uri: | ||
| 188 | src_uri = re.sub("\s+", " ", src_uri) | ||
| 189 | ctrlfile.write("Source: %s\n" % " ".join(src_uri.split())) | ||
| 190 | ctrlfile.close() | ||
| 191 | |||
| 192 | for script in ["preinst", "postinst", "prerm", "postrm"]: | ||
| 193 | scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1) | ||
| 194 | if not scriptvar: | ||
| 195 | continue | ||
| 196 | try: | ||
| 197 | scriptfile = file(os.path.join(controldir, script), 'w') | ||
| 198 | except OSError: | ||
| 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 = bb.data.getVar("CONFFILES", localdata, 1) | ||
| 205 | if conffiles_str: | ||
| 206 | try: | ||
| 207 | conffiles = file(os.path.join(controldir, 'conffiles'), 'w') | ||
| 208 | except OSError: | ||
| 209 | raise bb.build.FuncFailed("unable to open conffiles for writing.") | ||
| 210 | for f in conffiles_str.split(): | ||
| 211 | conffiles.write('%s\n' % f) | ||
| 212 | conffiles.close() | ||
| 213 | |||
| 214 | os.chdir(basedir) | ||
| 215 | ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1), | ||
| 216 | bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir)) | ||
| 217 | if ret != 0: | ||
| 218 | raise bb.build.FuncFailed("ipkg-build execution failed") | ||
| 219 | |||
| 220 | for script in ["preinst", "postinst", "prerm", "postrm", "control" ]: | ||
| 221 | scriptfile = os.path.join(controldir, script) | ||
| 222 | try: | ||
| 223 | os.remove(scriptfile) | ||
| 224 | except OSError: | ||
| 225 | pass | ||
| 226 | try: | ||
| 227 | os.rmdir(controldir) | ||
| 228 | except OSError: | ||
| 229 | pass | ||
| 230 | del localdata | ||
| 231 | } | ||
