5 IPKGCONF_TARGET = "${STAGING_ETCDIR_NATIVE}/opkg.conf"
6 IPKGCONF_SDK = "${STAGING_ETCDIR_NATIVE}/opkg-sdk.conf"
7 IPKGCONF_CANSDK = "${STAGING_ETCDIR_NATIVE}/opkg-canadian-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)!
19 pkg = bb.data.getVar('PKG', d, 1)
20 pkgfn = bb.data.getVar('PKGFN', d, 1)
21 rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
22 ipkdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
23 stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
24 tmpdir = bb.data.getVar('TMPDIR', d, 1)
26 if None in (pkg,pkgfn,rootfs):
27 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('opkg-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
69 do_package_update_index_ipk[lockfiles] = "${DEPLOY_DIR_IPK}.lock"
70 do_package_update_index_ipk[nostamp] = "1"
71 do_package_update_index_ipk[recrdeptask] += "do_package_write_ipk"
72 do_package_update_index_ipk[recrdeptask] += "do_package_write_ipk"
73 do_package_update_index_ipk[depends] += "opkg-utils-native:do_populate_sysroot"
76 # Update the Packages index files in ${DEPLOY_DIR_IPK}
78 do_package_update_index_ipk () {
81 ipkgarchs="${PACKAGE_ARCHS}"
83 if [ ! -z "${DEPLOY_KEEP_PACKAGES}" ]; then
87 mkdir -p ${DEPLOY_DIR_IPK}
88 touch ${DEPLOY_DIR_IPK}/Packages
89 opkg-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 opkg-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 opkg-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 opkg-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}
134 echo "lists_dir ext /var/lib/opkg" >> ${IPKGCONF_TARGET}
135 echo "lists_dir ext /var/lib/opkg" >> ${IPKGCONF_SDK}
136 echo "lists_dir ext /var/lib/opkg" >> ${IPKGCONF_CANSDK}
139 python do_package_ipk () {
142 workdir = bb.data.getVar('WORKDIR', d, 1)
144 bb.error("WORKDIR not defined, unable to package")
148 outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
150 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
153 dvar = bb.data.getVar('D', d, 1)
155 bb.error("D not defined, unable to package")
159 tmpdir = bb.data.getVar('TMPDIR', d, 1)
161 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
162 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
164 pkgdest = bb.data.getVar('PKGDEST', d, 1)
165 bb.mkdirhier(pkgdest)
167 packages = bb.data.getVar('PACKAGES', d, True)
168 for pkg in packages.split():
169 localdata = bb.data.createCopy(d)
170 root = "%s/%s" % (pkgdest, pkg)
173 lf = bb.utils.lockfile(root + ".lock")
175 bb.data.setVar('ROOT', '', localdata)
176 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
177 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
180 bb.data.setVar('PKG', pkgname, localdata)
182 overrides = bb.data.getVar('OVERRIDES', localdata, True)
184 raise bb.build.FuncFailed('OVERRIDES not defined')
185 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
187 bb.data.update_data(localdata)
188 basedir = os.path.join(os.path.dirname(root))
189 arch = bb.data.getVar('PACKAGE_ARCH', localdata, 1)
190 pkgoutdir = "%s/%s" % (outdir, arch)
191 bb.mkdirhier(pkgoutdir)
193 from glob import glob
194 g = glob('*') + glob('.[!.]*')
196 del g[g.index('CONTROL')]
197 del g[g.index('./CONTROL')]
200 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
201 bb.note("Not creating empty archive for %s-%s" % (pkg, bb.data.expand('${PV}-${PR}${DISTRO_PR}', localdata)))
202 bb.utils.unlockfile(lf)
205 controldir = os.path.join(root, 'CONTROL')
206 bb.mkdirhier(controldir)
208 ctrlfile = file(os.path.join(controldir, 'control'), 'w')
210 bb.utils.unlockfile(lf)
211 raise bb.build.FuncFailed("unable to open control file for writing.")
214 pe = bb.data.getVar('PE', d, 1)
215 if pe and int(pe) > 0:
216 fields.append(["Version: %s:%s-%s\n", ['PE', 'PKGV', 'PKGR']])
218 fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']])
219 fields.append(["Description: %s\n", ['DESCRIPTION']])
220 fields.append(["Section: %s\n", ['SECTION']])
221 fields.append(["Priority: %s\n", ['PRIORITY']])
222 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
223 fields.append(["License: %s\n", ['LICENSE']])
224 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
225 fields.append(["OE: %s\n", ['PN']])
226 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
227 fields.append(["Build: %s/%s\n", ['METADATA_BRANCH', 'METADATA_REVISION']])
232 l2.append(bb.data.getVar(i, d, 1))
235 ctrlfile.write("Package: %s\n" % pkgname)
236 # check for required fields
238 for (c, fs) in fields:
240 if bb.data.getVar(f, localdata) is None:
242 ctrlfile.write(c % tuple(pullData(fs, localdata)))
245 (type, value, traceback) = sys.exc_info()
247 bb.utils.unlockfile(lf)
248 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
251 bb.build.exec_func("mapping_rename_hook", localdata)
253 def write_dep_field(varname, outstring):
254 var = bb.data.getVar(varname, localdata, True)
256 ctrlfile.write('%s: %s\n' % (outstring, ", ".join(explode_deps(var))))
258 write_dep_field('RDEPENDS', 'Depends')
259 write_dep_field('RSUGGESTS', 'Suggests')
260 write_dep_field('RRECOMMENDS', 'Recommends')
261 write_dep_field('RPROVIDES', 'Provides')
262 write_dep_field('RREPLACES', 'Replaces')
263 write_dep_field('RCONFLICTS', 'Conflicts')
265 src_uri = bb.data.getVar("SRC_URI", localdata, 1) or d.getVar("FILE", True)
266 src_uri = re.sub("\s+", " ", src_uri)
267 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
270 for script in ["preinst", "postinst", "prerm", "postrm"]:
271 scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
275 scriptfile = file(os.path.join(controldir, script), 'w')
277 bb.utils.unlockfile(lf)
278 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
279 scriptfile.write(scriptvar)
281 os.chmod(os.path.join(controldir, script), 0755)
283 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
286 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
288 bb.utils.unlockfile(lf)
289 raise bb.build.FuncFailed("unable to open conffiles for writing.")
290 for f in conffiles_str.split():
291 conffiles.write('%s\n' % f)
295 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1),
296 bb.data.getVar("OPKGBUILDCMD",d,1), pkg, pkgoutdir))
298 bb.utils.unlockfile(lf)
299 raise bb.build.FuncFailed("opkg-build execution failed")
301 bb.utils.prunedir(controldir)
302 bb.utils.unlockfile(lf)
306 if bb.data.getVar('PACKAGES', d, True) != '':
307 deps = (bb.data.getVarFlag('do_package_write_ipk', 'depends', d) or "").split()
308 deps.append('opkg-utils-native:do_populate_sysroot')
309 deps.append('fakeroot-native:do_populate_sysroot')
310 bb.data.setVarFlag('do_package_write_ipk', 'depends', " ".join(deps), d)
313 python do_package_write_ipk () {
314 packages = bb.data.getVar('PACKAGES', d, True)
316 bb.debug(1, "No PACKAGES defined, nothing to package")
319 bb.build.exec_func("read_subpackage_metadata", d)
320 bb.build.exec_func("do_package_ipk", d)
322 do_package_write_ipk[dirs] = "${D}"
323 addtask package_write_ipk before do_package_write after do_package
324 addtask package_update_index_ipk before do_rootfs