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   
 16  from __future__ import with_statement 
 17  # Portions Copyright Dan Radez <dradez+buildbot@redhat.com> 
 18  # Portions Copyright Steve 'Ashcrow' Milner <smilner+buildbot@redhat.com> 
 19   
 20  import os 
 21  from buildbot.steps.shell import ShellCommand 
 22  from buildbot.process import buildstep 
 23  from buildbot import config 
 24   
25 -class RpmBuild(ShellCommand):
26 """ 27 RpmBuild build step. 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 Create the RpmBuild object. 50 51 @type specfile: str 52 @param specfile: location of the specfile to build 53 @type topdir: str 54 @param topdir: define the _topdir rpm parameter 55 @type builddir: str 56 @param builddir: define the _builddir rpm parameter 57 @type rpmdir: str 58 @param rpmdir: define the _rpmdir rpm parameter 59 @type sourcedir: str 60 @param sourcedir: define the _sourcedir rpm parameter 61 @type specdir: str 62 @param specdir: define the _specdir rpm parameter 63 @type srcrpmdir: str 64 @param srcrpmdir: define the _srcrpmdir rpm parameter 65 @type dist: str 66 @param dist: define the dist string. 67 @type autoRelease: boolean 68 @param autoRelease: Use auto incrementing release numbers. 69 @type vcsRevision: boolean 70 @param vcsRevision: Use vcs version number as revision number. 71 """ 72 ShellCommand.__init__(self, **kwargs) 73 self.rpmbuild = ( 74 'rpmbuild --define "_topdir %s" --define "_builddir %s"' 75 ' --define "_rpmdir %s" --define "_sourcedir %s"' 76 ' --define "_specdir %s" --define "_srcrpmdir %s"' 77 ' --define "dist %s"' % (topdir, builddir, rpmdir, sourcedir, 78 specdir, srcrpmdir, dist)) 79 self.specfile = specfile 80 self.autoRelease = autoRelease 81 self.vcsRevision = vcsRevision 82 83 if not self.specfile: 84 config.error("You must specify a specfile")
85
86 - def start(self):
87 if self.autoRelease: 88 relfile = '%s.release' % ( 89 os.path.basename(self.specfile).split('.')[0]) 90 try: 91 with open(relfile, 'r') as rfile: 92 rel = int(rfile.readline().strip()) 93 except: 94 rel = 0 95 self.rpmbuild = self.rpmbuild + ' --define "_release %s"' % rel 96 with open(relfile, 'w') as rfile: 97 rfile.write(str(rel+1)) 98 99 if self.vcsRevision: 100 revision = self.getProperty('got_revision') 101 # only do this in the case where there's a single codebase 102 if revision and not isinstance(revision, dict): 103 self.rpmbuild = (self.rpmbuild + ' --define "_revision %s"' % 104 revision) 105 106 self.rpmbuild = self.rpmbuild + ' -ba %s' % self.specfile 107 108 self.command = self.rpmbuild 109 110 # create the actual RemoteShellCommand instance now 111 kwargs = self.remote_kwargs 112 kwargs['command'] = self.command 113 cmd = buildstep.RemoteShellCommand(**kwargs) 114 self.setupEnvironment(cmd) 115 self.startCommand(cmd)
116
117 - def createSummary(self, log):
118 rpm_prefixes = ['Provides:', 'Requires(', 'Requires:', 119 'Checking for unpackaged', 'Wrote:', 120 'Executing(%', '+ ', 'Processing files:'] 121 rpm_err_pfx = [' ', 'RPM build errors:', 'error: '] 122 123 rpmcmdlog = [] 124 rpmerrors = [] 125 126 for line in log.getText().splitlines(True): 127 for pfx in rpm_prefixes: 128 if line.startswith(pfx): 129 rpmcmdlog.append(line) 130 break 131 for err in rpm_err_pfx: 132 if line.startswith(err): 133 rpmerrors.append(line) 134 break 135 self.addCompleteLog('RPM Command Log', "".join(rpmcmdlog)) 136 if rpmerrors: 137 self.addCompleteLog('RPM Errors', "".join(rpmerrors))
138