diff options
author | Richard Purdie <richard@openedhand.com> | 2006-07-21 10:10:31 +0000 |
---|---|---|
committer | Richard Purdie <richard@openedhand.com> | 2006-07-21 10:10:31 +0000 |
commit | b2f192faabe412adce79534e22efe9fb69ee40e2 (patch) | |
tree | 7076c49d4286f8a1733650bd8fbc7161af200d57 /meta/classes/package_ipk.bbclass | |
parent | 2cf0eadf9f730027833af802d7e6c90b44248f80 (diff) | |
download | poky-b2f192faabe412adce79534e22efe9fb69ee40e2.tar.gz |
Rename /openembedded/ -> /meta/
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@530 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'meta/classes/package_ipk.bbclass')
-rw-r--r-- | meta/classes/package_ipk.bbclass | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass new file mode 100644 index 0000000000..9ae526bb3b --- /dev/null +++ b/meta/classes/package_ipk.bbclass | |||
@@ -0,0 +1,234 @@ | |||
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 | PACKAGEFUNCS += "do_package_ipk" | ||
5 | |||
6 | python package_ipk_fn () { | ||
7 | from bb import data | ||
8 | bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d) | ||
9 | } | ||
10 | |||
11 | python package_ipk_install () { | ||
12 | import os, sys | ||
13 | pkg = bb.data.getVar('PKG', d, 1) | ||
14 | pkgfn = bb.data.getVar('PKGFN', d, 1) | ||
15 | rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1) | ||
16 | ipkdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1) | ||
17 | stagingdir = bb.data.getVar('STAGING_DIR', d, 1) | ||
18 | tmpdir = bb.data.getVar('TMPDIR', d, 1) | ||
19 | |||
20 | if None in (pkg,pkgfn,rootfs): | ||
21 | raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)") | ||
22 | try: | ||
23 | bb.mkdirhier(rootfs) | ||
24 | os.chdir(rootfs) | ||
25 | except OSError: | ||
26 | (type, value, traceback) = sys.exc_info() | ||
27 | print value | ||
28 | raise bb.build.FuncFailed | ||
29 | |||
30 | # Generate ipk.conf if it or the stamp doesnt exist | ||
31 | conffile = os.path.join(stagingdir,"ipkg.conf") | ||
32 | if not os.access(conffile, os.R_OK): | ||
33 | ipkg_archs = bb.data.getVar('IPKG_ARCHS',d) | ||
34 | if ipkg_archs is None: | ||
35 | bb.error("IPKG_ARCHS missing") | ||
36 | raise FuncFailed | ||
37 | ipkg_archs = ipkg_archs.split() | ||
38 | arch_priority = 1 | ||
39 | |||
40 | f = open(conffile,"w") | ||
41 | for arch in ipkg_archs: | ||
42 | f.write("arch %s %s\n" % ( arch, arch_priority )) | ||
43 | arch_priority += 1 | ||
44 | f.write("src local file:%s" % ipkdir) | ||
45 | f.close() | ||
46 | |||
47 | |||
48 | if (not os.access(os.path.join(ipkdir,"Packages"), os.R_OK) or | ||
49 | not os.access(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),os.R_OK)): | ||
50 | ret = os.system('ipkg-make-index -p %s %s ' % (os.path.join(ipkdir, "Packages"), ipkdir)) | ||
51 | if (ret != 0 ): | ||
52 | raise bb.build.FuncFailed | ||
53 | f=open(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),"w") | ||
54 | f.close() | ||
55 | |||
56 | ret = os.system('ipkg-cl -o %s -f %s update' % (rootfs, conffile)) | ||
57 | ret = os.system('ipkg-cl -o %s -f %s install %s' % (rootfs, conffile, pkgfn)) | ||
58 | if (ret != 0 ): | ||
59 | raise bb.build.FuncFailed | ||
60 | } | ||
61 | |||
62 | python do_package_ipk () { | ||
63 | import copy # to back up env data | ||
64 | import sys | ||
65 | import re | ||
66 | |||
67 | workdir = bb.data.getVar('WORKDIR', d, 1) | ||
68 | if not workdir: | ||
69 | bb.error("WORKDIR not defined, unable to package") | ||
70 | return | ||
71 | |||
72 | import os # path manipulations | ||
73 | outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1) | ||
74 | if not outdir: | ||
75 | bb.error("DEPLOY_DIR_IPK not defined, unable to package") | ||
76 | return | ||
77 | bb.mkdirhier(outdir) | ||
78 | |||
79 | dvar = bb.data.getVar('D', d, 1) | ||
80 | if not dvar: | ||
81 | bb.error("D not defined, unable to package") | ||
82 | return | ||
83 | bb.mkdirhier(dvar) | ||
84 | |||
85 | packages = bb.data.getVar('PACKAGES', d, 1) | ||
86 | if not packages: | ||
87 | bb.debug(1, "PACKAGES not defined, nothing to package") | ||
88 | return | ||
89 | |||
90 | tmpdir = bb.data.getVar('TMPDIR', d, 1) | ||
91 | # Invalidate the packages file | ||
92 | if os.access(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages"),os.R_OK): | ||
93 | os.unlink(os.path.join(os.path.join(tmpdir, "stamps"),"do_packages")) | ||
94 | |||
95 | if packages == []: | ||
96 | bb.debug(1, "No packages; nothing to do") | ||
97 | return | ||
98 | |||
99 | for pkg in packages.split(): | ||
100 | localdata = bb.data.createCopy(d) | ||
101 | root = "%s/install/%s" % (workdir, pkg) | ||
102 | |||
103 | bb.data.setVar('ROOT', '', localdata) | ||
104 | bb.data.setVar('ROOT_%s' % pkg, root, localdata) | ||
105 | pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1) | ||
106 | if not pkgname: | ||
107 | pkgname = pkg | ||
108 | bb.data.setVar('PKG', pkgname, localdata) | ||
109 | |||
110 | overrides = bb.data.getVar('OVERRIDES', localdata) | ||
111 | if not overrides: | ||
112 | raise bb.build.FuncFailed('OVERRIDES not defined') | ||
113 | overrides = bb.data.expand(overrides, localdata) | ||
114 | bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata) | ||
115 | |||
116 | bb.data.update_data(localdata) | ||
117 | basedir = os.path.join(os.path.dirname(root)) | ||
118 | pkgoutdir = outdir | ||
119 | bb.mkdirhier(pkgoutdir) | ||
120 | os.chdir(root) | ||
121 | from glob import glob | ||
122 | g = glob('*') | ||
123 | try: | ||
124 | del g[g.index('CONTROL')] | ||
125 | del g[g.index('./CONTROL')] | ||
126 | except ValueError: | ||
127 | pass | ||
128 | if not g and not bb.data.getVar('ALLOW_EMPTY', localdata): | ||
129 | from bb import note | ||
130 | note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1))) | ||
131 | continue | ||
132 | controldir = os.path.join(root, 'CONTROL') | ||
133 | bb.mkdirhier(controldir) | ||
134 | try: | ||
135 | ctrlfile = file(os.path.join(controldir, 'control'), 'w') | ||
136 | except OSError: | ||
137 | raise bb.build.FuncFailed("unable to open control file for writing.") | ||
138 | |||
139 | fields = [] | ||
140 | fields.append(["Version: %s-%s\n", ['PV', 'PR']]) | ||
141 | fields.append(["Description: %s\n", ['DESCRIPTION']]) | ||
142 | fields.append(["Section: %s\n", ['SECTION']]) | ||
143 | fields.append(["Priority: %s\n", ['PRIORITY']]) | ||
144 | fields.append(["Maintainer: %s\n", ['MAINTAINER']]) | ||
145 | fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']]) | ||
146 | fields.append(["OE: %s\n", ['P']]) | ||
147 | fields.append(["Homepage: %s\n", ['HOMEPAGE']]) | ||
148 | |||
149 | def pullData(l, d): | ||
150 | l2 = [] | ||
151 | for i in l: | ||
152 | l2.append(bb.data.getVar(i, d, 1)) | ||
153 | return l2 | ||
154 | |||
155 | ctrlfile.write("Package: %s\n" % pkgname) | ||
156 | # check for required fields | ||
157 | try: | ||
158 | for (c, fs) in fields: | ||
159 | for f in fs: | ||
160 | if bb.data.getVar(f, localdata) is None: | ||
161 | raise KeyError(f) | ||
162 | ctrlfile.write(c % tuple(pullData(fs, localdata))) | ||
163 | except KeyError: | ||
164 | (type, value, traceback) = sys.exc_info() | ||
165 | ctrlfile.close() | ||
166 | raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value) | ||
167 | # more fields | ||
168 | |||
169 | bb.build.exec_func("mapping_rename_hook", localdata) | ||
170 | |||
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 | } | ||