1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 RPM Building steps.
19 """
20
21 from buildbot.steps.shell import ShellCommand
22 from buildbot.process.buildstep import RemoteShellCommand
23
24
26 """
27 Build and RPM based on pased spec filename
28 """
29
30 name = "rpmbuilder"
31 haltOnFailure = 1
32 flunkOnFailure = 1
33 description = ["RPMBUILD"]
34 descriptionDone = ["RPMBUILD"]
35
36 - def __init__(self,
37 specfile=None,
38 topdir='`pwd`',
39 builddir='`pwd`',
40 rpmdir='`pwd`',
41 sourcedir='`pwd`',
42 specdir='`pwd`',
43 srcrpmdir='`pwd`',
44 dist='.el5',
45 autoRelease=False,
46 vcsRevision=False,
47 **kwargs):
48 """
49 Creates the RpmBuild object.
50
51 @type specfile: str
52 @param specfile: the name of the spec file for the rpmbuild
53 @type topdir: str
54 @param topdir: the top directory for rpm building.
55 @type builddir: str
56 @param builddir: the directory to use for building
57 @type rpmdir: str
58 @param rpmdir: the directory to dump the rpms into
59 @type sourcedir: str
60 @param sourcedir: the directory that houses source code
61 @type srcrpmdir: str
62 @param srcrpmdir: the directory to dump source rpms into
63 @type dist: str
64 @param dist: the distribution to build for
65 @type autoRelease: boolean
66 @param autoRelease: if the auto release mechanics should be used
67 @type vcsRevision: boolean
68 @param vcsRevision: if the vcs revision mechanics should be used
69 @type kwargs: dict
70 @param kwargs: All further keyword arguments.
71 """
72 ShellCommand.__init__(self, **kwargs)
73 self.addFactoryArguments(topdir=topdir,
74 builddir=builddir,
75 rpmdir=rpmdir,
76 sourcedir=sourcedir,
77 specdir=specdir,
78 srcrpmdir=srcrpmdir,
79 specfile=specfile,
80 dist=dist,
81 autoRelease=autoRelease,
82 vcsRevision=vcsRevision)
83 self.rpmbuild = (
84 'rpmbuild --define "_topdir %s" --define "_builddir %s"'
85 ' --define "_rpmdir %s" --define "_sourcedir %s"'
86 ' --define "_specdir %s" --define "_srcrpmdir %s"'
87 ' --define "dist %s"' % (topdir, builddir, rpmdir, sourcedir,
88 specdir, srcrpmdir, dist))
89 self.specfile = specfile
90 self.autoRelease = autoRelease
91 self.vcsRevision = vcsRevision
92
94 """
95 Buildbot Calls Me when it's time to start
96 """
97 if self.autoRelease:
98 relfile = '%s.release' % (
99 self.os.path.basename(self.specfile).split('.')[0])
100 try:
101 rfile = open(relfile, 'r')
102 rel = int(rfile.readline().strip())
103 rfile.close()
104 except:
105 rel = 0
106 self.rpmbuild = self.rpmbuild + ' --define "_release %s"' % rel
107 rfile = open(relfile, 'w')
108 rfile.write(str(rel+1))
109 rfile.close()
110
111 if self.vcsRevision:
112 self.rpmbuild = self.rpmbuild + ' --define "_revision %s"' % \
113 self.getProperty('got_revision')
114
115 self.rpmbuild = self.rpmbuild + ' -ba %s' % self.specfile
116
117 self.command = ['bash', '-c', self.rpmbuild]
118
119
120 kwargs = self.remote_kwargs
121 kwargs['command'] = self.command
122 cmd = RemoteShellCommand(**kwargs)
123 self.setupEnvironment(cmd)
124 self.checkForOldSlaveAndLogfiles()
125 self.startCommand(cmd)
126
128 """
129 Create nice summary logs.
130
131 @param log: The log to create summary off of.
132 """
133 rpm_prefixes = ['Provides:', 'Requires(rpmlib):', 'Requires:',
134 'Checking for unpackaged', 'Wrote:',
135 'Executing(%', '+ ']
136 rpm_err_pfx = [' ', 'RPM build errors:', 'error: ']
137
138 rpmcmdlog = []
139 rpmerrors = []
140
141 for line in log.readlines():
142 for pfx in rpm_prefixes:
143 if pfx in line:
144 rpmcmdlog.append(line)
145 for err in rpm_err_pfx:
146 if err in line:
147 rpmerrors.append(line)
148 self.addCompleteLog('RPM Command Log', "".join(rpmcmdlog))
149 self.addCompleteLog('RPM Errors', "".join(rpmerrors))
150