1
# Copyright 2009, 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
7
from canonical.buildd.debian import DebianBuildManager, DebianBuildState
10
class SBuildExitCodes:
11
"""SBUILD process result codes."""
19
class BuildLogRegexes:
20
"""Build log regexes for performing actions based on regexes, and extracting dependencies for auto dep-waits"""
22
("^E: There are problems and -y was used without --force-yes"),
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>"),
33
class BinaryPackageBuildState(DebianBuildState):
37
class BinaryPackageBuildManager(DebianBuildManager):
38
"""Handle buildd building for a debian style binary package build"""
40
initial_build_state = BinaryPackageBuildState.SBUILD
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(" ")
48
def initiate(self, files, chroot, extra_args):
49
"""Initiate a build with a given set of files and chroot."""
53
if f.endswith(".dsc"):
55
if self._dscfile is None:
56
raise ValueError, files
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)
64
super(BinaryPackageBuildManager, self).initiate(
65
files, chroot, extra_args)
68
"""Run the sbuild process to build the package."""
69
args = ["sbuild-package", self._buildid, self.arch_tag]
71
args.extend([self.suite])
72
args.extend(self._sbuildargs)
73
args.extend(["--dist=" + self.suite])
75
args.extend(['autobuild'])
76
args.extend(self._sbuildargs)
77
args.extend(["--dist=autobuild"])
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 )
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)
98
success = SBuildExitCodes.GIVENBACK
100
if success == SBuildExitCodes.DEPFAIL:
101
for rx, dep in BuildLogRegexes.DEPFAIL:
102
mo = re.search(rx, tmpLog, re.M)
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
111
success = SBuildExitCodes.PACKAGEFAIL
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()
130
print("Returning build status: OK")
132
self._state = DebianBuildState.REAP
133
self.doReapProcesses()