diff options
author | Mark Hatle <mhatle@windriver.com> | 2010-08-20 09:52:39 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-08-23 20:55:14 +0100 |
commit | 55a046bd4c4bf6e8ebb41a68205f46795f56fdbc (patch) | |
tree | 0c8c41f14598d5591fb28f4a0e1bfae5fa77ca84 /meta/classes/package_rpm.bbclass | |
parent | f29f9364a3f14203d5883a9e95f38afa5926249f (diff) | |
download | poky-55a046bd4c4bf6e8ebb41a68205f46795f56fdbc.tar.gz |
package_rpm: Rewrite the way the spec files are generated
Use a single spec file to generate all of the split packages. This allows
us to ensure the RPM package source package meta data is correct, and also
speeds up the package generation process.
Signed-off-by: Mark Hatle <mhatle@windriver.com>
Diffstat (limited to 'meta/classes/package_rpm.bbclass')
-rw-r--r-- | meta/classes/package_rpm.bbclass | 546 |
1 files changed, 377 insertions, 169 deletions
diff --git a/meta/classes/package_rpm.bbclass b/meta/classes/package_rpm.bbclass index 7a1f8e08fd..3334c9ae6a 100644 --- a/meta/classes/package_rpm.bbclass +++ b/meta/classes/package_rpm.bbclass | |||
@@ -2,178 +2,113 @@ inherit package | |||
2 | 2 | ||
3 | IMAGE_PKGTYPE ?= "rpm" | 3 | IMAGE_PKGTYPE ?= "rpm" |
4 | 4 | ||
5 | RPMBUILDPATH="${WORKDIR}/rpm" | 5 | RPM="${BUILD_ARCH}-${BUILD_OS}-rpm" |
6 | 6 | RPMBUILD="${BUILD_ARCH}-${BUILD_OS}-rpmbuild" | |
7 | RPMOPTS="" | ||
8 | RPMBUILDOPTS="--target ${TARGET_SYS} --define '_topdir ${RPMBUILDPATH}' --buildroot ${ROOT}" | ||
9 | RPM="${BUILD_ARCH}-${BUILD_OS}-rpm ${RPMOPTS}" | ||
10 | RPMBUILD="${BUILD_ARCH}-${BUILD_OS}-rpmbuild --short-circuit ${RPMBUILDOPTS}" | ||
11 | |||
12 | PKGWRITEDIRRPM = ${WORKDIR}/deploy-rpms" | ||
13 | |||
14 | python write_specfile() { | ||
15 | version = bb.data.getVar('PV', d, 1) | ||
16 | version = version.replace('-', '+') | ||
17 | bb.data.setVar('RPMPV', version, d) | ||
18 | |||
19 | out_vartranslate = { | ||
20 | "PKG": "Name", | ||
21 | "RPMPV": "Version", | ||
22 | "PR": "Release", | ||
23 | "DESCRIPTION": "%description", | ||
24 | "LICENSE": "License", | ||
25 | "SECTION": "Group", | ||
26 | "pkg_postinst": "%post", | ||
27 | "pkg_preinst": "%pre", | ||
28 | } | ||
29 | |||
30 | root = bb.data.getVar('ROOT', d) | ||
31 | |||
32 | # get %files | ||
33 | filesvar = bb.data.expand(bb.data.getVar('FILES', d), d) or "" | ||
34 | from glob import glob | ||
35 | files = filesvar.split() | ||
36 | todelete = [] | ||
37 | for file in files: | ||
38 | if file[0] == '.': | ||
39 | newfile = file[1:] | ||
40 | files[files.index(file)] = newfile | ||
41 | file = newfile | ||
42 | else: | ||
43 | newfile = file | ||
44 | realfile = os.path.join(root, './'+file) | ||
45 | if not glob(realfile): | ||
46 | todelete.append(files[files.index(newfile)]) | ||
47 | for r in todelete: | ||
48 | try: | ||
49 | del files[files.index(r)] | ||
50 | except ValueError: | ||
51 | pass | ||
52 | |||
53 | if not files and bb.data.getVar('ALLOW_EMPTY', d) != "1": | ||
54 | bb.note("Not creating empty archive for %s-%s-%s" % (bb.data.getVar('PKG',d, 1), bb.data.getVar('PV', d, 1), bb.data.getVar('PR', d, 1))) | ||
55 | return | ||
56 | |||
57 | # output .spec using this metadata store | ||
58 | try: | ||
59 | from __builtin__ import file | ||
60 | if not bb.data.getVar('OUTSPECFILE', d): | ||
61 | raise OSError('eek!') | ||
62 | specfile = file(bb.data.getVar('OUTSPECFILE', d), 'w') | ||
63 | except OSError: | ||
64 | raise bb.build.FuncFailed("unable to open spec file for writing.") | ||
65 | |||
66 | fd = specfile | ||
67 | for var in out_vartranslate.keys(): | ||
68 | if out_vartranslate[var][0] == "%": | ||
69 | continue | ||
70 | val = bb.data.getVar(var, d, 1) | ||
71 | if val: | ||
72 | fd.write("%s\t: %s\n" % (out_vartranslate[var], val)) | ||
73 | |||
74 | fd.write("AutoReqProv: no\n") | ||
75 | |||
76 | def fix_dep_versions(varname): | ||
77 | depends = bb.utils.explode_dep_versions(bb.data.getVar(varname, d, True) or "") | ||
78 | newdeps = [] | ||
79 | for dep in depends: | ||
80 | ver = depends[dep] | ||
81 | if dep and ver: | ||
82 | if '-' in ver: | ||
83 | subd = read_subpkgdata_dict(dep, d) | ||
84 | pv = subd['PV'] | ||
85 | reppv = pv.replace('-', '+') | ||
86 | ver = ver.replace(pv, reppv) | ||
87 | newdeps.append("%s (%s)" % (dep, ver)) | ||
88 | elif dep: | ||
89 | newdeps.append(dep) | ||
90 | bb.data.setVar(varname, " ".join(newdeps), d) | ||
91 | |||
92 | fix_dep_versions('RDEPENDS') | ||
93 | |||
94 | # Recommends is not supported by rpm at this time | ||
95 | # fix_dep_versions('RRECOMMENDS') | ||
96 | |||
97 | bb.build.exec_func("mapping_rename_hook", d) | ||
98 | |||
99 | def write_dep_field(varname, outstring): | ||
100 | depends = bb.utils.explode_dep_versions(bb.data.getVar(varname, d, True) or "") | ||
101 | for dep in depends: | ||
102 | ver = depends[dep] | ||
103 | if dep and ver: | ||
104 | fd.write("%s: %s %s\n" % (outstring, dep, ver)) | ||
105 | elif dep: | ||
106 | fd.write("%s: %s\n" % (outstring, dep)) | ||
107 | |||
108 | write_dep_field('RDEPENDS', 'Requires') | ||
109 | # write_dep_field('RRECOMMENDS', 'Recommends') | ||
110 | |||
111 | fd.write("Summary\t: .\n") | ||
112 | |||
113 | for var in out_vartranslate.keys(): | ||
114 | if out_vartranslate[var][0] != "%": | ||
115 | continue | ||
116 | val = bb.data.getVar(var, d) | ||
117 | if val: | ||
118 | fd.write(out_vartranslate[var] + "\n") | ||
119 | fd.write(val + "\n\n") | ||
120 | |||
121 | fd.write("%files\n") | ||
122 | for file in files: | ||
123 | if file[0] != '/': | ||
124 | fd.write('/') | ||
125 | fd.write("%s\n" % file) | ||
126 | |||
127 | fd.close() | ||
128 | |||
129 | # call out rpm -bb on the .spec, thereby creating an rpm | ||
130 | 7 | ||
131 | bb.note(bb.data.expand("${RPMBUILD} -bb ${OUTSPECFILE}", d)) | 8 | PKGWRITEDIRRPM = "${WORKDIR}/deploy-rpms" |
132 | 9 | ||
133 | bb.data.setVar('BUILDSPEC', "${RPMBUILD} -bb ${OUTSPECFILE}\n", d) | 10 | python package_rpm_fn () { |
134 | bb.data.setVarFlag('BUILDSPEC', 'func', '1', d) | 11 | bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d) |
135 | bb.build.exec_func('BUILDSPEC', d) | ||
136 | |||
137 | # move the rpm into the pkgoutdir | ||
138 | rpm = bb.data.expand('${RPMBUILDPATH}/RPMS/${TARGET_ARCH}/${PKG}-${RPMPV}-${PR}.${TARGET_ARCH}.rpm', d) | ||
139 | outrpm = bb.data.expand('${PKGWRITEDIRRPM}/${PACKAGE_ARCH}/${PKG}-${RPMPV}-${PR}.${TARGET_ARCH}.rpm', d) | ||
140 | bb.movefile(rpm, outrpm) | ||
141 | } | 12 | } |
142 | 13 | ||
143 | rpm_prep() { | 14 | python package_rpm_install () { |
144 | if [ ! -e ${WORKDIR}/rpmrc ]; then | 15 | bb.fatal("package_rpm_install not implemented!") |
145 | mkdir -p ${RPMBUILDPATH}/{SPECS,RPMS,SRPMS,SOURCES,BUILD} | ||
146 | fi | ||
147 | } | 16 | } |
148 | 17 | ||
149 | python do_package_rpm () { | 18 | python write_specfile () { |
150 | workdir = bb.data.getVar('WORKDIR', d, 1) | 19 | # We need to change '-' in a version field to '+' |
151 | if not workdir: | 20 | # This needs to be done BEFORE the mapping_rename_hook |
152 | bb.error("WORKDIR not defined, unable to package") | 21 | def translate_vers(varname, d): |
22 | depends = bb.data.getVar(varname, d, True) | ||
23 | if depends: | ||
24 | depends_dict = bb.utils.explode_dep_versions(depends) | ||
25 | newdeps_dict = {} | ||
26 | for dep in depends_dict: | ||
27 | ver = depends_dict[dep] | ||
28 | if dep and ver: | ||
29 | if '-' in ver: | ||
30 | subd = read_subpkgdata_dict(dep, d) | ||
31 | pv = subd['PV'] | ||
32 | reppv = pv.replace('-', '+') | ||
33 | ver = ver.replace(pv, reppv) | ||
34 | newdeps_dict[dep] = ver | ||
35 | depends = bb.utils.join_deps(newdeps_dict) | ||
36 | bb.data.setVar(varname, depends.strip(), d) | ||
37 | |||
38 | # We need to change the style the dependency from BB to RPM | ||
39 | # This needs to happen AFTER the mapping_rename_hook | ||
40 | def translate_deps(varname, d): | ||
41 | depends = bb.data.getVar('RPM' + varname, d, True) or bb.data.getVar(varname, d, True) or "" | ||
42 | depends = depends.replace('(', '') | ||
43 | depends = depends.replace(')', '') | ||
44 | bb.data.setVar('RPM' + varname, depends, d) | ||
45 | |||
46 | def walk_files(walkpath, target, conffiles): | ||
47 | import os | ||
48 | for rootpath, dirs, files in os.walk(walkpath): | ||
49 | path = rootpath.replace(walkpath, "") | ||
50 | #for dir in dirs: | ||
51 | # target.append("%dir " + path + "/" + dir) | ||
52 | for file in files: | ||
53 | if conffiles.count(path + "/" + file): | ||
54 | target.append("%config " + path + "/" + file) | ||
55 | else: | ||
56 | target.append(path + "/" + file) | ||
57 | |||
58 | packages = bb.data.getVar('PACKAGES', d, True) | ||
59 | if not packages or packages == '': | ||
60 | bb.debug(1, "No packages; nothing to do") | ||
153 | return | 61 | return |
154 | 62 | ||
155 | outdir = bb.data.getVar('PKGWRITEDIRRPM', d, 1) | 63 | pkgdest = bb.data.getVar('PKGDEST', d, True) |
156 | if not outdir: | 64 | if not pkgdest: |
157 | bb.error("PKGWRITEDIRRPM not defined, unable to package") | 65 | bb.fatal("No PKGDEST") |
158 | return | 66 | return |
159 | bb.mkdirhier(outdir) | ||
160 | 67 | ||
161 | packages = bb.data.getVar('PACKAGES', d, 1) | 68 | outspecfile = bb.data.getVar('OUTSPECFILE', d, True) |
162 | if not packages: | 69 | if not outspecfile: |
163 | bb.debug(1, "PACKAGES not defined, nothing to package") | 70 | bb.fatal("No OUTSPECFILE") |
164 | return | 71 | return |
165 | 72 | ||
166 | if packages == []: | 73 | # Construct the SPEC file... |
167 | bb.debug(1, "No packages; nothing to do") | 74 | srcname = bb.data.getVar('PN', d, True) |
168 | return | 75 | srcsummary = (bb.data.getVar('SUMMARY', d, True) or ".") |
169 | 76 | srcversion = bb.data.getVar('PV', d, True).replace('-', '+') | |
170 | # If "rpm" comes into overrides the presence of this function causes problems. | 77 | srcrelease = bb.data.getVar('PR', d, True) |
171 | # Since we don't need it, remove it for now - hacky. | 78 | srcepoch = (bb.data.getVar('PE', d, True) or "") |
172 | bb.data.delVar("do_package_write_rpm", d) | 79 | srclicense = bb.data.getVar('LICENSE', d, True) |
80 | srcsection = bb.data.getVar('SECTION', d, True) | ||
81 | srcmaintainer = bb.data.getVar('MAINTAINER', d, True) | ||
82 | srchomepage = bb.data.getVar('HOMEPAGE', d, True) | ||
83 | srcdescription = bb.data.getVar('DESCRIPTION', d, True) | ||
84 | |||
85 | translate_deps('DEPENDS', d) | ||
86 | srcdepends = bb.data.getVar('RPMDEPENDS', d, True) | ||
87 | srcrdepends = [] | ||
88 | srcrrecommends = [] | ||
89 | srcrsuggests = [] | ||
90 | srcrprovides = [] | ||
91 | srcrreplaces = [] | ||
92 | srcrconflicts = [] | ||
93 | srcrobsoletes = [] | ||
94 | |||
95 | srcpreinst = [] | ||
96 | srcpostinst = [] | ||
97 | srcprerm = [] | ||
98 | srcpostrm = [] | ||
99 | |||
100 | spec_preamble_top = [] | ||
101 | spec_preamble_bottom = [] | ||
102 | |||
103 | spec_scriptlets_top = [] | ||
104 | spec_scriptlets_bottom = [] | ||
105 | |||
106 | spec_files_top = [] | ||
107 | spec_files_bottom = [] | ||
173 | 108 | ||
174 | for pkg in packages.split(): | 109 | for pkg in packages.split(): |
175 | localdata = bb.data.createCopy(d) | 110 | localdata = bb.data.createCopy(d) |
176 | pkgdest = bb.data.getVar('PKGDEST', d, 1) | 111 | |
177 | root = "%s/%s" % (pkgdest, pkg) | 112 | root = "%s/%s" % (pkgdest, pkg) |
178 | 113 | ||
179 | lf = bb.utils.lockfile(root + ".lock") | 114 | lf = bb.utils.lockfile(root + ".lock") |
@@ -188,16 +123,289 @@ python do_package_rpm () { | |||
188 | bb.data.setVar('OVERRIDES', pkg, localdata) | 123 | bb.data.setVar('OVERRIDES', pkg, localdata) |
189 | 124 | ||
190 | bb.data.update_data(localdata) | 125 | bb.data.update_data(localdata) |
191 | basedir = os.path.join(os.path.dirname(root)) | 126 | |
192 | pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, 1)) | 127 | conffiles = (bb.data.getVar('CONFFILES', localdata, True) or "").split() |
193 | bb.mkdirhier(pkgoutdir) | 128 | |
194 | bb.data.setVar('OUTSPECFILE', os.path.join(workdir, "%s.spec" % pkg), localdata) | 129 | splitname = pkgname |
195 | # Save the value of RPMBUILD expanded into the new dictonary so any | 130 | |
196 | # changes in the compoents that make up workdir don't break packaging | 131 | splitsummary = (bb.data.getVar('SUMMARY', d, True) or ".") |
197 | bb.data.setVar('RPMBUILD', bb.data.getVar("RPMBUILD", d, True), localdata) | 132 | splitversion = (bb.data.getVar('PV', localdata, True) or "").replace('-', '+') |
198 | bb.data.setVar('RPMBUILDPATH', bb.data.getVar("RPMBUILDPATH", d, True), localdata) | 133 | splitrelease = (bb.data.getVar('PR', localdata, True) or "") |
199 | bb.build.exec_func('write_specfile', localdata) | 134 | splitepoch = (bb.data.getVar('PE', localdata, True) or "") |
135 | splitlicense = (bb.data.getVar('LICENSE', localdata, True) or "") | ||
136 | splitsection = (bb.data.getVar('SECTION', localdata, True) or "") | ||
137 | splitdescription = (bb.data.getVar('DESCRIPTION', localdata, True) or "") | ||
138 | |||
139 | translate_vers('RDEPENDS', localdata) | ||
140 | translate_vers('RRECOMMENDS', localdata) | ||
141 | translate_vers('RSUGGESTS', localdata) | ||
142 | translate_vers('RPROVIDES', localdata) | ||
143 | translate_vers('RREPLACES', localdata) | ||
144 | translate_vers('RCONFLICTS', localdata) | ||
145 | |||
146 | # Map the dependencies into their final form | ||
147 | bb.build.exec_func("mapping_rename_hook", localdata) | ||
148 | |||
149 | translate_deps('RDEPENDS', localdata) | ||
150 | translate_deps('RRECOMMENDS', localdata) | ||
151 | translate_deps('RSUGGESTS', localdata) | ||
152 | translate_deps('RPROVIDES', localdata) | ||
153 | translate_deps('RREPLACES', localdata) | ||
154 | translate_deps('RCONFLICTS', localdata) | ||
155 | |||
156 | splitrdepends = bb.data.getVar('RPMRDEPENDS', localdata, True) | ||
157 | splitrrecommends = bb.data.getVar('RPMRRECOMMENDS', localdata, True) | ||
158 | splitrsuggests = bb.data.getVar('RPMRSUGGESTS', localdata, True) | ||
159 | splitrprovides = bb.data.getVar('RPMRPROVIDES', localdata, True) | ||
160 | splitrreplaces = bb.data.getVar('RPMRREPLACES', localdata, True) | ||
161 | splitrconflicts = bb.data.getVar('RPMRCONFLICTS', localdata, True) | ||
162 | splitrobsoletes = [] | ||
163 | |||
164 | # Gather special src/first package data | ||
165 | if srcname == splitname: | ||
166 | srcrdepends = splitrdepends | ||
167 | srcrrecommends = splitrrecommends | ||
168 | srcrsuggests = splitrsuggests | ||
169 | srcrprovides = splitrprovides | ||
170 | srcrreplaces = splitrreplaces | ||
171 | srcrconflicts = splitrconflicts | ||
172 | |||
173 | srcpreinst = bb.data.getVar('pkg_preinst', localdata, True) | ||
174 | srcpostinst = bb.data.getVar('pkg_postinst', localdata, True) | ||
175 | srcprerm = bb.data.getVar('pkg_prerm', localdata, True) | ||
176 | srcpostrm = bb.data.getVar('pkg_postrm', localdata, True) | ||
177 | |||
178 | file_list = [] | ||
179 | walk_files(root, file_list, conffiles) | ||
180 | if not file_list and bb.data.getVar('ALLOW_EMPTY', localdata) != "1": | ||
181 | bb.note("Not creating empty RPM package for %s" % splitname) | ||
182 | else: | ||
183 | bb.note("Creating RPM package for %s" % splitname) | ||
184 | spec_files_top.append('%files') | ||
185 | if file_list: | ||
186 | spec_files_top.extend(file_list) | ||
187 | spec_files_top.append('') | ||
188 | |||
189 | bb.utils.unlockfile(lf) | ||
190 | continue | ||
191 | |||
192 | # Process subpackage data | ||
193 | spec_preamble_bottom.append('%%package -n %s' % splitname) | ||
194 | spec_preamble_bottom.append('Summary: %s' % splitsummary) | ||
195 | if srcversion != splitversion: | ||
196 | spec_preamble_bottom.append('Version: %s' % splitversion) | ||
197 | if srcrelease != splitrelease: | ||
198 | spec_preamble_bottom.append('Release: %s' % splitrelease) | ||
199 | if srcepoch != splitepoch: | ||
200 | spec_preamble_bottom.append('Epoch: %s' % splitepoch) | ||
201 | if srclicense != splitlicense: | ||
202 | spec_preamble_bottom.append('License: %s' % splitlicense) | ||
203 | spec_preamble_bottom.append('Group: %s' % splitsection) | ||
204 | |||
205 | # Replaces == Obsoletes && Provides | ||
206 | if splitrreplaces and splitrreplaces.strip() != "": | ||
207 | for dep in splitrreplaces.split(','): | ||
208 | if splitrprovides: | ||
209 | splitrprovides = splitrprovides + ", " + dep | ||
210 | else: | ||
211 | splitrprovides = dep | ||
212 | if splitrobsoletes: | ||
213 | splitrobsoletes = splitrobsoletes + ", " + dep | ||
214 | else: | ||
215 | splitrobsoletes = dep | ||
216 | |||
217 | if splitrdepends and splitrdepends.strip() != "": | ||
218 | spec_preamble_bottom.append('Requires: %s' % splitrdepends) | ||
219 | #if splitrrecommends and splitrrecommends.strip() != "": | ||
220 | # spec_preamble_bottom.append('#Recommends: %s' % splitrrecommends) | ||
221 | #if splitrsuggests and splitrsuggests.strip() != "": | ||
222 | # spec_preamble_bottom.append('#Suggests: %s' % splitrsuggests) | ||
223 | if splitrprovides and splitrprovides.strip() != "": | ||
224 | spec_preamble_bottom.append('Provides: %s' % splitrprovides) | ||
225 | if splitrobsoletes and splitrobsoletes.strip() != "": | ||
226 | spec_preamble_bottom.append('Obsoletes: %s' % splitrobsoletes) | ||
227 | if splitrconflicts and splitrconflicts.strip() != "": | ||
228 | for dep in splitrconflicts.split(','): | ||
229 | # A conflict can NOT be in the provide or an internal conflict happens! | ||
230 | if dep not in splitrprovides: | ||
231 | spec_preamble_bottom.append('Conflicts: %s' % dep) | ||
232 | |||
233 | spec_preamble_bottom.append('') | ||
234 | |||
235 | spec_preamble_bottom.append('%%description -n %s' % splitname) | ||
236 | spec_preamble_bottom.append('%s' % splitdescription) | ||
237 | |||
238 | spec_preamble_bottom.append('') | ||
239 | |||
240 | # Now process scriptlets | ||
241 | for script in ["preinst", "postinst", "prerm", "postrm"]: | ||
242 | scriptvar = bb.data.getVar('pkg_%s' % script, localdata, True) | ||
243 | if not scriptvar: | ||
244 | continue | ||
245 | if script == 'preinst': | ||
246 | spec_scriptlets_bottom.append('%%pre -n %s' % splitname) | ||
247 | elif script == 'postinst': | ||
248 | spec_scriptlets_bottom.append('%%post -n %s' % splitname) | ||
249 | elif script == 'prerm': | ||
250 | spec_scriptlets_bottom.append('%%preun -n %s' % splitname) | ||
251 | elif script == 'postrm': | ||
252 | spec_scriptlets_bottom.append('%%postun -n %s' % splitname) | ||
253 | spec_scriptlets_bottom.append(scriptvar) | ||
254 | spec_scriptlets_bottom.append('') | ||
255 | |||
256 | # Now process files | ||
257 | file_list = [] | ||
258 | walk_files(root, file_list, conffiles) | ||
259 | if not file_list and bb.data.getVar('ALLOW_EMPTY', localdata) != "1": | ||
260 | bb.note("Not creating empty RPM package for %s" % splitname) | ||
261 | else: | ||
262 | bb.note("Creating RPM package for %s" % splitname) | ||
263 | spec_files_bottom.append('%%files -n %s' % splitname) | ||
264 | if file_list: | ||
265 | spec_files_bottom.extend(file_list) | ||
266 | spec_files_bottom.append('') | ||
267 | |||
268 | del localdata | ||
200 | bb.utils.unlockfile(lf) | 269 | bb.utils.unlockfile(lf) |
270 | |||
271 | spec_preamble_top.append('Summary: %s' % srcsummary) | ||
272 | spec_preamble_top.append('Name: %s' % srcname) | ||
273 | spec_preamble_top.append('Version: %s' % srcversion) | ||
274 | spec_preamble_top.append('Release: %s' % srcrelease) | ||
275 | if srcepoch and srcepoch.strip() != "": | ||
276 | spec_preamble_top.append('Epoch: %s' % srcepoch) | ||
277 | spec_preamble_top.append('License: %s' % srclicense) | ||
278 | spec_preamble_top.append('Group: %s' % srcsection) | ||
279 | spec_preamble_top.append('Packager: %s' % srcmaintainer) | ||
280 | spec_preamble_top.append('URL: %s' % srchomepage) | ||
281 | |||
282 | # Replaces == Obsoletes && Provides | ||
283 | if srcrreplaces and srcrreplaces.strip() != "": | ||
284 | for dep in srcrreplaces.split(','): | ||
285 | if srcrprovides: | ||
286 | srcrprovides = srcrprovides + ", " + dep | ||
287 | else: | ||
288 | srcrprovides = dep | ||
289 | if srcrobsoletes: | ||
290 | srcrobsoletes = srcrobsoletes + ", " + dep | ||
291 | else: | ||
292 | srcrobsoletes = dep | ||
293 | if srcdepends and srcdepends.strip() != "": | ||
294 | spec_preamble_top.append('BuildRequires: %s' % srcdepends) | ||
295 | if srcrdepends and srcrdepends.strip() != "": | ||
296 | spec_preamble_top.append('Requires: %s' % srcrdepends) | ||
297 | #if srcrrecommends and srcrrecommends.strip() != "": | ||
298 | # spec_preamble_top.append('#Recommends: %s' % srcrrecommends) | ||
299 | #if srcrsuggests and srcrsuggests.strip() != "": | ||
300 | # spec_preamble_top.append('#Suggests: %s' % srcrsuggests) | ||
301 | if srcrprovides and srcrprovides.strip() != "": | ||
302 | spec_preamble_top.append('Provides: %s' % srcrprovides) | ||
303 | if srcrobsoletes and srcrobsoletes.strip() != "": | ||
304 | spec_preamble_top.append('Obsoletes: %s' % srcrobsoletes) | ||
305 | if srcrconflicts and srcrconflicts.strip() != "": | ||
306 | for dep in srcrconflicts.split(','): | ||
307 | # A conflict can NOT be in the provide or an internal conflict happens! | ||
308 | if dep not in srcrprovides: | ||
309 | spec_preamble_bottom.append('Conflicts: %s' % dep) | ||
310 | |||
311 | spec_preamble_top.append('') | ||
312 | |||
313 | spec_preamble_top.append('%description') | ||
314 | spec_preamble_top.append('%s' % srcdescription) | ||
315 | |||
316 | spec_preamble_top.append('') | ||
317 | |||
318 | if srcpreinst: | ||
319 | spec_scriptlets_top.append('%pre') | ||
320 | spec_scriptlets_top.append(srcpreinst) | ||
321 | spec_scriptlets_top.append('') | ||
322 | if srcpostinst: | ||
323 | spec_scriptlets_top.append('%post') | ||
324 | spec_scriptlets_top.append(srcpostinst) | ||
325 | spec_scriptlets_top.append('') | ||
326 | if srcprerm: | ||
327 | spec_scriptlets_top.append('%preun') | ||
328 | spec_scriptlets_top.append(srcprerm) | ||
329 | spec_scriptlets_top.append('') | ||
330 | if srcpostrm: | ||
331 | spec_scriptlets_top.append('%postun') | ||
332 | spec_scriptlets_top.append(srcpostrm) | ||
333 | spec_scriptlets_top.append('') | ||
334 | |||
335 | # Write the SPEC file | ||
336 | try: | ||
337 | from __builtin__ import file | ||
338 | specfile = file(outspecfile, 'w') | ||
339 | except OSError: | ||
340 | raise bb.build.FuncFailed("unable to open spec file for writing.") | ||
341 | |||
342 | for line in spec_preamble_top: | ||
343 | specfile.write(line + "\n") | ||
344 | |||
345 | for line in spec_preamble_bottom: | ||
346 | specfile.write(line + "\n") | ||
347 | |||
348 | for line in spec_scriptlets_top: | ||
349 | specfile.write(line + "\n") | ||
350 | |||
351 | for line in spec_scriptlets_bottom: | ||
352 | specfile.write(line + "\n") | ||
353 | |||
354 | for line in spec_files_top: | ||
355 | specfile.write(line + "\n") | ||
356 | |||
357 | for line in spec_files_bottom: | ||
358 | specfile.write(line + "\n") | ||
359 | |||
360 | specfile.close() | ||
361 | } | ||
362 | |||
363 | python do_package_rpm () { | ||
364 | import os | ||
365 | |||
366 | workdir = bb.data.getVar('WORKDIR', d, True) | ||
367 | outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, True) | ||
368 | dvar = bb.data.getVar('D', d, True) | ||
369 | tmpdir = bb.data.getVar('TMPDIR', d, True) | ||
370 | pkgd = bb.data.getVar('PKGD', d, True) | ||
371 | pkgdest = bb.data.getVar('PKGDEST', d, True) | ||
372 | if not workdir or not outdir or not dvar or not tmpdir: | ||
373 | bb.error("Variables incorrectly set, unable to package") | ||
374 | return | ||
375 | |||
376 | if not os.path.exists(dvar): | ||
377 | bb.debug(1, "Nothing installed, nothing to do") | ||
378 | return | ||
379 | |||
380 | packages = bb.data.getVar('PACKAGES', d, True) | ||
381 | if not packages or packages == '': | ||
382 | bb.debug(1, "No packages; nothing to do") | ||
383 | return | ||
384 | |||
385 | # Construct the spec file... | ||
386 | srcname = bb.data.getVar('PN', d, True) | ||
387 | outspecfile = workdir + "/" + srcname + ".spec" | ||
388 | bb.data.setVar('OUTSPECFILE', outspecfile, d) | ||
389 | bb.build.exec_func('write_specfile', d) | ||
390 | |||
391 | # Setup the rpmbuild arguments... | ||
392 | rpmbuild = bb.data.getVar('RPMBUILD', d, True) | ||
393 | targetsys = bb.data.getVar('TARGET_SYS', d, True) | ||
394 | pkgwritedir = bb.data.expand('${PKGWRITEDIRRPM}/${PACKAGE_ARCH}', d) | ||
395 | pkgarch = bb.data.expand('${PACKAGE_ARCH}', d) | ||
396 | bb.mkdirhier(pkgwritedir) | ||
397 | os.chmod(pkgwritedir, 0755) | ||
398 | |||
399 | cmd = rpmbuild | ||
400 | cmd = cmd + " --nodeps --short-circuit --target " + pkgarch + " --buildroot " + pkgd | ||
401 | cmd = cmd + " --define '_topdir " + workdir + "' --define '_rpmdir " + pkgwritedir + "'" | ||
402 | cmd = cmd + " --define '_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm'" | ||
403 | cmd = cmd + " -bb " + outspecfile | ||
404 | |||
405 | # Build the spec file! | ||
406 | bb.data.setVar('BUILDSPEC', cmd + "\n", d) | ||
407 | bb.data.setVarFlag('BUILDSPEC', 'func', '1', d) | ||
408 | bb.build.exec_func('BUILDSPEC', d) | ||
201 | } | 409 | } |
202 | 410 | ||
203 | python () { | 411 | python () { |
@@ -206,7 +414,7 @@ python () { | |||
206 | deps.append('rpm-native:do_populate_sysroot') | 414 | deps.append('rpm-native:do_populate_sysroot') |
207 | deps.append('virtual/fakeroot-native:do_populate_sysroot') | 415 | deps.append('virtual/fakeroot-native:do_populate_sysroot') |
208 | bb.data.setVarFlag('do_package_write_rpm', 'depends', " ".join(deps), d) | 416 | bb.data.setVarFlag('do_package_write_rpm', 'depends', " ".join(deps), d) |
209 | bb.data.setVarFlag('do_package_write_ipk', 'fakeroot', "1", d) | 417 | bb.data.setVarFlag('do_package_write_rpm', 'fakeroot', 1, d) |
210 | } | 418 | } |
211 | 419 | ||
212 | SSTATETASKS += "do_package_write_rpm" | 420 | SSTATETASKS += "do_package_write_rpm" |
@@ -215,15 +423,15 @@ do_package_write_rpm[sstate-inputdirs] = "${PKGWRITEDIRRPM}" | |||
215 | do_package_write_rpm[sstate-outputdirs] = "${DEPLOY_DIR_RPM}" | 423 | do_package_write_rpm[sstate-outputdirs] = "${DEPLOY_DIR_RPM}" |
216 | 424 | ||
217 | python do_package_write_rpm_setscene () { | 425 | python do_package_write_rpm_setscene () { |
218 | sstate_setscene(d) | 426 | sstate_setscene(d) |
219 | } | 427 | } |
220 | #addtask do_package_write_rpm_setscene | 428 | #addtask do_package_write_rpm_setscene |
221 | 429 | ||
222 | python do_package_write_rpm () { | 430 | python do_package_write_rpm () { |
223 | bb.build.exec_func("read_subpackage_metadata", d) | 431 | bb.build.exec_func("read_subpackage_metadata", d) |
224 | bb.build.exec_func("rpm_prep", d) | ||
225 | bb.build.exec_func("do_package_rpm", d) | 432 | bb.build.exec_func("do_package_rpm", d) |
226 | } | 433 | } |
434 | |||
227 | do_package_write_rpm[dirs] = "${PKGWRITEDIRRPM}" | 435 | do_package_write_rpm[dirs] = "${PKGWRITEDIRRPM}" |
228 | addtask package_write_rpm before do_package_write after do_package | 436 | addtask package_write_rpm before do_package_write after do_package |
229 | 437 | ||