]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/classes/package_ipk.bbclass
gnutls: bump PR. don't use _prepend for do_configure.
[familiar-h63xx-build.git] / org.handhelds.familiar / classes / package_ipk.bbclass
1 inherit package
2 DEPENDS_prepend="${@["ipkg-utils-native ", ""][(bb.data.getVar('PACKAGES', d, 1) == '')]}"
3 BOOTSTRAP_EXTRA_RDEPENDS += "ipkg-collateral ipkg ipkg-link"
4 BOOTSTRAP_EXTRA_DEPENDS  += "ipkg-collateral ipkg ipkg-link"
5 PACKAGEFUNCS += "do_package_ipk"
6
7 python package_ipk_fn () {
8         from bb import data
9         bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
10 }
11
12 python package_ipk_install () {
13         import os, sys
14         pkg = bb.data.getVar('PKG', d, 1)
15         pkgfn = bb.data.getVar('PKGFN', d, 1)
16         rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
17         ipkdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
18         stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
19         tmpdir = bb.data.getVar('TMPDIR', d, 1)
20
21         if None in (pkg,pkgfn,rootfs):
22                 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)")
23         try:
24                 bb.mkdirhier(rootfs)
25                 os.chdir(rootfs)
26         except OSError:
27                 (type, value, traceback) = sys.exc_info()
28                 print value
29                 raise bb.build.FuncFailed
30
31         # Generate ipk.conf if it or the stamp doesnt exist
32         conffile = os.path.join(stagingdir,"ipkg.conf")
33         if not  os.access(conffile, os.R_OK):
34                 ipkg_archs = bb.data.getVar('IPKG_ARCHS',d)
35                 if ipkg_archs is None:
36                         bb.error("IPKG_ARCHS missing")
37                         raise FuncFailed
38                 ipkg_archs = ipkg_archs.split()
39                 arch_priority = 1
40
41                 f = open(conffile,"w")
42                 for arch in ipkg_archs:
43                         f.write("arch %s %s\n" % ( arch, arch_priority ))
44                         arch_priority += 1
45                 f.write("src local file:%s" % ipkdir)
46                 f.close()
47
48
49         if (not os.access(os.path.join(ipkdir,"Packages"), os.R_OK) or
50                 not os.access(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),os.R_OK)):
51                 ret = os.system('ipkg-make-index -p %s %s ' % (os.path.join(ipkdir, "Packages"), ipkdir))
52                 if (ret != 0 ):
53                         raise bb.build.FuncFailed
54                 f=open(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),"w")
55                 f.close()
56
57         ret = os.system('ipkg-cl  -o %s -f %s update' % (rootfs, conffile))
58         ret = os.system('ipkg-cl  -o %s -f %s install %s' % (rootfs, conffile, pkgfn))
59         if (ret != 0 ):
60                 raise bb.build.FuncFailed
61 }
62
63 EPOCH ?= ""
64
65 python do_package_ipk () {
66         import copy # to back up env data
67         import sys
68         import re
69
70         workdir = bb.data.getVar('WORKDIR', d, 1)
71         if not workdir:
72                 bb.error("WORKDIR not defined, unable to package")
73                 return
74
75         import os # path manipulations
76         outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
77         if not outdir:
78                 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
79                 return
80         bb.mkdirhier(outdir)
81
82         dvar = bb.data.getVar('D', d, 1)
83         if not dvar:
84                 bb.error("D not defined, unable to package")
85                 return
86         bb.mkdirhier(dvar)
87
88         packages = bb.data.getVar('PACKAGES', d, 1)
89         if not packages:
90                 bb.debug(1, "PACKAGES not defined, nothing to package")
91                 return
92
93         tmpdir = bb.data.getVar('TMPDIR', d, 1)
94         # Invalidate the packages file
95         if os.access(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),os.R_OK):
96                 os.unlink(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"))
97
98         if packages == []:
99                 bb.debug(1, "No packages; nothing to do")
100                 return
101
102         for pkg in packages.split():
103                 localdata = bb.data.createCopy(d)
104                 root = "%s/install/%s" % (workdir, pkg)
105
106                 bb.data.setVar('ROOT', '', localdata)
107                 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
108                 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
109                 if not pkgname:
110                         pkgname = pkg
111                 bb.data.setVar('PKG', pkgname, localdata)
112
113                 overrides = bb.data.getVar('OVERRIDES', localdata)
114                 if not overrides:
115                         raise bb.build.FuncFailed('OVERRIDES not defined')
116                 overrides = bb.data.expand(overrides, localdata)
117                 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
118
119                 bb.data.update_data(localdata)
120                 basedir = os.path.join(os.path.dirname(root))
121                 pkgoutdir = outdir
122                 bb.mkdirhier(pkgoutdir)
123                 os.chdir(root)
124                 from glob import glob
125                 g = glob('*')
126                 try:
127                         del g[g.index('CONTROL')]
128                         del g[g.index('./CONTROL')]
129                 except ValueError:
130                         pass
131                 if not g and not bb.data.getVar('ALLOW_EMPTY', localdata):
132                         from bb import note
133                         note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
134                         continue
135                 controldir = os.path.join(root, 'CONTROL')
136                 bb.mkdirhier(controldir)
137                 try:
138                         ctrlfile = file(os.path.join(controldir, 'control'), 'w')
139                 except OSError:
140                         raise bb.build.FuncFailed("unable to open control file for writing.")
141
142                 fields = []
143                 fields.append(["Version: %s%s-%s\n", ['EPOCH', 'PV', 'PR']])
144                 fields.append(["Description: %s\n", ['DESCRIPTION']])
145                 fields.append(["Section: %s\n", ['SECTION']])
146                 fields.append(["Priority: %s\n", ['PRIORITY']])
147                 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
148                 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
149                 fields.append(["OE: %s\n", ['P']])
150                 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
151
152                 def pullData(l, d):
153                         l2 = []
154                         for i in l:
155                                 l2.append(bb.data.getVar(i, d, 1))
156                         return l2
157
158                 ctrlfile.write("Package: %s\n" % pkgname)
159                 # check for required fields
160                 try:
161                         for (c, fs) in fields:
162                                 for f in fs:
163                                         if bb.data.getVar(f, localdata) is None:
164                                                 raise KeyError(f)
165                                 ctrlfile.write(c % tuple(pullData(fs, localdata)))
166                 except KeyError:
167                         (type, value, traceback) = sys.exc_info()
168                         ctrlfile.close()
169                         raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
170                 # more fields
171                 rdepends = explode_deps(bb.data.getVar("RDEPENDS", localdata, 1) or "")
172                 rrecommends = explode_deps(bb.data.getVar("RRECOMMENDS", localdata, 1) or "")
173                 rsuggests = (bb.data.getVar("RSUGGESTS", localdata, 1) or "").split()
174                 rprovides = (bb.data.getVar("RPROVIDES", localdata, 1) or "").split()
175                 rreplaces = (bb.data.getVar("RREPLACES", localdata, 1) or "").split()
176                 rconflicts = (bb.data.getVar("RCONFLICTS", localdata, 1) or "").split()
177                 if rdepends:
178                         ctrlfile.write("Depends: %s\n" % ", ".join(rdepends))
179                 if rsuggests:
180                         ctrlfile.write("Suggests: %s\n" % ", ".join(rsuggests))
181                 if rrecommends:
182                         ctrlfile.write("Recommends: %s\n" % ", ".join(rrecommends))
183                 if rprovides:
184                         ctrlfile.write("Provides: %s\n" % ", ".join(rprovides))
185                 if rreplaces:
186                         ctrlfile.write("Replaces: %s\n" % ", ".join(rreplaces))
187                 if rconflicts:
188                         ctrlfile.write("Conflicts: %s\n" % ", ".join(rconflicts))
189                 src_uri = bb.data.getVar("SRC_URI", localdata, 1)
190                 if src_uri:
191                         src_uri = re.sub("\s+", " ", src_uri)
192                         ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
193                 ctrlfile.close()
194
195                 for script in ["preinst", "postinst", "prerm", "postrm"]:
196                         scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
197                         if not scriptvar:
198                                 continue
199                         try:
200                                 scriptfile = file(os.path.join(controldir, script), 'w')
201                         except OSError:
202                                 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
203                         scriptfile.write(scriptvar)
204                         scriptfile.close()
205                         os.chmod(os.path.join(controldir, script), 0755)
206
207                 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
208                 if conffiles_str:
209                         try:
210                                 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
211                         except OSError:
212                                 raise bb.build.FuncFailed("unable to open conffiles for writing.")
213                         for f in conffiles_str.split():
214                                 conffiles.write('%s\n' % f)
215                         conffiles.close()
216
217                 os.chdir(basedir)
218                 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1), 
219                                                           bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
220                 if ret != 0:
221                         raise bb.build.FuncFailed("ipkg-build execution failed")
222
223                 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
224                         scriptfile = os.path.join(controldir, script)
225                         try:
226                                 os.remove(scriptfile)
227                         except OSError:
228                                 pass
229                 try:
230                         os.rmdir(controldir)
231                 except OSError:
232                         pass
233                 del localdata
234 }