3 BOOTSTRAP_EXTRA_RDEPENDS += "opkg-collateral opkg"
6 IPKGCONF_TARGET = "${STAGING_ETCDIR_NATIVE}/opkg.conf"
7 IPKGCONF_SDK = "${STAGING_ETCDIR_NATIVE}/opkg-sdk.conf"
9 python package_ipk_fn () {
11 bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
14 python package_ipk_install () {
16 # Warning - this function is not multimachine safe (see stagingdir reference)!
20 pkg = bb.data.getVar('PKG', d, 1)
21 pkgfn = bb.data.getVar('PKGFN', d, 1)
22 rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
23 ipkdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
24 stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
25 tmpdir = bb.data.getVar('TMPDIR', d, 1)
27 if None in (pkg,pkgfn,rootfs):
28 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)")
33 (type, value, traceback) = sys.exc_info()
35 raise bb.build.FuncFailed
37 # Generate ipk.conf if it or the stamp doesnt exist
38 conffile = os.path.join(stagingdir,"opkg.conf")
39 if not os.access(conffile, os.R_OK):
40 ipkg_archs = bb.data.getVar('PACKAGE_ARCHS',d)
41 if ipkg_archs is None:
42 bb.error("PACKAGE_ARCHS missing")
44 ipkg_archs = ipkg_archs.split()
47 f = open(conffile,"w")
48 for arch in ipkg_archs:
49 f.write("arch %s %s\n" % ( arch, arch_priority ))
51 f.write("src local file:%s" % ipkdir)
55 if (not os.access(os.path.join(ipkdir,"Packages"), os.R_OK) or
56 not os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"),os.R_OK):
57 ret = os.system('ipkg-make-index -p %s %s ' % (os.path.join(ipkdir, "Packages"), ipkdir))
59 raise bb.build.FuncFailed
60 f = open(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"),"w")
63 ret = os.system('opkg-cl -o %s -f %s update' % (rootfs, conffile))
64 ret = os.system('opkg-cl -o %s -f %s install %s' % (rootfs, conffile, pkgfn))
66 raise bb.build.FuncFailed
70 # Update the Packages index files in ${DEPLOY_DIR_IPK}
72 package_update_index_ipk () {
75 ipkgarchs="${PACKAGE_ARCHS}"
77 if [ ! -z "${DEPLOY_KEEP_PACKAGES}" ]; then
81 touch ${DEPLOY_DIR_IPK}/Packages
82 ipkg-make-index -r ${DEPLOY_DIR_IPK}/Packages -p ${DEPLOY_DIR_IPK}/Packages -l ${DEPLOY_DIR_IPK}/Packages.filelist -m ${DEPLOY_DIR_IPK}
84 for arch in $ipkgarchs; do
85 if [ -e ${DEPLOY_DIR_IPK}/$arch/ ] ; then
86 touch ${DEPLOY_DIR_IPK}/$arch/Packages
87 ipkg-make-index -r ${DEPLOY_DIR_IPK}/$arch/Packages -p ${DEPLOY_DIR_IPK}/$arch/Packages -l ${DEPLOY_DIR_IPK}/$arch/Packages.filelist -m ${DEPLOY_DIR_IPK}/$arch/
89 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/ ] ; then
90 touch ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages
91 ipkg-make-index -r ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages -p ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages -l ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages.filelist -m ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/
97 # Generate an ipkg conf file ${IPKGCONF_TARGET} suitable for use against
98 # the target system and an ipkg conf file ${IPKGCONF_SDK} suitable for
99 # use against the host system in sdk builds
101 package_generate_ipkg_conf () {
102 mkdir -p ${STAGING_ETCDIR_NATIVE}/
103 echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_TARGET}
104 echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_SDK}
105 ipkgarchs="${PACKAGE_ARCHS}"
107 for arch in $ipkgarchs; do
108 echo "arch $arch $priority" >> ${IPKGCONF_TARGET}
109 echo "arch ${BUILD_ARCH}-$arch-sdk $priority" >> ${IPKGCONF_SDK}
110 priority=$(expr $priority + 5)
111 if [ -e ${DEPLOY_DIR_IPK}/$arch/Packages ] ; then
112 echo "src oe-$arch file:${DEPLOY_DIR_IPK}/$arch" >> ${IPKGCONF_TARGET}
114 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages ] ; then
115 echo "src oe-${BUILD_ARCH}-$arch-sdk file:${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk" >> ${IPKGCONF_SDK}
120 python do_package_ipk () {
123 workdir = bb.data.getVar('WORKDIR', d, 1)
125 bb.error("WORKDIR not defined, unable to package")
128 import os # path manipulations
129 outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
131 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
134 dvar = bb.data.getVar('D', d, 1)
136 bb.error("D not defined, unable to package")
140 tmpdir = bb.data.getVar('TMPDIR', d, 1)
142 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
143 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
145 packages = bb.data.getVar('PACKAGES', d, True)
146 for pkg in packages.split():
147 localdata = bb.data.createCopy(d)
148 pkgdest = bb.data.getVar('PKGDEST', d, 1)
149 root = "%s/%s" % (pkgdest, pkg)
151 lf = bb.utils.lockfile(root + ".lock")
153 bb.data.setVar('ROOT', '', localdata)
154 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
155 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
158 bb.data.setVar('PKG', pkgname, localdata)
160 overrides = bb.data.getVar('OVERRIDES', localdata)
162 raise bb.build.FuncFailed('OVERRIDES not defined')
163 overrides = bb.data.expand(overrides, localdata)
164 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
166 bb.data.update_data(localdata)
167 basedir = os.path.join(os.path.dirname(root))
168 arch = bb.data.getVar('PACKAGE_ARCH', localdata, 1)
169 pkgoutdir = "%s/%s" % (outdir, arch)
170 bb.mkdirhier(pkgoutdir)
172 from glob import glob
175 del g[g.index('CONTROL')]
176 del g[g.index('./CONTROL')]
179 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
181 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
182 bb.utils.unlockfile(lf)
185 controldir = os.path.join(root, 'CONTROL')
186 bb.mkdirhier(controldir)
188 ctrlfile = file(os.path.join(controldir, 'control'), 'w')
190 bb.utils.unlockfile(lf)
191 raise bb.build.FuncFailed("unable to open control file for writing.")
194 pe = bb.data.getVar('PE', d, 1)
195 if pe and int(pe) > 0:
196 fields.append(["Version: %s:%s-%s\n", ['PE', 'PV', 'PR']])
198 fields.append(["Version: %s-%s\n", ['PV', 'PR']])
199 fields.append(["Description: %s\n", ['DESCRIPTION']])
200 fields.append(["Section: %s\n", ['SECTION']])
201 fields.append(["Priority: %s\n", ['PRIORITY']])
202 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
203 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
204 fields.append(["OE: %s\n", ['PN']])
205 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
210 l2.append(bb.data.getVar(i, d, 1))
213 ctrlfile.write("Package: %s\n" % pkgname)
214 # check for required fields
216 for (c, fs) in fields:
218 if bb.data.getVar(f, localdata) is None:
220 ctrlfile.write(c % tuple(pullData(fs, localdata)))
222 (type, value, traceback) = sys.exc_info()
224 bb.utils.unlockfile(lf)
225 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
228 bb.build.exec_func("mapping_rename_hook", localdata)
230 rdepends = explode_deps(bb.data.getVar("RDEPENDS", localdata, 1) or "")
231 rrecommends = explode_deps(bb.data.getVar("RRECOMMENDS", localdata, 1) or "")
232 rsuggests = (bb.data.getVar("RSUGGESTS", localdata, 1) or "").split()
233 rprovides = (bb.data.getVar("RPROVIDES", localdata, 1) or "").split()
234 rreplaces = (bb.data.getVar("RREPLACES", localdata, 1) or "").split()
235 rconflicts = (bb.data.getVar("RCONFLICTS", localdata, 1) or "").split()
237 ctrlfile.write("Depends: %s\n" % ", ".join(rdepends))
239 ctrlfile.write("Suggests: %s\n" % ", ".join(rsuggests))
241 ctrlfile.write("Recommends: %s\n" % ", ".join(rrecommends))
243 ctrlfile.write("Provides: %s\n" % ", ".join(rprovides))
245 ctrlfile.write("Replaces: %s\n" % ", ".join(rreplaces))
247 ctrlfile.write("Conflicts: %s\n" % ", ".join(rconflicts))
248 src_uri = bb.data.getVar("SRC_URI", localdata, 1)
250 src_uri = re.sub("\s+", " ", src_uri)
251 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
254 for script in ["preinst", "postinst", "prerm", "postrm"]:
255 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
259 scriptfile = file(os.path.join(controldir, script), 'w')
261 bb.utils.unlockfile(lf)
262 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
263 scriptfile.write(scriptvar)
265 os.chmod(os.path.join(controldir, script), 0755)
267 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
270 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
272 bb.utils.unlockfile(lf)
273 raise bb.build.FuncFailed("unable to open conffiles for writing.")
274 for f in conffiles_str.split():
275 conffiles.write('%s\n' % f)
279 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1),
280 bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
282 bb.utils.unlockfile(lf)
283 raise bb.build.FuncFailed("ipkg-build execution failed")
285 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
286 scriptfile = os.path.join(controldir, script)
288 os.remove(scriptfile)
295 bb.utils.unlockfile(lf)
300 if bb.data.getVar('PACKAGES', d, True) != '':
301 deps = (bb.data.getVarFlag('do_package_write_ipk', 'depends', d) or "").split()
302 deps.append('ipkg-utils-native:do_populate_staging')
303 deps.append('fakeroot-native:do_populate_staging')
304 bb.data.setVarFlag('do_package_write_ipk', 'depends', " ".join(deps), d)
307 python do_package_write_ipk () {
308 packages = bb.data.getVar('PACKAGES', d, True)
310 bb.debug(1, "No PACKAGES defined, nothing to package")
313 bb.build.exec_func("read_subpackage_metadata", d)
314 bb.build.exec_func("do_package_ipk", d)
316 do_package_write_ipk[dirs] = "${D}"
317 addtask package_write_ipk before do_package_write after do_package