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