Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/buildbot/buildbot/steps/package/rpm/rpmbuild.py
blob: 38bce85b8e3fe7efb50595efc00fdf3c1446a967 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Dan Radez <dradez+buildbot@redhat.com>
# Steve 'Ashcrow' Milner <smilner+buildbot@redhat.com>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
RPM Building steps.
"""

from buildbot.steps.shell import ShellCommand
from buildbot.process.buildstep import RemoteShellCommand


class RpmBuild(ShellCommand):
    """
    Build and RPM based on pased spec filename
    """

    import os.path

    name = "rpmbuilder"
    haltOnFailure = 1
    flunkOnFailure = 1
    description = ["RPMBUILD"]
    descriptionDone = ["RPMBUILD"]

    def __init__(self,
                 specfile=None,
                 topdir='`pwd`',
                 builddir='`pwd`',
                 rpmdir='`pwd`',
                 sourcedir='`pwd`',
                 specdir='`pwd`',
                 srcrpmdir='`pwd`',
                 dist='.el5',
                 autoRelease=False,
                 vcsRevision=False,
                 **kwargs):
        """
        Creates the RpmBuild object.

        @type specfile: str
        @param specfile: the name of the spec file for the rpmbuild
        @type topdir: str
        @param topdir: the top directory for rpm building.
        @type builddir: str
        @param builddir: the directory to use for building
        @type rpmdir: str
        @param rpmdir: the directory to dump the rpms into
        @type sourcedir: str
        @param sourcedir: the directory that houses source code
        @type srcrpmdir: str
        @param srcrpmdir: the directory to dump source rpms into
        @type dist: str
        @param dist: the distribution to build for
        @type autoRelease: boolean
        @param autoRelease: if the auto release mechanics should be used
        @type vcsRevision: boolean
        @param vcsRevision: if the vcs revision mechanics should be used
        @type kwargs: dict
        @param kwargs: All further keyword arguments.
        """
        ShellCommand.__init__(self, **kwargs)
        self.addFactoryArguments(topdir=topdir,
                                 builddir=builddir,
                                 rpmdir=rpmdir,
                                 sourcedir=sourcedir,
                                 specdir=specdir,
                                 srcrpmdir=srcrpmdir,
                                 specfile=specfile,
                                 dist=dist,
                                 autoRelease=autoRelease,
                                 vcsRevision=vcsRevision)
        self.rpmbuild = (
            'rpmbuild --define "_topdir %s" --define "_builddir %s"'
            ' --define "_rpmdir %s" --define "_sourcedir %s"'
            ' --define "_specdir %s" --define "_srcrpmdir %s"'
            ' --define "dist %s"' % (topdir, builddir, rpmdir, sourcedir,
            specdir, srcrpmdir, dist))
        self.specfile = specfile
        self.autoRelease = autoRelease
        self.vcsRevision = vcsRevision

    def start(self):
        """
        Buildbot Calls Me when it's time to start
        """
        if self.autoRelease:
            relfile = '%s.release' % (
                self.os.path.basename(self.specfile).split('.')[0])
            try:
                rfile = open(relfile, 'r')
                rel = int(rfile.readline().strip())
                rfile.close()
            except:
                rel = 0
            self.rpmbuild = self.rpmbuild + ' --define "_release %s"' % rel
            rfile = open(relfile, 'w')
            rfile.write(str(rel+1))
            rfile.close()

        if self.vcsRevision:
            self.rpmbuild = self.rpmbuild + ' --define "_revision %s"' % \
                self.getProperty('got_revision')

        self.rpmbuild = self.rpmbuild + ' -ba %s' % self.specfile

        self.command = ['bash', '-c', self.rpmbuild]

        # create the actual RemoteShellCommand instance now
        kwargs = self.remote_kwargs
        kwargs['command'] = self.command
        cmd = RemoteShellCommand(**kwargs)
        self.setupEnvironment(cmd)
        self.checkForOldSlaveAndLogfiles()
        self.startCommand(cmd)

    def createSummary(self, log):
        """
        Create nice summary logs.

        @param log: The log to create summary off of.
        """
        rpm_prefixes = ['Provides:', 'Requires(rpmlib):', 'Requires:',
                        'Checking for unpackaged', 'Wrote:',
                        'Executing(%', '+ ']
        rpm_err_pfx = ['   ', 'RPM build errors:', 'error: ']

        rpmcmdlog = []
        rpmerrors = []

        for line in log.readlines():
            for pfx in rpm_prefixes:
                if pfx in line:
                    rpmcmdlog.append(line)
            for err in rpm_err_pfx:
                if err in line:
                    rpmerrors.append(line)
        self.addCompleteLog('RPM Command Log', "".join(rpmcmdlog))
        self.addCompleteLog('RPM Errors', "".join(rpmerrors))