~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/buildd/binarypackage.py

  • Committer: mbp at canonical
  • Date: 2011-11-20 23:37:23 UTC
  • mto: This revision was merged to the branch mainline in revision 14344.
  • Revision ID: mbp@canonical.com-20111120233723-370p96db2crru5tm
Delete canonical.buildd again

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009, 2010 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
 
5
 
import re
6
 
 
7
 
from canonical.buildd.debian import DebianBuildManager, DebianBuildState
8
 
 
9
 
 
10
 
class SBuildExitCodes:
11
 
    """SBUILD process result codes."""
12
 
    OK = 0
13
 
    DEPFAIL = 1
14
 
    GIVENBACK = 2
15
 
    PACKAGEFAIL = 3
16
 
    BUILDERFAIL = 4
17
 
 
18
 
 
19
 
class BuildLogRegexes:
20
 
    """Build log regexes for performing actions based on regexes, and extracting dependencies for auto dep-waits"""
21
 
    GIVENBACK = [
22
 
        ("^E: There are problems and -y was used without --force-yes"),
23
 
        ]
24
 
    DEPFAIL = [
25
 
        ("(?P<pk>[\-+.\w]+)\(inst [^ ]+ ! >> wanted (?P<v>[\-.+\w:~]+)\)","\g<pk> (>> \g<v>)"),
26
 
        ("(?P<pk>[\-+.\w]+)\(inst [^ ]+ ! >?= wanted (?P<v>[\-.+\w:~]+)\)","\g<pk> (>= \g<v>)"),
27
 
        ("(?s)^E: Couldn't find package (?P<pk>[\-+.\w]+)(?!.*^E: Couldn't find package)","\g<pk>"),
28
 
        ("(?s)^E: Package '?(?P<pk>[\-+.\w]+)'? has no installation candidate(?!.*^E: Package)","\g<pk>"),
29
 
        ("(?s)^E: Unable to locate package (?P<pk>[\-+.\w]+)(?!.*^E: Unable to locate package)", "\g<pk>"),
30
 
        ]
31
 
 
32
 
 
33
 
class BinaryPackageBuildState(DebianBuildState):
34
 
    SBUILD = "SBUILD"
35
 
 
36
 
 
37
 
class BinaryPackageBuildManager(DebianBuildManager):
38
 
    """Handle buildd building for a debian style binary package build"""
39
 
 
40
 
    initial_build_state = BinaryPackageBuildState.SBUILD
41
 
 
42
 
    def __init__(self, slave, buildid):
43
 
        DebianBuildManager.__init__(self, slave, buildid)
44
 
        self._sbuildpath = slave._config.get("binarypackagemanager", "sbuildpath")
45
 
        self._sbuildargs = slave._config.get("binarypackagemanager",
46
 
                                             "sbuildargs").split(" ")
47
 
 
48
 
    def initiate(self, files, chroot, extra_args):
49
 
        """Initiate a build with a given set of files and chroot."""
50
 
 
51
 
        self._dscfile = None
52
 
        for f in files:
53
 
            if f.endswith(".dsc"):
54
 
                self._dscfile = f
55
 
        if self._dscfile is None:
56
 
            raise ValueError, files
57
 
 
58
 
        self.archive_purpose = extra_args.get('archive_purpose')
59
 
        self.suite = extra_args.get('suite')
60
 
        self.component = extra_args['ogrecomponent']
61
 
        self.arch_indep = extra_args.get('arch_indep', False)
62
 
        self.build_debug_symbols = extra_args.get('build_debug_symbols', False)
63
 
 
64
 
        super(BinaryPackageBuildManager, self).initiate(
65
 
            files, chroot, extra_args)
66
 
 
67
 
    def doRunBuild(self):
68
 
        """Run the sbuild process to build the package."""
69
 
        args = ["sbuild-package", self._buildid, self.arch_tag]
70
 
        if self.suite:
71
 
            args.extend([self.suite])
72
 
            args.extend(self._sbuildargs)
73
 
            args.extend(["--dist=" + self.suite])
74
 
        else:
75
 
            args.extend(['autobuild'])
76
 
            args.extend(self._sbuildargs)
77
 
            args.extend(["--dist=autobuild"])
78
 
        if self.arch_indep:
79
 
            args.extend(["-A"])
80
 
        if self.archive_purpose:
81
 
            args.extend(["--purpose=" + self.archive_purpose])
82
 
        if self.build_debug_symbols:
83
 
            args.extend(["--build-debug-symbols"])
84
 
        args.extend(["--architecture=" + self.arch_tag])
85
 
        args.extend(["--comp=" + self.component])
86
 
        args.extend([self._dscfile])
87
 
        self.runSubProcess( self._sbuildpath, args )
88
 
 
89
 
    def iterate_SBUILD(self, success):
90
 
        """Finished the sbuild run."""
91
 
        tmpLog = self.getTmpLogContents()
92
 
        if success != SBuildExitCodes.OK:
93
 
            if (success == SBuildExitCodes.DEPFAIL or
94
 
                success == SBuildExitCodes.PACKAGEFAIL):
95
 
                for rx in BuildLogRegexes.GIVENBACK:
96
 
                    mo = re.search(rx, tmpLog, re.M)
97
 
                    if mo:
98
 
                        success = SBuildExitCodes.GIVENBACK
99
 
 
100
 
            if success == SBuildExitCodes.DEPFAIL:
101
 
                for rx, dep in BuildLogRegexes.DEPFAIL:
102
 
                    mo = re.search(rx, tmpLog, re.M)
103
 
                    if mo:
104
 
                        if not self.alreadyfailed:
105
 
                            print("Returning build status: DEPFAIL")
106
 
                            print("Dependencies: " + mo.expand(dep))
107
 
                            self._slave.depFail(mo.expand(dep))
108
 
                            success = SBuildExitCodes.DEPFAIL
109
 
                            break
110
 
                    else:
111
 
                        success = SBuildExitCodes.PACKAGEFAIL
112
 
 
113
 
            if success == SBuildExitCodes.GIVENBACK:
114
 
                if not self.alreadyfailed:
115
 
                    print("Returning build status: GIVENBACK")
116
 
                    self._slave.giveBack()
117
 
            elif success == SBuildExitCodes.PACKAGEFAIL:
118
 
                if not self.alreadyfailed:
119
 
                    print("Returning build status: PACKAGEFAIL")
120
 
                    self._slave.buildFail()
121
 
            elif success >= SBuildExitCodes.BUILDERFAIL:
122
 
                # anything else is assumed to be a buildd failure
123
 
                if not self.alreadyfailed:
124
 
                    print("Returning build status: BUILDERFAIL")
125
 
                    self._slave.builderFail()
126
 
            self.alreadyfailed = True
127
 
            self._state = DebianBuildState.REAP
128
 
            self.doReapProcesses()
129
 
        else:
130
 
            print("Returning build status: OK")
131
 
            self.gatherResults()
132
 
            self._state = DebianBuildState.REAP
133
 
            self.doReapProcesses()