3 BOOTSTRAP_EXTRA_RDEPENDS += "opkg-collateral opkg"
6 IPKGCONF_TARGET = "${STAGING_ETCDIR_NATIVE}/opkg.conf"
7 IPKGCONF_SDK = "${STAGING_ETCDIR_NATIVE}/opkg-sdk.conf"
8 IPKGCONF_CANSDK = "${STAGING_ETCDIR_NATIVE}/opkg-canadian-sdk.conf"
10 python package_ipk_fn () {
12 bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
15 python package_ipk_install () {
17 # Warning - this function is not multimachine safe (see stagingdir reference)!
21 pkg = bb.data.getVar('PKG', d, 1)
22 pkgfn = bb.data.getVar('PKGFN', d, 1)
23 rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
24 ipkdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
25 stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
26 tmpdir = bb.data.getVar('TMPDIR', d, 1)
28 if None in (pkg,pkgfn,rootfs):
29 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)")
34 (type, value, traceback) = sys.exc_info()
36 raise bb.build.FuncFailed
38 # Generate ipk.conf if it or the stamp doesnt exist
39 conffile = os.path.join(stagingdir,"opkg.conf")
40 if not os.access(conffile, os.R_OK):
41 ipkg_archs = bb.data.getVar('PACKAGE_ARCHS',d)
42 if ipkg_archs is None:
43 bb.error("PACKAGE_ARCHS missing")
45 ipkg_archs = ipkg_archs.split()
48 f = open(conffile,"w")
49 for arch in ipkg_archs:
50 f.write("arch %s %s\n" % ( arch, arch_priority ))
52 f.write("src local file:%s" % ipkdir)
56 if (not os.access(os.path.join(ipkdir,"Packages"), os.R_OK) or
57 not os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"),os.R_OK):
58 ret = os.system('ipkg-make-index -p %s %s ' % (os.path.join(ipkdir, "Packages"), ipkdir))
60 raise bb.build.FuncFailed
61 f = open(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"),"w")
64 ret = os.system('opkg-cl -o %s -f %s update' % (rootfs, conffile))
65 ret = os.system('opkg-cl -o %s -f %s install %s' % (rootfs, conffile, pkgfn))
67 raise bb.build.FuncFailed
71 # Update the Packages index files in ${DEPLOY_DIR_IPK}
73 package_update_index_ipk () {
76 ipkgarchs="${PACKAGE_ARCHS}"
78 if [ ! -z "${DEPLOY_KEEP_PACKAGES}" ]; then
82 touch ${DEPLOY_DIR_IPK}/Packages
83 ipkg-make-index -r ${DEPLOY_DIR_IPK}/Packages -p ${DEPLOY_DIR_IPK}/Packages -l ${DEPLOY_DIR_IPK}/Packages.filelist -m ${DEPLOY_DIR_IPK}
85 for arch in $ipkgarchs; do
86 if [ -e ${DEPLOY_DIR_IPK}/$arch/ ] ; then
87 touch ${DEPLOY_DIR_IPK}/$arch/Packages
88 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/
90 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/ ] ; then
91 touch ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages
92 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/
94 if [ -e ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/ ] ; then
95 touch ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages
96 ipkg-make-index -r ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages -p ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages -l ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages.filelist -m ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/
102 # Generate an ipkg conf file ${IPKGCONF_TARGET} suitable for use against
103 # the target system and an ipkg conf file ${IPKGCONF_SDK} suitable for
104 # use against the host system in sdk builds
106 package_generate_ipkg_conf () {
107 mkdir -p ${STAGING_ETCDIR_NATIVE}/
108 echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_TARGET}
109 echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_SDK}
110 echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_CANSDK}
111 ipkgarchs="${PACKAGE_ARCHS}"
113 for arch in $ipkgarchs; do
114 echo "arch $arch $priority" >> ${IPKGCONF_TARGET}
115 echo "arch ${BUILD_ARCH}-$arch-sdk $priority" >> ${IPKGCONF_SDK}
116 echo "arch ${SDK_SYS}-sdk-$arch $priority" >> ${IPKGCONF_CANSDK}
117 priority=$(expr $priority + 5)
118 if [ -e ${DEPLOY_DIR_IPK}/$arch/Packages ] ; then
119 echo "src oe-$arch file:${DEPLOY_DIR_IPK}/$arch" >> ${IPKGCONF_TARGET}
121 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages ] ; then
122 echo "src oe-${BUILD_ARCH}-$arch-sdk file:${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk" >> ${IPKGCONF_SDK}
124 if [ -e ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages ] ; then
125 echo "src oe-${SDK_SYS}-sdk-$arch file:${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch" >> ${IPKGCONF_CANSDK}
130 python do_package_ipk () {
131 import sys, re, copy, bb
133 workdir = bb.data.getVar('WORKDIR', d, 1)
135 bb.error("WORKDIR not defined, unable to package")
138 import os # path manipulations
139 outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
141 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
144 dvar = bb.data.getVar('D', d, 1)
146 bb.error("D not defined, unable to package")
150 tmpdir = bb.data.getVar('TMPDIR', d, 1)
152 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
153 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
155 packages = bb.data.getVar('PACKAGES', d, True)
156 for pkg in packages.split():
157 localdata = bb.data.createCopy(d)
158 pkgdest = bb.data.getVar('PKGDEST', d, 1)
159 root = "%s/%s" % (pkgdest, pkg)
161 lf = bb.utils.lockfile(root + ".lock")
163 bb.data.setVar('ROOT', '', localdata)
164 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
165 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
168 bb.data.setVar('PKG', pkgname, localdata)
170 overrides = bb.data.getVar('OVERRIDES', localdata)
172 raise bb.build.FuncFailed('OVERRIDES not defined')
173 overrides = bb.data.expand(overrides, localdata)
174 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
176 bb.data.update_data(localdata)
177 basedir = os.path.join(os.path.dirname(root))
178 arch = bb.data.getVar('PACKAGE_ARCH', localdata, 1)
179 pkgoutdir = "%s/%s" % (outdir, arch)
180 bb.mkdirhier(pkgoutdir)
182 from glob import glob
185 del g[g.index('CONTROL')]
186 del g[g.index('./CONTROL')]
189 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
191 note("Not creating empty archive for %s-%s" % (pkg, bb.data.expand('${PV}-${PR}${DISTRO_PR}', localdata, True)))
192 bb.utils.unlockfile(lf)
195 controldir = os.path.join(root, 'CONTROL')
196 bb.mkdirhier(controldir)
198 ctrlfile = file(os.path.join(controldir, 'control'), 'w')
200 bb.utils.unlockfile(lf)
201 raise bb.build.FuncFailed("unable to open control file for writing.")
204 pe = bb.data.getVar('PE', d, 1)
205 if pe and int(pe) > 0:
206 fields.append(["Version: %s:%s-%s%s\n", ['PE', 'PV', 'PR', 'DISTRO_PR']])
208 fields.append(["Version: %s-%s%s\n", ['PV', 'PR', 'DISTRO_PR']])
209 fields.append(["Description: %s\n", ['DESCRIPTION']])
210 fields.append(["Section: %s\n", ['SECTION']])
211 fields.append(["Priority: %s\n", ['PRIORITY']])
212 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
213 fields.append(["License: %s\n", ['LICENSE']])
214 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
215 fields.append(["OE: %s\n", ['PN']])
216 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
221 l2.append(bb.data.getVar(i, d, 1))
224 ctrlfile.write("Package: %s\n" % pkgname)
225 # check for required fields
227 for (c, fs) in fields:
229 if bb.data.getVar(f, localdata) is None:
231 ctrlfile.write(c % tuple(pullData(fs, localdata)))
233 (type, value, traceback) = sys.exc_info()
235 bb.utils.unlockfile(lf)
236 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
239 bb.build.exec_func("mapping_rename_hook", localdata)
241 rdepends = explode_deps(bb.data.getVar("RDEPENDS", localdata, 1) or "")
242 rrecommends = explode_deps(bb.data.getVar("RRECOMMENDS", localdata, 1) or "")
243 rsuggests = (bb.data.getVar("RSUGGESTS", localdata, 1) or "").split()
244 rprovides = (bb.data.getVar("RPROVIDES", localdata, 1) or "").split()
245 rreplaces = (bb.data.getVar("RREPLACES", localdata, 1) or "").split()
246 rconflicts = (bb.data.getVar("RCONFLICTS", localdata, 1) or "").split()
248 if not '-locale-' and not '-dbg' and not '-dev' in pkgname:
249 rdepends.append('%s-locale*' % pkgname)
252 ctrlfile.write("Depends: %s\n" % ", ".join(rdepends))
254 ctrlfile.write("Suggests: %s\n" % ", ".join(rsuggests))
256 ctrlfile.write("Recommends: %s\n" % ", ".join(rrecommends))
258 ctrlfile.write("Provides: %s\n" % ", ".join(rprovides))
260 ctrlfile.write("Replaces: %s\n" % ", ".join(rreplaces))
262 ctrlfile.write("Conflicts: %s\n" % ", ".join(rconflicts))
263 src_uri = bb.data.getVar("SRC_URI", localdata, 1)
265 src_uri = re.sub("\s+", " ", src_uri)
266 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
269 for script in ["preinst", "postinst", "prerm", "postrm"]:
270 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
274 scriptfile = file(os.path.join(controldir, script), 'w')
276 bb.utils.unlockfile(lf)
277 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
278 scriptfile.write(scriptvar)
280 os.chmod(os.path.join(controldir, script), 0755)
282 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
285 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
287 bb.utils.unlockfile(lf)
288 raise bb.build.FuncFailed("unable to open conffiles for writing.")
289 for f in conffiles_str.split():
290 conffiles.write('%s\n' % f)
294 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1),
295 bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
297 bb.utils.unlockfile(lf)
298 raise bb.build.FuncFailed("ipkg-build execution failed")
300 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
301 scriptfile = os.path.join(controldir, script)
303 os.remove(scriptfile)
310 bb.utils.unlockfile(lf)
315 if bb.data.getVar('PACKAGES', d, True) != '':
316 deps = (bb.data.getVarFlag('do_package_write_ipk', 'depends', d) or "").split()
317 deps.append('ipkg-utils-native:do_populate_staging')
318 deps.append('fakeroot-native:do_populate_staging')
319 bb.data.setVarFlag('do_package_write_ipk', 'depends', " ".join(deps), d)
322 python do_package_write_ipk () {
324 packages = bb.data.getVar('PACKAGES', d, True)
326 bb.debug(1, "No PACKAGES defined, nothing to package")
329 bb.build.exec_func("read_subpackage_metadata", d)
330 bb.build.exec_func("do_package_ipk", d)
332 do_package_write_ipk[dirs] = "${D}"
333 addtask package_write_ipk before do_package_write after do_package