diff options
Diffstat (limited to 'meta/classes/package_rpm.bbclass')
-rw-r--r-- | meta/classes/package_rpm.bbclass | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/meta/classes/package_rpm.bbclass b/meta/classes/package_rpm.bbclass new file mode 100644 index 0000000000..c29ab5f423 --- /dev/null +++ b/meta/classes/package_rpm.bbclass | |||
@@ -0,0 +1,133 @@ | |||
1 | inherit package | ||
2 | inherit rpm_core | ||
3 | |||
4 | RPMBUILD="rpmbuild --short-circuit ${RPMOPTS}" | ||
5 | PACKAGEFUNCS += "do_package_rpm" | ||
6 | |||
7 | python write_specfile() { | ||
8 | from bb import data, build | ||
9 | import sys | ||
10 | out_vartranslate = { | ||
11 | "PKG": "Name", | ||
12 | "PV": "Version", | ||
13 | "PR": "Release", | ||
14 | "DESCRIPTION": "%description", | ||
15 | "ROOT": "BuildRoot", | ||
16 | "LICENSE": "License", | ||
17 | "SECTION": "Group", | ||
18 | } | ||
19 | |||
20 | root = bb.data.getVar('ROOT', d) | ||
21 | |||
22 | # get %files | ||
23 | filesvar = bb.data.expand(bb.data.getVar('FILES', d), d) or "" | ||
24 | from glob import glob | ||
25 | files = filesvar.split() | ||
26 | todelete = [] | ||
27 | for file in files: | ||
28 | if file[0] == '.': | ||
29 | newfile = file[1:] | ||
30 | files[files.index(file)] = newfile | ||
31 | file = newfile | ||
32 | else: | ||
33 | newfile = file | ||
34 | realfile = os.path.join(root, './'+file) | ||
35 | if not glob(realfile): | ||
36 | todelete.append(files[files.index(newfile)]) | ||
37 | for r in todelete: | ||
38 | try: | ||
39 | del files[files.index(r)] | ||
40 | except ValueError: | ||
41 | pass | ||
42 | if not files: | ||
43 | from bb import note | ||
44 | 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))) | ||
45 | return | ||
46 | |||
47 | # output .spec using this metadata store | ||
48 | try: | ||
49 | from __builtin__ import file | ||
50 | if not bb.data.getVar('OUTSPECFILE', d): | ||
51 | raise OSError('eek!') | ||
52 | specfile = file(bb.data.getVar('OUTSPECFILE', d), 'w') | ||
53 | except OSError: | ||
54 | raise bb.build.FuncFailed("unable to open spec file for writing.") | ||
55 | |||
56 | # fd = sys.__stdout__ | ||
57 | fd = specfile | ||
58 | for var in out_vartranslate.keys(): | ||
59 | if out_vartranslate[var][0] == "%": | ||
60 | continue | ||
61 | fd.write("%s\t: %s\n" % (out_vartranslate[var], bb.data.getVar(var, d))) | ||
62 | fd.write("Summary\t: .\n") | ||
63 | |||
64 | for var in out_vartranslate.keys(): | ||
65 | if out_vartranslate[var][0] != "%": | ||
66 | continue | ||
67 | fd.write(out_vartranslate[var] + "\n") | ||
68 | fd.write(bb.data.getVar(var, d) + "\n\n") | ||
69 | |||
70 | fd.write("%files\n") | ||
71 | for file in files: | ||
72 | fd.write("%s\n" % file) | ||
73 | |||
74 | fd.close() | ||
75 | |||
76 | # call out rpm -bb on the .spec, thereby creating an rpm | ||
77 | |||
78 | bb.data.setVar('BUILDSPEC', "${RPMBUILD} -bb ${OUTSPECFILE}\n", d) | ||
79 | bb.data.setVarFlag('BUILDSPEC', 'func', '1', d) | ||
80 | bb.build.exec_func('BUILDSPEC', d) | ||
81 | |||
82 | # move the rpm into the pkgoutdir | ||
83 | rpm = bb.data.expand('${RPMBUILDPATH}/RPMS/${TARGET_ARCH}/${PKG}-${PV}-${PR}.${TARGET_ARCH}.rpm', d) | ||
84 | outrpm = bb.data.expand('${DEPLOY_DIR_RPM}/${PKG}-${PV}-${PR}.${TARGET_ARCH}.rpm', d) | ||
85 | bb.movefile(rpm, outrpm) | ||
86 | } | ||
87 | |||
88 | python do_package_rpm () { | ||
89 | workdir = bb.data.getVar('WORKDIR', d) | ||
90 | if not workdir: | ||
91 | raise bb.build.FuncFailed("WORKDIR not defined") | ||
92 | workdir = bb.data.expand(workdir, d) | ||
93 | |||
94 | import os # path manipulations | ||
95 | outdir = bb.data.getVar('DEPLOY_DIR_RPM', d) | ||
96 | if not outdir: | ||
97 | raise bb.build.FuncFailed("DEPLOY_DIR_RPM not defined") | ||
98 | outdir = bb.data.expand(outdir, d) | ||
99 | bb.mkdirhier(outdir) | ||
100 | |||
101 | packages = bb.data.getVar('PACKAGES', d) | ||
102 | if not packages: | ||
103 | packages = "${PN}" | ||
104 | bb.data.setVar('FILES', '', d) | ||
105 | ddir = bb.data.expand(bb.data.getVar('D', d), d) | ||
106 | bb.mkdirhier(ddir) | ||
107 | bb.data.setVar(bb.data.expand('FILES_${PN}', d), ''.join([ "./%s" % x for x in os.listdir(ddir)]), d) | ||
108 | packages = bb.data.expand(packages, d) | ||
109 | |||
110 | for pkg in packages.split(): | ||
111 | localdata = bb.data.createCopy(d) | ||
112 | root = "%s/install/%s" % (workdir, pkg) | ||
113 | |||
114 | bb.data.setVar('ROOT', '', localdata) | ||
115 | bb.data.setVar('ROOT_%s' % pkg, root, localdata) | ||
116 | bb.data.setVar('PKG', pkg, localdata) | ||
117 | |||
118 | overrides = bb.data.getVar('OVERRIDES', localdata) | ||
119 | if not overrides: | ||
120 | raise bb.build.FuncFailed('OVERRIDES not defined') | ||
121 | overrides = bb.data.expand(overrides, localdata) | ||
122 | bb.data.setVar('OVERRIDES', '%s:%s' % (overrides, pkg), localdata) | ||
123 | |||
124 | bb.data.update_data(localdata) | ||
125 | # stuff | ||
126 | root = bb.data.getVar('ROOT', localdata) | ||
127 | basedir = os.path.dirname(root) | ||
128 | pkgoutdir = outdir | ||
129 | bb.mkdirhier(pkgoutdir) | ||
130 | bb.data.setVar('OUTSPECFILE', os.path.join(workdir, "%s.spec" % pkg), localdata) | ||
131 | bb.build.exec_func('write_specfile', localdata) | ||
132 | del localdata | ||
133 | } | ||