summaryrefslogtreecommitdiffstats
path: root/meta/classes/package_rpm.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/package_rpm.bbclass')
-rw-r--r--meta/classes/package_rpm.bbclass731
1 files changed, 731 insertions, 0 deletions
diff --git a/meta/classes/package_rpm.bbclass b/meta/classes/package_rpm.bbclass
new file mode 100644
index 0000000..1ff2b36
--- /dev/null
+++ b/meta/classes/package_rpm.bbclass
@@ -0,0 +1,731 @@
1inherit package
2
3IMAGE_PKGTYPE ?= "rpm"
4
5RPM="rpm"
6RPMBUILD="rpmbuild"
7
8PKGWRITEDIRRPM = "${WORKDIR}/deploy-rpms"
9
10# Maintaining the perfile dependencies has singificant overhead when writing the
11# packages. When set, this value merges them for efficiency.
12MERGEPERFILEDEPS = "1"
13
14# Construct per file dependencies file
15def write_rpm_perfiledata(srcname, d):
16 workdir = d.getVar('WORKDIR', True)
17 packages = d.getVar('PACKAGES', True)
18 pkgd = d.getVar('PKGD', True)
19
20 def dump_filerdeps(varname, outfile, d):
21 outfile.write("#!/usr/bin/env python\n\n")
22 outfile.write("# Dependency table\n")
23 outfile.write('deps = {\n')
24 for pkg in packages.split():
25 dependsflist_key = 'FILE' + varname + 'FLIST' + "_" + pkg
26 dependsflist = (d.getVar(dependsflist_key, True) or "")
27 for dfile in dependsflist.split():
28 key = "FILE" + varname + "_" + dfile + "_" + pkg
29 depends_dict = bb.utils.explode_dep_versions(d.getVar(key, True) or "")
30 file = dfile.replace("@underscore@", "_")
31 file = file.replace("@closebrace@", "]")
32 file = file.replace("@openbrace@", "[")
33 file = file.replace("@tab@", "\t")
34 file = file.replace("@space@", " ")
35 file = file.replace("@at@", "@")
36 outfile.write('"' + pkgd + file + '" : "')
37 for dep in depends_dict:
38 ver = depends_dict[dep]
39 if dep and ver:
40 ver = ver.replace("(","")
41 ver = ver.replace(")","")
42 outfile.write(dep + " " + ver + " ")
43 else:
44 outfile.write(dep + " ")
45 outfile.write('",\n')
46 outfile.write('}\n\n')
47 outfile.write("import sys\n")
48 outfile.write("while 1:\n")
49 outfile.write("\tline = sys.stdin.readline().strip()\n")
50 outfile.write("\tif not line:\n")
51 outfile.write("\t\tsys.exit(0)\n")
52 outfile.write("\tif line in deps:\n")
53 outfile.write("\t\tprint(deps[line] + '\\n')\n")
54
55 # OE-core dependencies a.k.a. RPM requires
56 outdepends = workdir + "/" + srcname + ".requires"
57
58 try:
59 dependsfile = open(outdepends, 'w')
60 except OSError:
61 raise bb.build.FuncFailed("unable to open spec file for writing.")
62
63 dump_filerdeps('RDEPENDS', dependsfile, d)
64
65 dependsfile.close()
66 os.chmod(outdepends, 0755)
67
68 # OE-core / RPM Provides
69 outprovides = workdir + "/" + srcname + ".provides"
70
71 try:
72 providesfile = open(outprovides, 'w')
73 except OSError:
74 raise bb.build.FuncFailed("unable to open spec file for writing.")
75
76 dump_filerdeps('RPROVIDES', providesfile, d)
77
78 providesfile.close()
79 os.chmod(outprovides, 0755)
80
81 return (outdepends, outprovides)
82
83
84python write_specfile () {
85 import oe.packagedata
86
87 # append information for logs and patches to %prep
88 def add_prep(d,spec_files_bottom):
89 if d.getVarFlag('ARCHIVER_MODE', 'srpm', True) == '1' and bb.data.inherits_class('archiver', d):
90 spec_files_bottom.append('%%prep -n %s' % d.getVar('PN', True) )
91 spec_files_bottom.append('%s' % "echo \"include logs and patches, Please check them in SOURCES\"")
92 spec_files_bottom.append('')
93
94 # append the name of tarball to key word 'SOURCE' in xxx.spec.
95 def tail_source(d):
96 if d.getVarFlag('ARCHIVER_MODE', 'srpm', True) == '1' and bb.data.inherits_class('archiver', d):
97 ar_outdir = d.getVar('ARCHIVER_OUTDIR', True)
98 if not os.path.exists(ar_outdir):
99 return
100 source_list = os.listdir(ar_outdir)
101 source_number = 0
102 for source in source_list:
103 # The rpmbuild doesn't need the root permission, but it needs
104 # to know the file's user and group name, the only user and
105 # group in fakeroot is "root" when working in fakeroot.
106 f = os.path.join(ar_outdir, source)
107 os.chown(f, 0, 0)
108 spec_preamble_top.append('Source%s: %s' % (source_number, source))
109 source_number += 1
110 # We need a simple way to remove the MLPREFIX from the package name,
111 # and dependency information...
112 def strip_multilib(name, d):
113 multilibs = d.getVar('MULTILIBS', True) or ""
114 for ext in multilibs.split():
115 eext = ext.split(':')
116 if len(eext) > 1 and eext[0] == 'multilib' and name and name.find(eext[1] + '-') >= 0:
117 name = "".join(name.split(eext[1] + '-'))
118 return name
119
120 def strip_multilib_deps(deps, d):
121 depends = bb.utils.explode_dep_versions2(deps or "")
122 newdeps = {}
123 for dep in depends:
124 newdeps[strip_multilib(dep, d)] = depends[dep]
125 return bb.utils.join_deps(newdeps)
126
127# ml = d.getVar("MLPREFIX", True)
128# if ml and name and len(ml) != 0 and name.find(ml) == 0:
129# return ml.join(name.split(ml, 1)[1:])
130# return name
131
132 # In RPM, dependencies are of the format: pkg <>= Epoch:Version-Release
133 # This format is similar to OE, however there are restrictions on the
134 # characters that can be in a field. In the Version field, "-"
135 # characters are not allowed. "-" is allowed in the Release field.
136 #
137 # We translate the "-" in the version to a "+", by loading the PKGV
138 # from the dependent recipe, replacing the - with a +, and then using
139 # that value to do a replace inside of this recipe's dependencies.
140 # This preserves the "-" separator between the version and release, as
141 # well as any "-" characters inside of the release field.
142 #
143 # All of this has to happen BEFORE the mapping_rename_hook as
144 # after renaming we cannot look up the dependencies in the packagedata
145 # store.
146 def translate_vers(varname, d):
147 depends = d.getVar(varname, True)
148 if depends:
149 depends_dict = bb.utils.explode_dep_versions2(depends)
150 newdeps_dict = {}
151 for dep in depends_dict:
152 verlist = []
153 for ver in depends_dict[dep]:
154 if '-' in ver:
155 subd = oe.packagedata.read_subpkgdata_dict(dep, d)
156 if 'PKGV' in subd:
157 pv = subd['PV']
158 pkgv = subd['PKGV']
159 reppv = pkgv.replace('-', '+')
160 ver = ver.replace(pv, reppv).replace(pkgv, reppv)
161 if 'PKGR' in subd:
162 # Make sure PKGR rather than PR in ver
163 pr = '-' + subd['PR']
164 pkgr = '-' + subd['PKGR']
165 if pkgr not in ver:
166 ver = ver.replace(pr, pkgr)
167 verlist.append(ver)
168 else:
169 verlist.append(ver)
170 newdeps_dict[dep] = verlist
171 depends = bb.utils.join_deps(newdeps_dict)
172 d.setVar(varname, depends.strip())
173
174 # We need to change the style the dependency from BB to RPM
175 # This needs to happen AFTER the mapping_rename_hook
176 def print_deps(variable, tag, array, d):
177 depends = variable
178 if depends:
179 depends_dict = bb.utils.explode_dep_versions2(depends)
180 for dep in depends_dict:
181 for ver in depends_dict[dep]:
182 ver = ver.replace('(', '')
183 ver = ver.replace(')', '')
184 array.append("%s: %s %s" % (tag, dep, ver))
185 if not len(depends_dict[dep]):
186 array.append("%s: %s" % (tag, dep))
187
188 def walk_files(walkpath, target, conffiles):
189 # We can race against the ipk/deb backends which create CONTROL or DEBIAN directories
190 # when packaging. We just ignore these files which are created in
191 # packages-split/ and not package/
192 # We have the odd situation where the CONTROL/DEBIAN directory can be removed in the middle of
193 # of the walk, the isdir() test would then fail and the walk code would assume its a file
194 # hence we check for the names in files too.
195 for rootpath, dirs, files in os.walk(walkpath):
196 path = rootpath.replace(walkpath, "")
197 if path.endswith("DEBIAN") or path.endswith("CONTROL"):
198 continue
199 for dir in dirs:
200 if dir == "CONTROL" or dir == "DEBIAN":
201 continue
202 # All packages own the directories their files are in...
203 target.append('%dir "' + path + '/' + dir + '"')
204 for file in files:
205 if file == "CONTROL" or file == "DEBIAN":
206 continue
207 if conffiles.count(path + '/' + file):
208 target.append('%config "' + path + '/' + file + '"')
209 else:
210 target.append('"' + path + '/' + file + '"')
211
212 # Prevent the prerm/postrm scripts from being run during an upgrade
213 def wrap_uninstall(scriptvar):
214 scr = scriptvar.strip()
215 if scr.startswith("#!"):
216 pos = scr.find("\n") + 1
217 else:
218 pos = 0
219 scr = scr[:pos] + 'if [ "$1" = "0" ] ; then\n' + scr[pos:] + '\nfi'
220 return scr
221
222 def get_perfile(varname, pkg, d):
223 deps = []
224 dependsflist_key = 'FILE' + varname + 'FLIST' + "_" + pkg
225 dependsflist = (d.getVar(dependsflist_key, True) or "")
226 for dfile in dependsflist.split():
227 key = "FILE" + varname + "_" + dfile + "_" + pkg
228 depends = d.getVar(key, True)
229 if depends:
230 deps.append(depends)
231 return " ".join(deps)
232
233 def append_description(spec_preamble, text):
234 """
235 Add the description to the spec file.
236 """
237 import textwrap
238 dedent_text = textwrap.dedent(text).strip()
239 # Bitbake saves "\n" as "\\n"
240 if '\\n' in dedent_text:
241 for t in dedent_text.split('\\n'):
242 spec_preamble.append(t.strip())
243 else:
244 spec_preamble.append('%s' % textwrap.fill(dedent_text, width=75))
245
246 packages = d.getVar('PACKAGES', True)
247 if not packages or packages == '':
248 bb.debug(1, "No packages; nothing to do")
249 return
250
251 pkgdest = d.getVar('PKGDEST', True)
252 if not pkgdest:
253 bb.fatal("No PKGDEST")
254
255 outspecfile = d.getVar('OUTSPECFILE', True)
256 if not outspecfile:
257 bb.fatal("No OUTSPECFILE")
258
259 # Construct the SPEC file...
260 srcname = strip_multilib(d.getVar('PN', True), d)
261 srcsummary = (d.getVar('SUMMARY', True) or d.getVar('DESCRIPTION', True) or ".")
262 srcversion = d.getVar('PKGV', True).replace('-', '+')
263 srcrelease = d.getVar('PKGR', True)
264 srcepoch = (d.getVar('PKGE', True) or "")
265 srclicense = d.getVar('LICENSE', True)
266 srcsection = d.getVar('SECTION', True)
267 srcmaintainer = d.getVar('MAINTAINER', True)
268 srchomepage = d.getVar('HOMEPAGE', True)
269 srcdescription = d.getVar('DESCRIPTION', True) or "."
270 srccustomtagschunk = get_package_additional_metadata("rpm", d)
271
272 srcdepends = strip_multilib_deps(d.getVar('DEPENDS', True), d)
273 srcrdepends = []
274 srcrrecommends = []
275 srcrsuggests = []
276 srcrprovides = []
277 srcrreplaces = []
278 srcrconflicts = []
279 srcrobsoletes = []
280
281 srcrpreinst = []
282 srcrpostinst = []
283 srcrprerm = []
284 srcrpostrm = []
285
286 spec_preamble_top = []
287 spec_preamble_bottom = []
288
289 spec_scriptlets_top = []
290 spec_scriptlets_bottom = []
291
292 spec_files_top = []
293 spec_files_bottom = []
294
295 perfiledeps = (d.getVar("MERGEPERFILEDEPS", True) or "0") == "0"
296
297 for pkg in packages.split():
298 localdata = bb.data.createCopy(d)
299
300 root = "%s/%s" % (pkgdest, pkg)
301
302 localdata.setVar('ROOT', '')
303 localdata.setVar('ROOT_%s' % pkg, root)
304 pkgname = localdata.getVar('PKG_%s' % pkg, True)
305 if not pkgname:
306 pkgname = pkg
307 localdata.setVar('PKG', pkgname)
308
309 localdata.setVar('OVERRIDES', pkg)
310
311 bb.data.update_data(localdata)
312
313 conffiles = (localdata.getVar('CONFFILES', True) or "").split()
314
315 splitname = strip_multilib(pkgname, d)
316
317 splitsummary = (localdata.getVar('SUMMARY', True) or localdata.getVar('DESCRIPTION', True) or ".")
318 splitversion = (localdata.getVar('PKGV', True) or "").replace('-', '+')
319 splitrelease = (localdata.getVar('PKGR', True) or "")
320 splitepoch = (localdata.getVar('PKGE', True) or "")
321 splitlicense = (localdata.getVar('LICENSE', True) or "")
322 splitsection = (localdata.getVar('SECTION', True) or "")
323 splitdescription = (localdata.getVar('DESCRIPTION', True) or ".")
324 splitcustomtagschunk = get_package_additional_metadata("rpm", localdata)
325
326 translate_vers('RDEPENDS', localdata)
327 translate_vers('RRECOMMENDS', localdata)
328 translate_vers('RSUGGESTS', localdata)
329 translate_vers('RPROVIDES', localdata)
330 translate_vers('RREPLACES', localdata)
331 translate_vers('RCONFLICTS', localdata)
332
333 # Map the dependencies into their final form
334 mapping_rename_hook(localdata)
335
336 splitrdepends = strip_multilib_deps(localdata.getVar('RDEPENDS', True), d)
337 splitrrecommends = strip_multilib_deps(localdata.getVar('RRECOMMENDS', True), d)
338 splitrsuggests = strip_multilib_deps(localdata.getVar('RSUGGESTS', True), d)
339 splitrprovides = strip_multilib_deps(localdata.getVar('RPROVIDES', True), d)
340 splitrreplaces = strip_multilib_deps(localdata.getVar('RREPLACES', True), d)
341 splitrconflicts = strip_multilib_deps(localdata.getVar('RCONFLICTS', True), d)
342 splitrobsoletes = []
343
344 splitrpreinst = localdata.getVar('pkg_preinst', True)
345 splitrpostinst = localdata.getVar('pkg_postinst', True)
346 splitrprerm = localdata.getVar('pkg_prerm', True)
347 splitrpostrm = localdata.getVar('pkg_postrm', True)
348
349
350 if not perfiledeps:
351 # Add in summary of per file dependencies
352 splitrdepends = splitrdepends + " " + get_perfile('RDEPENDS', pkg, d)
353 splitrprovides = splitrprovides + " " + get_perfile('RPROVIDES', pkg, d)
354
355 # Gather special src/first package data
356 if srcname == splitname:
357 srcrdepends = splitrdepends
358 srcrrecommends = splitrrecommends
359 srcrsuggests = splitrsuggests
360 srcrprovides = splitrprovides
361 srcrreplaces = splitrreplaces
362 srcrconflicts = splitrconflicts
363
364 srcrpreinst = splitrpreinst
365 srcrpostinst = splitrpostinst
366 srcrprerm = splitrprerm
367 srcrpostrm = splitrpostrm
368
369 file_list = []
370 walk_files(root, file_list, conffiles)
371 if not file_list and localdata.getVar('ALLOW_EMPTY') != "1":
372 bb.note("Not creating empty RPM package for %s" % splitname)
373 else:
374 bb.note("Creating RPM package for %s" % splitname)
375 spec_files_top.append('%files')
376 spec_files_top.append('%defattr(-,-,-,-)')
377 if file_list:
378 bb.note("Creating RPM package for %s" % splitname)
379 spec_files_top.extend(file_list)
380 else:
381 bb.note("Creating EMPTY RPM Package for %s" % splitname)
382 spec_files_top.append('')
383 continue
384
385 # Process subpackage data
386 spec_preamble_bottom.append('%%package -n %s' % splitname)
387 spec_preamble_bottom.append('Summary: %s' % splitsummary)
388 if srcversion != splitversion:
389 spec_preamble_bottom.append('Version: %s' % splitversion)
390 if srcrelease != splitrelease:
391 spec_preamble_bottom.append('Release: %s' % splitrelease)
392 if srcepoch != splitepoch:
393 spec_preamble_bottom.append('Epoch: %s' % splitepoch)
394 if srclicense != splitlicense:
395 spec_preamble_bottom.append('License: %s' % splitlicense)
396 spec_preamble_bottom.append('Group: %s' % splitsection)
397
398 if srccustomtagschunk != splitcustomtagschunk:
399 spec_preamble_bottom.append(splitcustomtagschunk)
400
401 # Replaces == Obsoletes && Provides
402 robsoletes = bb.utils.explode_dep_versions2(splitrobsoletes or "")
403 rprovides = bb.utils.explode_dep_versions2(splitrprovides or "")
404 rreplaces = bb.utils.explode_dep_versions2(splitrreplaces or "")
405 for dep in rreplaces:
406 if not dep in robsoletes:
407 robsoletes[dep] = rreplaces[dep]
408 if not dep in rprovides:
409 rprovides[dep] = rreplaces[dep]
410 splitrobsoletes = bb.utils.join_deps(robsoletes, commasep=False)
411 splitrprovides = bb.utils.join_deps(rprovides, commasep=False)
412
413 print_deps(splitrdepends, "Requires", spec_preamble_bottom, d)
414 if splitrpreinst:
415 print_deps(splitrdepends, "Requires(pre)", spec_preamble_bottom, d)
416 if splitrpostinst:
417 print_deps(splitrdepends, "Requires(post)", spec_preamble_bottom, d)
418 if splitrprerm:
419 print_deps(splitrdepends, "Requires(preun)", spec_preamble_bottom, d)
420 if splitrpostrm:
421 print_deps(splitrdepends, "Requires(postun)", spec_preamble_bottom, d)
422
423 # Suggests in RPM are like recommends in OE-core!
424 print_deps(splitrrecommends, "Suggests", spec_preamble_bottom, d)
425 # While there is no analog for suggests... (So call them recommends for now)
426 print_deps(splitrsuggests, "Recommends", spec_preamble_bottom, d)
427 print_deps(splitrprovides, "Provides", spec_preamble_bottom, d)
428 print_deps(splitrobsoletes, "Obsoletes", spec_preamble_bottom, d)
429
430 # conflicts can not be in a provide! We will need to filter it.
431 if splitrconflicts:
432 depends_dict = bb.utils.explode_dep_versions2(splitrconflicts)
433 newdeps_dict = {}
434 for dep in depends_dict:
435 if dep not in splitrprovides:
436 newdeps_dict[dep] = depends_dict[dep]
437 if newdeps_dict:
438 splitrconflicts = bb.utils.join_deps(newdeps_dict)
439 else:
440 splitrconflicts = ""
441
442 print_deps(splitrconflicts, "Conflicts", spec_preamble_bottom, d)
443
444 spec_preamble_bottom.append('')
445
446 spec_preamble_bottom.append('%%description -n %s' % splitname)
447 append_description(spec_preamble_bottom, splitdescription)
448
449 spec_preamble_bottom.append('')
450
451 # Now process scriptlets
452 if splitrpreinst:
453 spec_scriptlets_bottom.append('%%pre -n %s' % splitname)
454 spec_scriptlets_bottom.append('# %s - preinst' % splitname)
455 spec_scriptlets_bottom.append(splitrpreinst)
456 spec_scriptlets_bottom.append('')
457 if splitrpostinst:
458 spec_scriptlets_bottom.append('%%post -n %s' % splitname)
459 spec_scriptlets_bottom.append('# %s - postinst' % splitname)
460 spec_scriptlets_bottom.append(splitrpostinst)
461 spec_scriptlets_bottom.append('')
462 if splitrprerm:
463 spec_scriptlets_bottom.append('%%preun -n %s' % splitname)
464 spec_scriptlets_bottom.append('# %s - prerm' % splitname)
465 scriptvar = wrap_uninstall(splitrprerm)
466 spec_scriptlets_bottom.append(scriptvar)
467 spec_scriptlets_bottom.append('')
468 if splitrpostrm:
469 spec_scriptlets_bottom.append('%%postun -n %s' % splitname)
470 spec_scriptlets_bottom.append('# %s - postrm' % splitname)
471 scriptvar = wrap_uninstall(splitrpostrm)
472 spec_scriptlets_bottom.append(scriptvar)
473 spec_scriptlets_bottom.append('')
474
475 # Now process files
476 file_list = []
477 walk_files(root, file_list, conffiles)
478 if not file_list and localdata.getVar('ALLOW_EMPTY') != "1":
479 bb.note("Not creating empty RPM package for %s" % splitname)
480 else:
481 spec_files_bottom.append('%%files -n %s' % splitname)
482 spec_files_bottom.append('%defattr(-,-,-,-)')
483 if file_list:
484 bb.note("Creating RPM package for %s" % splitname)
485 spec_files_bottom.extend(file_list)
486 else:
487 bb.note("Creating EMPTY RPM Package for %s" % splitname)
488 spec_files_bottom.append('')
489
490 del localdata
491
492 add_prep(d,spec_files_bottom)
493 spec_preamble_top.append('Summary: %s' % srcsummary)
494 spec_preamble_top.append('Name: %s' % srcname)
495 spec_preamble_top.append('Version: %s' % srcversion)
496 spec_preamble_top.append('Release: %s' % srcrelease)
497 if srcepoch and srcepoch.strip() != "":
498 spec_preamble_top.append('Epoch: %s' % srcepoch)
499 spec_preamble_top.append('License: %s' % srclicense)
500 spec_preamble_top.append('Group: %s' % srcsection)
501 spec_preamble_top.append('Packager: %s' % srcmaintainer)
502 if srchomepage:
503 spec_preamble_top.append('URL: %s' % srchomepage)
504 if srccustomtagschunk:
505 spec_preamble_top.append(srccustomtagschunk)
506 tail_source(d)
507
508 # Replaces == Obsoletes && Provides
509 robsoletes = bb.utils.explode_dep_versions2(srcrobsoletes or "")
510 rprovides = bb.utils.explode_dep_versions2(srcrprovides or "")
511 rreplaces = bb.utils.explode_dep_versions2(srcrreplaces or "")
512 for dep in rreplaces:
513 if not dep in robsoletes:
514 robsoletes[dep] = rreplaces[dep]
515 if not dep in rprovides:
516 rprovides[dep] = rreplaces[dep]
517 srcrobsoletes = bb.utils.join_deps(robsoletes, commasep=False)
518 srcrprovides = bb.utils.join_deps(rprovides, commasep=False)
519
520 print_deps(srcdepends, "BuildRequires", spec_preamble_top, d)
521 print_deps(srcrdepends, "Requires", spec_preamble_top, d)
522 if srcrpreinst:
523 print_deps(srcrdepends, "Requires(pre)", spec_preamble_top, d)
524 if srcrpostinst:
525 print_deps(srcrdepends, "Requires(post)", spec_preamble_top, d)
526 if srcrprerm:
527 print_deps(srcrdepends, "Requires(preun)", spec_preamble_top, d)
528 if srcrpostrm:
529 print_deps(srcrdepends, "Requires(postun)", spec_preamble_top, d)
530
531 # Suggests in RPM are like recommends in OE-core!
532 print_deps(srcrrecommends, "Suggests", spec_preamble_top, d)
533 # While there is no analog for suggests... (So call them recommends for now)
534 print_deps(srcrsuggests, "Recommends", spec_preamble_top, d)
535 print_deps(srcrprovides, "Provides", spec_preamble_top, d)
536 print_deps(srcrobsoletes, "Obsoletes", spec_preamble_top, d)
537
538 # conflicts can not be in a provide! We will need to filter it.
539 if srcrconflicts:
540 depends_dict = bb.utils.explode_dep_versions2(srcrconflicts)
541 newdeps_dict = {}
542 for dep in depends_dict:
543 if dep not in srcrprovides:
544 newdeps_dict[dep] = depends_dict[dep]
545 if newdeps_dict:
546 srcrconflicts = bb.utils.join_deps(newdeps_dict)
547 else:
548 srcrconflicts = ""
549
550 print_deps(srcrconflicts, "Conflicts", spec_preamble_top, d)
551
552 spec_preamble_top.append('')
553
554 spec_preamble_top.append('%description')
555 append_description(spec_preamble_top, srcdescription)
556
557 spec_preamble_top.append('')
558
559 if srcrpreinst:
560 spec_scriptlets_top.append('%pre')
561 spec_scriptlets_top.append('# %s - preinst' % srcname)
562 spec_scriptlets_top.append(srcrpreinst)
563 spec_scriptlets_top.append('')
564 if srcrpostinst:
565 spec_scriptlets_top.append('%post')
566 spec_scriptlets_top.append('# %s - postinst' % srcname)
567 spec_scriptlets_top.append(srcrpostinst)
568 spec_scriptlets_top.append('')
569 if srcrprerm:
570 spec_scriptlets_top.append('%preun')
571 spec_scriptlets_top.append('# %s - prerm' % srcname)
572 scriptvar = wrap_uninstall(srcrprerm)
573 spec_scriptlets_top.append(scriptvar)
574 spec_scriptlets_top.append('')
575 if srcrpostrm:
576 spec_scriptlets_top.append('%postun')
577 spec_scriptlets_top.append('# %s - postrm' % srcname)
578 scriptvar = wrap_uninstall(srcrpostrm)
579 spec_scriptlets_top.append(scriptvar)
580 spec_scriptlets_top.append('')
581
582 # Write the SPEC file
583 try:
584 specfile = open(outspecfile, 'w')
585 except OSError:
586 raise bb.build.FuncFailed("unable to open spec file for writing.")
587
588 # RPMSPEC_PREAMBLE is a way to add arbitrary text to the top
589 # of the generated spec file
590 external_preamble = d.getVar("RPMSPEC_PREAMBLE", True)
591 if external_preamble:
592 specfile.write(external_preamble + "\n")
593
594 for line in spec_preamble_top:
595 specfile.write(line + "\n")
596
597 for line in spec_preamble_bottom:
598 specfile.write(line + "\n")
599
600 for line in spec_scriptlets_top:
601 specfile.write(line + "\n")
602
603 for line in spec_scriptlets_bottom:
604 specfile.write(line + "\n")
605
606 for line in spec_files_top:
607 specfile.write(line + "\n")
608
609 for line in spec_files_bottom:
610 specfile.write(line + "\n")
611
612 specfile.close()
613}
614
615python do_package_rpm () {
616 # We need a simple way to remove the MLPREFIX from the package name,
617 # and dependency information...
618 def strip_multilib(name, d):
619 ml = d.getVar("MLPREFIX", True)
620 if ml and name and len(ml) != 0 and name.find(ml) >= 0:
621 return "".join(name.split(ml))
622 return name
623
624 workdir = d.getVar('WORKDIR', True)
625 tmpdir = d.getVar('TMPDIR', True)
626 pkgd = d.getVar('PKGD', True)
627 pkgdest = d.getVar('PKGDEST', True)
628 if not workdir or not pkgd or not tmpdir:
629 bb.error("Variables incorrectly set, unable to package")
630 return
631
632 packages = d.getVar('PACKAGES', True)
633 if not packages or packages == '':
634 bb.debug(1, "No packages; nothing to do")
635 return
636
637 # Construct the spec file...
638 # If the spec file already exist, and has not been stored into
639 # pseudo's files.db, it maybe cause rpmbuild src.rpm fail,
640 # so remove it before doing rpmbuild src.rpm.
641 srcname = strip_multilib(d.getVar('PN', True), d)
642 outspecfile = workdir + "/" + srcname + ".spec"
643 if os.path.isfile(outspecfile):
644 os.remove(outspecfile)
645 d.setVar('OUTSPECFILE', outspecfile)
646 bb.build.exec_func('write_specfile', d)
647
648 perfiledeps = (d.getVar("MERGEPERFILEDEPS", True) or "0") == "0"
649 if perfiledeps:
650 outdepends, outprovides = write_rpm_perfiledata(srcname, d)
651
652 # Setup the rpmbuild arguments...
653 rpmbuild = d.getVar('RPMBUILD', True)
654 targetsys = d.getVar('TARGET_SYS', True)
655 targetvendor = d.getVar('TARGET_VENDOR', True)
656 package_arch = (d.getVar('PACKAGE_ARCH', True) or "").replace("-", "_")
657 if package_arch not in "all any noarch".split() and not package_arch.endswith("_nativesdk"):
658 ml_prefix = (d.getVar('MLPREFIX', True) or "").replace("-", "_")
659 d.setVar('PACKAGE_ARCH_EXTEND', ml_prefix + package_arch)
660 else:
661 d.setVar('PACKAGE_ARCH_EXTEND', package_arch)
662 pkgwritedir = d.expand('${PKGWRITEDIRRPM}/${PACKAGE_ARCH_EXTEND}')
663 pkgarch = d.expand('${PACKAGE_ARCH_EXTEND}${TARGET_VENDOR}-${TARGET_OS}')
664 magicfile = d.expand('${STAGING_DIR_NATIVE}${datadir_native}/misc/magic.mgc')
665 bb.utils.mkdirhier(pkgwritedir)
666 os.chmod(pkgwritedir, 0755)
667
668 cmd = rpmbuild
669 cmd = cmd + " --nodeps --short-circuit --target " + pkgarch + " --buildroot " + pkgd
670 cmd = cmd + " --define '_topdir " + workdir + "' --define '_rpmdir " + pkgwritedir + "'"
671 cmd = cmd + " --define '_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm'"
672 cmd = cmd + " --define '_use_internal_dependency_generator 0'"
673 if perfiledeps:
674 cmd = cmd + " --define '__find_requires " + outdepends + "'"
675 cmd = cmd + " --define '__find_provides " + outprovides + "'"
676 else:
677 cmd = cmd + " --define '__find_requires %{nil}'"
678 cmd = cmd + " --define '__find_provides %{nil}'"
679 cmd = cmd + " --define '_unpackaged_files_terminate_build 0'"
680 cmd = cmd + " --define 'debug_package %{nil}'"
681 cmd = cmd + " --define '_rpmfc_magic_path " + magicfile + "'"
682 cmd = cmd + " --define '_tmppath " + workdir + "'"
683 if d.getVarFlag('ARCHIVER_MODE', 'srpm', True) == '1' and bb.data.inherits_class('archiver', d):
684 cmd = cmd + " --define '_sourcedir " + d.getVar('ARCHIVER_OUTDIR', True) + "'"
685 cmdsrpm = cmd + " --define '_srcrpmdir " + d.getVar('ARCHIVER_OUTDIR', True) + "'"
686 cmdsrpm = cmdsrpm + " -bs " + outspecfile
687 # Build the .src.rpm
688 d.setVar('SBUILDSPEC', cmdsrpm + "\n")
689 d.setVarFlag('SBUILDSPEC', 'func', '1')
690 bb.build.exec_func('SBUILDSPEC', d)
691 cmd = cmd + " -bb " + outspecfile
692
693 # Build the rpm package!
694 d.setVar('BUILDSPEC', cmd + "\n")
695 d.setVarFlag('BUILDSPEC', 'func', '1')
696 bb.build.exec_func('BUILDSPEC', d)
697}
698
699python () {
700 if d.getVar('PACKAGES', True) != '':
701 deps = ' rpm-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot'
702 d.appendVarFlag('do_package_write_rpm', 'depends', deps)
703 d.setVarFlag('do_package_write_rpm', 'fakeroot', 1)
704}
705
706SSTATETASKS += "do_package_write_rpm"
707do_package_write_rpm[sstate-inputdirs] = "${PKGWRITEDIRRPM}"
708do_package_write_rpm[sstate-outputdirs] = "${DEPLOY_DIR_RPM}"
709# Take a shared lock, we can write multiple packages at the same time...
710# but we need to stop the rootfs/solver from running while we do...
711do_package_write_rpm[sstate-lockfile-shared] += "${DEPLOY_DIR_RPM}/rpm.lock"
712
713python do_package_write_rpm_setscene () {
714 sstate_setscene(d)
715}
716addtask do_package_write_rpm_setscene
717
718python do_package_write_rpm () {
719 bb.build.exec_func("read_subpackage_metadata", d)
720 bb.build.exec_func("do_package_rpm", d)
721}
722
723do_package_write_rpm[dirs] = "${PKGWRITEDIRRPM}"
724do_package_write_rpm[cleandirs] = "${PKGWRITEDIRRPM}"
725do_package_write_rpm[umask] = "022"
726addtask package_write_rpm after do_packagedata do_package
727
728PACKAGEINDEXDEPS += "rpm-native:do_populate_sysroot"
729PACKAGEINDEXDEPS += "createrepo-native:do_populate_sysroot"
730
731do_build[recrdeptask] += "do_package_write_rpm"