Package buildbot :: Package steps :: Package package :: Package rpm :: Module rpmbuild
[frames] | no frames]

Source Code for Module buildbot.steps.package.rpm.rpmbuild

  1  # This file is part of Buildbot.  Buildbot is free software: you can 
  2  # redistribute it and/or modify it under the terms of the GNU General Public 
  3  # License as published by the Free Software Foundation, version 2. 
  4  # 
  5  # This program is distributed in the hope that it will be useful, but WITHOUT 
  6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  8  # details. 
  9  # 
 10  # You should have received a copy of the GNU General Public License along with 
 11  # this program; if not, write to the Free Software Foundation, Inc., 51 
 12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 13  # 
 14  # Portions Copyright Buildbot Team Members 
 15  # Portions Copyright Dan Radez <dradez+buildbot@redhat.com> 
 16  # Portions Copyright Steve 'Ashcrow' Milner <smilner+buildbot@redhat.com> 
 17  """ 
 18  RPM Building steps. 
 19  """ 
 20   
 21  from buildbot.steps.shell import ShellCommand 
 22  from buildbot.process.buildstep import RemoteShellCommand 
 23   
 24   
25 -class RpmBuild(ShellCommand):
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
93 - def start(self):
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 # create the actual RemoteShellCommand instance now 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
127 - def createSummary(self, log):
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