perl: remove versions 5.8.4 and 5.8.7
[openembedded.git] / classes / package_ipk.bbclass
1 inherit package
2
3 BOOTSTRAP_EXTRA_RDEPENDS += "opkg-collateral opkg"
4 IMAGE_PKGTYPE ?= "ipk"
5
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"
9
10 python package_ipk_fn () {
11         from bb import data
12         bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
13 }
14
15 python package_ipk_install () { 
16         #
17         # Warning - this function is not multimachine safe (see stagingdir reference)!
18         #
19
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)
26
27         if None in (pkg,pkgfn,rootfs):
28                 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)")
29         try:
30                 bb.mkdirhier(rootfs)
31                 os.chdir(rootfs)
32         except OSError:
33                 import sys
34                 (type, value, traceback) = sys.exc_info()
35                 print value
36                 raise bb.build.FuncFailed
37
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")
44                         raise FuncFailed
45                 ipkg_archs = ipkg_archs.split()
46                 arch_priority = 1
47
48                 f = open(conffile,"w")
49                 for arch in ipkg_archs:
50                         f.write("arch %s %s\n" % ( arch, arch_priority ))
51                         arch_priority += 1
52                 f.write("src local file:%s" % ipkdir)
53                 f.close()
54
55
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))
59                 if (ret != 0 ):
60                         raise bb.build.FuncFailed
61                 f = open(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"),"w")
62                 f.close()
63
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))
66         if (ret != 0 ):
67                 raise bb.build.FuncFailed
68 }
69
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"
75
76 #
77 # Update the Packages index files in ${DEPLOY_DIR_IPK}
78 #
79 do_package_update_index_ipk () {
80         set -x
81
82         ipkgarchs="${PACKAGE_ARCHS}"
83
84         if [ ! -z "${DEPLOY_KEEP_PACKAGES}" ]; then
85                 return
86         fi
87
88         mkdir -p ${DEPLOY_DIR_IPK}
89         touch ${DEPLOY_DIR_IPK}/Packages
90         ipkg-make-index -r ${DEPLOY_DIR_IPK}/Packages -p ${DEPLOY_DIR_IPK}/Packages -l ${DEPLOY_DIR_IPK}/Packages.filelist -m ${DEPLOY_DIR_IPK}
91
92         for arch in $ipkgarchs; do
93                 if [ -e ${DEPLOY_DIR_IPK}/$arch/ ] ; then 
94                         touch ${DEPLOY_DIR_IPK}/$arch/Packages
95                         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                 fi
97                 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/ ] ; then 
98                         touch ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages
99                         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                 fi
101                 if [ -e ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/ ] ; then
102                         touch ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages
103                         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/
104                 fi
105         done
106 }
107
108 #
109 # Generate an ipkg conf file ${IPKGCONF_TARGET} suitable for use against 
110 # the target system and an ipkg conf file ${IPKGCONF_SDK} suitable for 
111 # use against the host system in sdk builds
112 #
113 package_generate_ipkg_conf () {
114         mkdir -p ${STAGING_ETCDIR_NATIVE}/
115         echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_TARGET}
116         echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_SDK}
117         echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_CANSDK}
118         ipkgarchs="${PACKAGE_ARCHS}"
119         priority=1
120         for arch in $ipkgarchs; do
121                 echo "arch $arch $priority" >> ${IPKGCONF_TARGET}
122                 echo "arch ${BUILD_ARCH}-$arch-sdk $priority" >> ${IPKGCONF_SDK}
123                 echo "arch ${SDK_SYS}-sdk-$arch $priority" >> ${IPKGCONF_CANSDK}
124                 priority=$(expr $priority + 5)
125                 if [ -e ${DEPLOY_DIR_IPK}/$arch/Packages ] ; then
126                         echo "src oe-$arch file:${DEPLOY_DIR_IPK}/$arch" >> ${IPKGCONF_TARGET}
127                 fi
128                 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages ] ; then
129                         echo "src oe-${BUILD_ARCH}-$arch-sdk file:${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk" >> ${IPKGCONF_SDK}
130                 fi
131                 if [ -e ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages ] ; then
132                         echo "src oe-${SDK_SYS}-sdk-$arch file:${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch" >> ${IPKGCONF_CANSDK}
133                 fi
134         done
135 }
136
137 python do_package_ipk () {
138         import re, copy
139
140         workdir = bb.data.getVar('WORKDIR', d, 1)
141         if not workdir:
142                 bb.error("WORKDIR not defined, unable to package")
143                 return
144
145
146         outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
147         if not outdir:
148                 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
149                 return
150
151         dvar = bb.data.getVar('D', d, 1)
152         if not dvar:
153                 bb.error("D not defined, unable to package")
154                 return
155         bb.mkdirhier(dvar)
156
157         tmpdir = bb.data.getVar('TMPDIR', d, 1)
158
159         if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
160                 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
161
162         pkgdest = bb.data.getVar('PKGDEST', d, 1)
163         bb.mkdirhier(pkgdest)
164
165         packages = bb.data.getVar('PACKAGES', d, True)
166         for pkg in packages.split():
167                 localdata = bb.data.createCopy(d)
168                 root = "%s/%s" % (pkgdest, pkg)
169                 bb.mkdirhier(root)
170
171                 lf = bb.utils.lockfile(root + ".lock")
172
173                 bb.data.setVar('ROOT', '', localdata)
174                 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
175                 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
176                 if not pkgname:
177                         pkgname = pkg
178                 bb.data.setVar('PKG', pkgname, localdata)
179
180                 overrides = bb.data.getVar('OVERRIDES', localdata, True)
181                 if not overrides:
182                         raise bb.build.FuncFailed('OVERRIDES not defined')
183                 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
184
185                 bb.data.update_data(localdata)
186                 basedir = os.path.join(os.path.dirname(root))
187                 arch = bb.data.getVar('PACKAGE_ARCH', localdata, 1)
188                 pkgoutdir = "%s/%s" % (outdir, arch)
189                 bb.mkdirhier(pkgoutdir)
190                 os.chdir(root)
191                 from glob import glob
192                 g = glob('*') + glob('.[!.]*')
193                 try:
194                         del g[g.index('CONTROL')]
195                         del g[g.index('./CONTROL')]
196                 except ValueError:
197                         pass
198                 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
199                         bb.note("Not creating empty archive for %s-%s" % (pkg, bb.data.expand('${PV}-${PR}${DISTRO_PR}', localdata, True)))
200                         bb.utils.unlockfile(lf)
201                         continue
202
203                 controldir = os.path.join(root, 'CONTROL')
204                 bb.mkdirhier(controldir)
205                 try:
206                         ctrlfile = file(os.path.join(controldir, 'control'), 'w')
207                 except OSError:
208                         bb.utils.unlockfile(lf)
209                         raise bb.build.FuncFailed("unable to open control file for writing.")
210
211                 fields = []
212                 pe = bb.data.getVar('PE', d, 1)
213                 if pe and int(pe) > 0:
214                         fields.append(["Version: %s:%s-%s\n", ['PE', 'PKGV', 'PKGR']])
215                 else:
216                         fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']])
217                 fields.append(["Description: %s\n", ['DESCRIPTION']])
218                 fields.append(["Section: %s\n", ['SECTION']])
219                 fields.append(["Priority: %s\n", ['PRIORITY']])
220                 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
221                 fields.append(["License: %s\n", ['LICENSE']])
222                 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
223                 fields.append(["OE: %s\n", ['PN']])
224                 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
225
226                 def pullData(l, d):
227                         l2 = []
228                         for i in l:
229                                 l2.append(bb.data.getVar(i, d, 1))
230                         return l2
231
232                 ctrlfile.write("Package: %s\n" % pkgname)
233                 # check for required fields
234                 try:
235                         for (c, fs) in fields:
236                                 for f in fs:
237                                         if bb.data.getVar(f, localdata) is None:
238                                                 raise KeyError(f)
239                                 ctrlfile.write(c % tuple(pullData(fs, localdata)))
240                 except KeyError:
241                         import sys
242                         (type, value, traceback) = sys.exc_info()
243                         ctrlfile.close()
244                         bb.utils.unlockfile(lf)
245                         raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
246                 # more fields
247
248                 bb.build.exec_func("mapping_rename_hook", localdata)
249
250                 rdepends = explode_deps(bb.data.getVar("RDEPENDS", localdata, 1) or "")
251                 rrecommends = explode_deps(bb.data.getVar("RRECOMMENDS", localdata, 1) or "")
252                 rsuggests = (bb.data.getVar("RSUGGESTS", localdata, 1) or "").split()
253                 rprovides = (bb.data.getVar("RPROVIDES", localdata, 1) or "").split()
254                 rreplaces = (bb.data.getVar("RREPLACES", localdata, 1) or "").split()
255                 rconflicts = (bb.data.getVar("RCONFLICTS", localdata, 1) or "").split()
256
257                 if not '-locale-' and not '-dbg' and not '-dev' in pkgname:
258                         rdepends.append('%s-locale*' % pkgname)
259
260                 if rdepends:
261                         ctrlfile.write("Depends: %s\n" % ", ".join(rdepends))
262                 if rsuggests:
263                         ctrlfile.write("Suggests: %s\n" % ", ".join(rsuggests))
264                 if rrecommends:
265                         ctrlfile.write("Recommends: %s\n" % ", ".join(rrecommends))
266                 if rprovides:
267                         ctrlfile.write("Provides: %s\n" % ", ".join(rprovides))
268                 if rreplaces:
269                         ctrlfile.write("Replaces: %s\n" % ", ".join(rreplaces))
270                 if rconflicts:
271                         ctrlfile.write("Conflicts: %s\n" % ", ".join(rconflicts))
272                 src_uri = bb.data.getVar("SRC_URI", localdata, 1) or d.getVar("FILE", True)
273                 src_uri = re.sub("\s+", " ", src_uri)
274                 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
275                 ctrlfile.close()
276
277                 for script in ["preinst", "postinst", "prerm", "postrm"]:
278                         scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
279                         if not scriptvar:
280                                 continue
281                         try:
282                                 scriptfile = file(os.path.join(controldir, script), 'w')
283                         except OSError:
284                                 bb.utils.unlockfile(lf)
285                                 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
286                         scriptfile.write(scriptvar)
287                         scriptfile.close()
288                         os.chmod(os.path.join(controldir, script), 0755)
289
290                 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
291                 if conffiles_str:
292                         try:
293                                 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
294                         except OSError:
295                                 bb.utils.unlockfile(lf)
296                                 raise bb.build.FuncFailed("unable to open conffiles for writing.")
297                         for f in conffiles_str.split():
298                                 conffiles.write('%s\n' % f)
299                         conffiles.close()
300
301                 os.chdir(basedir)
302                 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1), 
303                                                           bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
304                 if ret != 0:
305                         bb.utils.unlockfile(lf)
306                         raise bb.build.FuncFailed("ipkg-build execution failed")
307
308                 bb.utils.prunedir(controldir)
309                 bb.utils.unlockfile(lf)
310 }
311
312 python () {
313     if bb.data.getVar('PACKAGES', d, True) != '':
314         deps = (bb.data.getVarFlag('do_package_write_ipk', 'depends', d) or "").split()
315         deps.append('ipkg-utils-native:do_populate_staging')
316         deps.append('fakeroot-native:do_populate_staging')
317         bb.data.setVarFlag('do_package_write_ipk', 'depends', " ".join(deps), d)
318 }
319
320 python do_package_write_ipk () {
321         packages = bb.data.getVar('PACKAGES', d, True)
322         if not packages:
323                 bb.debug(1, "No PACKAGES defined, nothing to package")
324                 return
325
326         bb.build.exec_func("read_subpackage_metadata", d)
327         bb.build.exec_func("do_package_ipk", d)
328 }
329 do_package_write_ipk[dirs] = "${D}"
330 addtask package_write_ipk before do_package_write after do_package
331 addtask package_update_index_ipk before do_rootfs