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"
7 python package_ipk_fn () {
9 bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
12 python package_ipk_install () {
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)
21 if None in (pkg,pkgfn,rootfs):
22 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)")
27 (type, value, traceback) = sys.exc_info()
29 raise bb.build.FuncFailed
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")
38 ipkg_archs = ipkg_archs.split()
41 f = open(conffile,"w")
42 for arch in ipkg_archs:
43 f.write("arch %s %s\n" % ( arch, arch_priority ))
45 f.write("src local file:%s" % ipkdir)
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))
53 raise bb.build.FuncFailed
54 f=open(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),"w")
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))
60 raise bb.build.FuncFailed
63 python do_package_ipk () {
64 import copy # to back up env data
68 workdir = bb.data.getVar('WORKDIR', d, 1)
70 bb.error("WORKDIR not defined, unable to package")
73 import os # path manipulations
74 outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
76 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
80 dvar = bb.data.getVar('D', d, 1)
82 bb.error("D not defined, unable to package")
86 packages = bb.data.getVar('PACKAGES', d, 1)
88 bb.debug(1, "PACKAGES not defined, nothing to package")
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"))
97 bb.debug(1, "No packages; nothing to do")
100 for pkg in packages.split():
101 localdata = bb.data.createCopy(d)
102 root = "%s/install/%s" % (workdir, pkg)
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)
109 bb.data.setVar('PKG', pkgname, localdata)
111 overrides = bb.data.getVar('OVERRIDES', localdata)
113 raise bb.build.FuncFailed('OVERRIDES not defined')
114 overrides = bb.data.expand(overrides, localdata)
115 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
117 bb.data.update_data(localdata)
118 basedir = os.path.join(os.path.dirname(root))
120 bb.mkdirhier(pkgoutdir)
122 from glob import glob
125 del g[g.index('CONTROL')]
126 del g[g.index('./CONTROL')]
129 if not g and not bb.data.getVar('ALLOW_EMPTY', localdata):
131 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
133 controldir = os.path.join(root, 'CONTROL')
134 bb.mkdirhier(controldir)
136 ctrlfile = file(os.path.join(controldir, 'control'), 'w')
138 raise bb.build.FuncFailed("unable to open control file for writing.")
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 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
153 l2.append(bb.data.getVar(i, d, 1))
156 ctrlfile.write("Package: %s\n" % pkgname)
157 # check for required fields
159 for (c, fs) in fields:
161 if bb.data.getVar(f, localdata) is None:
163 ctrlfile.write(c % tuple(pullData(fs, localdata)))
165 (type, value, traceback) = sys.exc_info()
167 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
169 rdepends = explode_deps(bb.data.getVar("RDEPENDS", localdata, 1) or "")
170 rrecommends = explode_deps(bb.data.getVar("RRECOMMENDS", localdata, 1) or "")
171 rsuggests = (bb.data.getVar("RSUGGESTS", localdata, 1) or "").split()
172 rprovides = (bb.data.getVar("RPROVIDES", localdata, 1) or "").split()
173 rreplaces = (bb.data.getVar("RREPLACES", localdata, 1) or "").split()
174 rconflicts = (bb.data.getVar("RCONFLICTS", localdata, 1) or "").split()
176 ctrlfile.write("Depends: %s\n" % ", ".join(rdepends))
178 ctrlfile.write("Suggests: %s\n" % ", ".join(rsuggests))
180 ctrlfile.write("Recommends: %s\n" % ", ".join(rrecommends))
182 ctrlfile.write("Provides: %s\n" % ", ".join(rprovides))
184 ctrlfile.write("Replaces: %s\n" % ", ".join(rreplaces))
186 ctrlfile.write("Conflicts: %s\n" % ", ".join(rconflicts))
187 src_uri = bb.data.getVar("SRC_URI", localdata, 1)
189 src_uri = re.sub("\s+", " ", src_uri)
190 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
193 for script in ["preinst", "postinst", "prerm", "postrm"]:
194 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
198 scriptfile = file(os.path.join(controldir, script), 'w')
200 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
201 scriptfile.write(scriptvar)
203 os.chmod(os.path.join(controldir, script), 0755)
205 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
208 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
210 raise bb.build.FuncFailed("unable to open conffiles for writing.")
211 for f in conffiles_str.split():
212 conffiles.write('%s\n' % f)
216 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1),
217 bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
219 raise bb.build.FuncFailed("ipkg-build execution failed")
221 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
222 scriptfile = os.path.join(controldir, script)
224 os.remove(scriptfile)