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
70 do_package_update_index_ipk[lockfiles] = "${DEPLOY_DIR_IPK}.lock"
71 do_package_update_index_ipk[nostamp] = "1"
72 do_package_update_index_ipk[recrdeptask] += "do_package_write_ipk"
73 do_package_update_index_ipk[recrdeptask] += "do_package_write_ipk"
74 do_package_update_index_ipk[depends] += "ipkg-utils-native:do_populate_staging"
77 # Update the Packages index files in ${DEPLOY_DIR_IPK}
79 do_package_update_index_ipk () {
82 ipkgarchs="${PACKAGE_ARCHS}"
84 if [ ! -z "${DEPLOY_KEEP_PACKAGES}" ]; then
88 touch ${DEPLOY_DIR_IPK}/Packages
89 ipkg-make-index -r ${DEPLOY_DIR_IPK}/Packages -p ${DEPLOY_DIR_IPK}/Packages -l ${DEPLOY_DIR_IPK}/Packages.filelist -m ${DEPLOY_DIR_IPK}
91 for arch in $ipkgarchs; do
92 if [ -e ${DEPLOY_DIR_IPK}/$arch/ ] ; then
93 touch ${DEPLOY_DIR_IPK}/$arch/Packages
94 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/
96 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/ ] ; then
97 touch ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages
98 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/
100 if [ -e ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/ ] ; then
101 touch ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages
102 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/
108 # Generate an ipkg conf file ${IPKGCONF_TARGET} suitable for use against
109 # the target system and an ipkg conf file ${IPKGCONF_SDK} suitable for
110 # use against the host system in sdk builds
112 package_generate_ipkg_conf () {
113 mkdir -p ${STAGING_ETCDIR_NATIVE}/
114 echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_TARGET}
115 echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_SDK}
116 echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_CANSDK}
117 ipkgarchs="${PACKAGE_ARCHS}"
119 for arch in $ipkgarchs; do
120 echo "arch $arch $priority" >> ${IPKGCONF_TARGET}
121 echo "arch ${BUILD_ARCH}-$arch-sdk $priority" >> ${IPKGCONF_SDK}
122 echo "arch ${SDK_SYS}-sdk-$arch $priority" >> ${IPKGCONF_CANSDK}
123 priority=$(expr $priority + 5)
124 if [ -e ${DEPLOY_DIR_IPK}/$arch/Packages ] ; then
125 echo "src oe-$arch file:${DEPLOY_DIR_IPK}/$arch" >> ${IPKGCONF_TARGET}
127 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages ] ; then
128 echo "src oe-${BUILD_ARCH}-$arch-sdk file:${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk" >> ${IPKGCONF_SDK}
130 if [ -e ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages ] ; then
131 echo "src oe-${SDK_SYS}-sdk-$arch file:${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch" >> ${IPKGCONF_CANSDK}
136 python do_package_ipk () {
137 import sys, re, copy, bb
139 workdir = bb.data.getVar('WORKDIR', d, 1)
141 bb.error("WORKDIR not defined, unable to package")
144 import os # path manipulations
145 outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
147 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
150 dvar = bb.data.getVar('D', d, 1)
152 bb.error("D not defined, unable to package")
156 tmpdir = bb.data.getVar('TMPDIR', d, 1)
158 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
159 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
161 packages = bb.data.getVar('PACKAGES', d, True)
162 for pkg in packages.split():
163 localdata = bb.data.createCopy(d)
164 pkgdest = bb.data.getVar('PKGDEST', d, 1)
165 root = "%s/%s" % (pkgdest, pkg)
167 lf = bb.utils.lockfile(root + ".lock")
169 bb.data.setVar('ROOT', '', localdata)
170 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
171 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
174 bb.data.setVar('PKG', pkgname, localdata)
176 overrides = bb.data.getVar('OVERRIDES', localdata)
178 raise bb.build.FuncFailed('OVERRIDES not defined')
179 overrides = bb.data.expand(overrides, localdata)
180 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
182 bb.data.update_data(localdata)
183 basedir = os.path.join(os.path.dirname(root))
184 arch = bb.data.getVar('PACKAGE_ARCH', localdata, 1)
185 pkgoutdir = "%s/%s" % (outdir, arch)
186 bb.mkdirhier(pkgoutdir)
188 from glob import glob
189 g = glob('*') + glob('.[!.]*')
191 del g[g.index('CONTROL')]
192 del g[g.index('./CONTROL')]
195 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
197 note("Not creating empty archive for %s-%s" % (pkg, bb.data.expand('${PV}-${PR}${DISTRO_PR}', localdata, True)))
198 bb.utils.unlockfile(lf)
201 controldir = os.path.join(root, 'CONTROL')
202 bb.mkdirhier(controldir)
204 ctrlfile = file(os.path.join(controldir, 'control'), 'w')
206 bb.utils.unlockfile(lf)
207 raise bb.build.FuncFailed("unable to open control file for writing.")
210 pe = bb.data.getVar('PE', d, 1)
211 if pe and int(pe) > 0:
212 fields.append(["Version: %s:%s-%s%s\n", ['PE', 'PV', 'PR', 'DISTRO_PR']])
214 fields.append(["Version: %s-%s%s\n", ['PV', 'PR', 'DISTRO_PR']])
215 fields.append(["Description: %s\n", ['DESCRIPTION']])
216 fields.append(["Section: %s\n", ['SECTION']])
217 fields.append(["Priority: %s\n", ['PRIORITY']])
218 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
219 fields.append(["License: %s\n", ['LICENSE']])
220 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
221 fields.append(["OE: %s\n", ['PN']])
222 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
227 l2.append(bb.data.getVar(i, d, 1))
230 ctrlfile.write("Package: %s\n" % pkgname)
231 # check for required fields
233 for (c, fs) in fields:
235 if bb.data.getVar(f, localdata) is None:
237 ctrlfile.write(c % tuple(pullData(fs, localdata)))
239 (type, value, traceback) = sys.exc_info()
241 bb.utils.unlockfile(lf)
242 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
245 bb.build.exec_func("mapping_rename_hook", localdata)
247 rdepends = explode_deps(bb.data.getVar("RDEPENDS", localdata, 1) or "")
248 rrecommends = explode_deps(bb.data.getVar("RRECOMMENDS", localdata, 1) or "")
249 rsuggests = (bb.data.getVar("RSUGGESTS", localdata, 1) or "").split()
250 rprovides = (bb.data.getVar("RPROVIDES", localdata, 1) or "").split()
251 rreplaces = (bb.data.getVar("RREPLACES", localdata, 1) or "").split()
252 rconflicts = (bb.data.getVar("RCONFLICTS", localdata, 1) or "").split()
254 if not '-locale-' and not '-dbg' and not '-dev' in pkgname:
255 rdepends.append('%s-locale*' % pkgname)
258 ctrlfile.write("Depends: %s\n" % ", ".join(rdepends))
260 ctrlfile.write("Suggests: %s\n" % ", ".join(rsuggests))
262 ctrlfile.write("Recommends: %s\n" % ", ".join(rrecommends))
264 ctrlfile.write("Provides: %s\n" % ", ".join(rprovides))
266 ctrlfile.write("Replaces: %s\n" % ", ".join(rreplaces))
268 ctrlfile.write("Conflicts: %s\n" % ", ".join(rconflicts))
269 src_uri = bb.data.getVar("SRC_URI", localdata, 1) or d.getVar("FILE", True)
270 src_uri = re.sub("\s+", " ", src_uri)
271 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
274 for script in ["preinst", "postinst", "prerm", "postrm"]:
275 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
279 scriptfile = file(os.path.join(controldir, script), 'w')
281 bb.utils.unlockfile(lf)
282 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
283 scriptfile.write(scriptvar)
285 os.chmod(os.path.join(controldir, script), 0755)
287 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
290 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
292 bb.utils.unlockfile(lf)
293 raise bb.build.FuncFailed("unable to open conffiles for writing.")
294 for f in conffiles_str.split():
295 conffiles.write('%s\n' % f)
299 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1),
300 bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
302 bb.utils.unlockfile(lf)
303 raise bb.build.FuncFailed("ipkg-build execution failed")
305 bb.utils.prunedir(controldir)
306 bb.utils.unlockfile(lf)
311 if bb.data.getVar('PACKAGES', d, True) != '':
312 deps = (bb.data.getVarFlag('do_package_write_ipk', 'depends', d) or "").split()
313 deps.append('ipkg-utils-native:do_populate_staging')
314 deps.append('fakeroot-native:do_populate_staging')
315 bb.data.setVarFlag('do_package_write_ipk', 'depends', " ".join(deps), d)
318 python do_package_write_ipk () {
320 packages = bb.data.getVar('PACKAGES', d, True)
322 bb.debug(1, "No PACKAGES defined, nothing to package")
325 bb.build.exec_func("read_subpackage_metadata", d)
326 bb.build.exec_func("do_package_ipk", d)
328 do_package_write_ipk[dirs] = "${D}"
329 addtask package_write_ipk before do_package_write after do_package
330 addtask package_update_index_ipk before do_rootfs