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
65 python do_package_ipk () {
66 import copy # to back up env data
70 workdir = bb.data.getVar('WORKDIR', d, 1)
72 bb.error("WORKDIR not defined, unable to package")
75 import os # path manipulations
76 outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
78 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
82 dvar = bb.data.getVar('D', d, 1)
84 bb.error("D not defined, unable to package")
88 packages = bb.data.getVar('PACKAGES', d, 1)
90 bb.debug(1, "PACKAGES not defined, nothing to package")
93 tmpdir = bb.data.getVar('TMPDIR', d, 1)
94 # Invalidate the packages file
95 if os.access(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),os.R_OK):
96 os.unlink(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"))
99 bb.debug(1, "No packages; nothing to do")
102 for pkg in packages.split():
103 localdata = bb.data.createCopy(d)
104 root = "%s/install/%s" % (workdir, pkg)
106 bb.data.setVar('ROOT', '', localdata)
107 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
108 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
111 bb.data.setVar('PKG', pkgname, localdata)
113 overrides = bb.data.getVar('OVERRIDES', localdata)
115 raise bb.build.FuncFailed('OVERRIDES not defined')
116 overrides = bb.data.expand(overrides, localdata)
117 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
119 bb.data.update_data(localdata)
120 basedir = os.path.join(os.path.dirname(root))
122 bb.mkdirhier(pkgoutdir)
124 from glob import glob
127 del g[g.index('CONTROL')]
128 del g[g.index('./CONTROL')]
131 if not g and not bb.data.getVar('ALLOW_EMPTY', localdata):
133 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
135 controldir = os.path.join(root, 'CONTROL')
136 bb.mkdirhier(controldir)
138 ctrlfile = file(os.path.join(controldir, 'control'), 'w')
140 raise bb.build.FuncFailed("unable to open control file for writing.")
143 fields.append(["Version: %s%s-%s\n", ['EPOCH', 'PV', 'PR']])
144 fields.append(["Description: %s\n", ['DESCRIPTION']])
145 fields.append(["Section: %s\n", ['SECTION']])
146 fields.append(["Priority: %s\n", ['PRIORITY']])
147 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
148 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
149 fields.append(["OE: %s\n", ['P']])
150 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
155 l2.append(bb.data.getVar(i, d, 1))
158 ctrlfile.write("Package: %s\n" % pkgname)
159 # check for required fields
161 for (c, fs) in fields:
163 if bb.data.getVar(f, localdata) is None:
165 ctrlfile.write(c % tuple(pullData(fs, localdata)))
167 (type, value, traceback) = sys.exc_info()
169 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
171 rdepends = explode_deps(bb.data.getVar("RDEPENDS", localdata, 1) or "")
172 rrecommends = explode_deps(bb.data.getVar("RRECOMMENDS", localdata, 1) or "")
173 rsuggests = (bb.data.getVar("RSUGGESTS", localdata, 1) or "").split()
174 rprovides = (bb.data.getVar("RPROVIDES", localdata, 1) or "").split()
175 rreplaces = (bb.data.getVar("RREPLACES", localdata, 1) or "").split()
176 rconflicts = (bb.data.getVar("RCONFLICTS", localdata, 1) or "").split()
178 ctrlfile.write("Depends: %s\n" % ", ".join(rdepends))
180 ctrlfile.write("Suggests: %s\n" % ", ".join(rsuggests))
182 ctrlfile.write("Recommends: %s\n" % ", ".join(rrecommends))
184 ctrlfile.write("Provides: %s\n" % ", ".join(rprovides))
186 ctrlfile.write("Replaces: %s\n" % ", ".join(rreplaces))
188 ctrlfile.write("Conflicts: %s\n" % ", ".join(rconflicts))
189 src_uri = bb.data.getVar("SRC_URI", localdata, 1)
191 src_uri = re.sub("\s+", " ", src_uri)
192 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
195 for script in ["preinst", "postinst", "prerm", "postrm"]:
196 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
200 scriptfile = file(os.path.join(controldir, script), 'w')
202 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
203 scriptfile.write(scriptvar)
205 os.chmod(os.path.join(controldir, script), 0755)
207 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
210 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
212 raise bb.build.FuncFailed("unable to open conffiles for writing.")
213 for f in conffiles_str.split():
214 conffiles.write('%s\n' % f)
218 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1),
219 bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
221 raise bb.build.FuncFailed("ipkg-build execution failed")
223 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
224 scriptfile = os.path.join(controldir, script)
226 os.remove(scriptfile)